当前位置: 首页 > >

Èí¼þÉè¼ÆµÄÆß´óÉè¼ÆÔ­Ôò

发布时间:

Ò»¡¢Ç°ÑÔ

??????Æß´óÉè¼ÆÔ­ÔòÊÇ23ÖÖÉè¼ÆģʽµÄ»ù´¡£¬ÌåÏÖÁËÈí¼þÉè¼ÆµÄ˼Ï룬µ«²¢²»ÊÇËùÓÐÉè¼Æģʽ¶¼×ñÑ­ÕâÆß´óÉè¼ÆÔ­Ôò£¬ÓÐЩÉè¼Æģʽֻ×ñÑ­Ò»²¿·ÖÉè¼ÆÔ­Ôò£¬ÊǶÔһЩʵ¼ÊÇé¿ö×öµÄһЩȡÉá¡£ÔÚÎÒÃÇÏîÄ¿ÖÐÒ²²¢²»Ò»¶¨ÍêÈ«×ñÑ­ËùÓÐÉè¼Æģʽ£¬ÒòΪÊÜһЩÒòËØÈçʱ¼ä¡¢ÈËÁ¦¡¢³É±¾µÈ£¬Èç¹ûÒ»¿ªÊ¼½«À©Õ¹ÐÔ×öµÄºÜÍêÃÀ£¬ÄÇô³É±¾¾ÍÉÏÀ´ÁË¡£ËùÒÔ×ñÑ­Éè¼Æģʽ²»Òª¹ý¶È£¬Ò»¶¨ÒªÊʶȡ£
??????±¾ÎĽ«½²½âÿһÖÖÉè¼ÆÔ­Ôò£¬´Ó¶¨Ò忪ʼ½øÐзÖÎö£¬Àí½â£¬È»ºóʹÓôúÂëʾÀýºÍUMLͼ£¬·ÖÎö´æÔÚµÄÎÊÌ⣬Öð²½Ñݽø£¬Á¦Çó½«Éè¼ÆÔ­Ôò½²Í¸£¬Ê¹¶ÁÕßÀí½â¡£ºóÐøµÄÉè¼ÆģʽÎÄÕÂÒ²½«²ÉÓÃÕâÖÖ·½Ê½¡£


¶þ¡¢¿ª±ÕÔ­Ôò

??????¿ª±ÕÔ­ÔòµÄ¶¨ÒåÊÇ£ºÒ»¸öÈí¼þʵÌ壨ÈçÀࡢģ¿é¡¢º¯Êý£©Ó¦¸Ã¶ÔÀ©Õ¹¿ª·Å¡¢¶ÔÐ޸Ĺرա£Éú»îÖÐÒ²Óкܶ࿪±ÕÔ­ÔòµÄÌåÏÖ£¬±ÈÈ繫˾µÄ8Сʱµ¯ÐÔÉ*àÖƶȣ¬¶Ô8СʱµÄÉ*àʱ¼äÊǵÄÐÞ¸ÄÊǹرյģ¬µ«ÊÇʲôʱºòÀ´Ê²Ã´Ê±ºò×ßÊÇ¿ª·ÅµÄ¡£
??????¿ª±ÕÔ­ÔòµÄº¬ÒåÆäʵÊÇ˵һ¸öÈí¼þʵÌåÓ¦¸Ãͨ¹ýÀ©Õ¹À´ÊµÏֱ仯£¬¶ø²»ÊÇͨ¹ýÐÞ¸ÄÒÑÓеĴúÂëÀ´ÊµÏÖ¡£ÔÚÏîÄ¿ÖÐÐèÇó±ä¸üÊǷdz£³£¼ûµÄ£¬Èç¹ûÎÒÃÇƵ·±ÐÞ¸ÄÔ­ÓеĴúÂë»áÔö¼ÓϵͳµÄ¸´ÔӶȣ¬Ôö¼ÓÏîÄ¿µÄ·çÏÕ¡£Ê¹Óÿª±ÕÔ­Ôò¿ÉÒÔÌá¸ßϵͳµÄ¿É¸´ÓÃÐÔ¼°¿Éά»¤ÐÔ£¬¾ßÌå×ö·¨¾ÍÊÇÓóéÏó¹¹½¨¿ò¼Ü£¬ÓÃʵÏÖÀ©Õ¹Ï¸½Ú¡£
??????ÏÂÃæÓÃÒ»¸öÀý×ÓÀ´½²½â¿ª±ÕÔ­Ôò£¬ÓÐÒ»¸öÔÚÏßÊéµêÂôÊéµÄ³¡¾°£¬Ã¿±¾ÊéÓм۸ñºÍÃû³Æ£¬ÎÒÃÇн¨Ò»¸öÊéµÄ½Ó¿ÚIBook£¬ºÍ¸Ã½Ó¿ÚµÄÒ»¸öʵÏÖÀàJavaBook¡£


public interface IBook {
String getName();
double getPrice();
}
public class JavaBook implements IBook {
@Override
public String getName() {
return "JavaÈëÃŵ½¾«Í¨";
}
@Override
public double getPrice() {
return 68.99;
}
}

??????´ËʱµÄUMLͼÊÇÕâÑùµÄ£¨Í¼Óеã´íÎó£¬IDEAÉú³ÉUMLʱget¿ªÍ·µÄ·½·¨Ëü»áÈÏΪÊÇÊôÐÔ£©

??????ÏÖÔÚÓÐÒ»¸öÐèÇ󣬾ÍÊÇÓÐЩÊéÐèÒª´òÕÛÏúÊÛ£¬ÎÒÃÇÐèÒª»ñÈ¡´òÕÛºóµÄ¼Û¸ñ£¬Ò»ÖÖ˼·ÊÇÐÞ¸ÄIBook£¬ÐÂÔöÒ»¸ö´òÕÛ¼Û¸ñµÄ·½·¨£¬µ«ÊÇÕâÖָĶ¯Ó°ÏìºÜ´ó£¬ÊµÏÖÁ˸ýӿڵÄÀ඼ҪʵÏÖÕâ¸ö·½·¨£»ÁíÒ»ÖÖ˼·¾ÍÊǽ«JavaBookÖеÄgetPrice() ·½·¨Ð޸ijɴòÕÛºóµÄ¼Û¸ñ£¬µ«ÊÇÕâÑù¾Í»ñÈ¡²»µ½Ô­¼ÛÁË£»»¹Ò»ÖÖ˼·ÊÇÔÚJavaBookÖÐÐÂÔöÒ»¸ö»ñÈ¡´òÕÛºó¼Û¸ñµÄ·½·¨£¬ÕâÑù¼ÈÄÜ»ñÈ¡Ô­¼ÛÓÖÄÜ»ñÈ¡´òÕÛºóµÄ¼Û¸ñ£¬µ«ÊÇÕâÈýÖÖÖÖ×ö·¨¶¼Î¥±³ÁË¿ª±ÕÔ­Ôò£¬Ò²¾ÍÊǶÔJavaBook½øÐÐÁËÐÞ¸ÄÀ´ÊµÏֱ仯£¬ÕýÈ·µÄ×ö·¨ÊÇÐÂÔöÒ»¸öJavaBookµÄ´òÕÛÀ࣬¼Ì³Ð×ÔJavaBook£¬ÐÂÔöÒ»¸ö»ñÈ¡´òÕÛºó¼Û¸ñµÄ·½·¨¡£


public class JavaDiscountBook extends JavaBook {
double getDiscountPrice(){
return super.getPrice() * 0.8;
}
}

??????´ËʱµÄUMLͼÊÇ£º

??????ÕâÑùÔÚ²»ÐÞ¸ÄÔ­À´´úÂëµÄ»ù´¡ÉÏ£¬ÊµÏÖÁËÐèÇó±ä¸ü£¬ÆäʵʵÏÖ¿ª±ÕÔ­ÔòµÄºËÐÄÊÇÃæÏò³éÏó±à³Ì£¬ºóÃæһЩÉè¼ÆÔ­ÔòÒ²ÊÇÈç´Ë¡£


Èý¡¢ÒÀÀµµ¹ÖÃÔ­Ôò

??????ÒÀÀµµ¹ÖÃÔ­Ôò¶¨Ò壺¸ß²ãÄ£¿é²»Ó¦¸ÃÒÀÀµµ×²ãÄ£¿é£¬¶þÕ߶¼Ó¦¸ÃÒÀÀµÆä³éÏó¡£Ò²¾ÍÊÇ˵Õë¶Ô½Ó¿Ú±à³Ì£¬²»ÒªÕë¶ÔʵÏÖ±à³Ì£¬Õë¶Ô½Ó¿Ú±à³Ì°üÀ¨Ê¹Óýӿڻò³éÏóÀ࣬ÕâÑù¿ÉÒÔʹµÃ¸÷¸öÄ£¿é±Ë´Ë¶ÀÁ¢£¬½µµÍÄ£¿é¼äµÄñîºÏÐÔ¡£¶øÇÒÔÚʵÏÖÀàÖо¡Á¿²»·¢ÉúÖ±½ÓµÄÒÀÀµ¹Øϵ£¬ÒÀÀµ¹Øϵͨ¹ý½Ó¿Ú»ò³éÏóÀà²úÉú¡£
??????ÓÐÒ»¸ö³¡¾°£¬Ë¾»ú¿ÉÒÔ¿ª³µ£¬ÎÒÃÇн¨Ò»¸öDriverÀàºÍÒ»¸öBenzÀ࣬˾»ú¿ÉÒÔ¿ª±¼³Û³µ£¬´úÂëÈçÏ£º


public class Driver {
public void driver(Benz benz){
benz.run();
}
}
public class Benz {
public void run(){
System.out.println("±¼³Û³µ¿ÉÒÔÅÜ£¡");
}
}

´ËʱµÄUMLͼÊÇÕâÑùµÄ

??????DriverÀà¾ÍÒÀÀµBenzÀ࣬ÏÔȻΥ·´ÁËÒÀÀµµ¹ÖÃÔ­Ôò£¬Èç¹ûÎÒÃÇ˾»úÏ뿪ÆäËû³µ£¬¾Í±ØÐëÐÞ¸ÄDriverÀ࣬ÎÒÃǽøÒ»²½Ð޸ģ¬Ôö¼ÓIDriverµÄ½Ó¿ÚºÍICar½Ó¿Ú£¬IDriverµÄdriverÀà²ÎÊýÊÇICar£¬ÕâÑùʹµÃÒÀÀµ¹Øϵ·¢ÉúÔÚÕâÁ½¸ö½Ó¿ÚÉÏ£¬²»Í¬µÄ˾»úʵÏÖIDriver½Ó¿Ú£¬²»Í¬µÄ³µÊµÏÖICar½Ó¿Ú¾Í¿ÉÒÔÁË£¬´úÂëÈçÏ£º


public interface IDriver {
void driver(ICar car);
}
public interface ICar {
void run();
}
public class Benz implements ICar{
@Override
public void run(){
System.out.println("±¼³Û³µ¿ÉÒÔÅÜ£¡");
}
}
public class Driver implements IDriver{
@Override
public void driver(ICar car){
car.run();
}
}

??????´ËʱµÄUMLͼÊÇÕâÑùµÄ

??????ÕâÑù²»ÂÛʲôÀàÐ͵ijµ¶¼¿ÉÒÔ´«ÈëDriverµÄdriver()·½·¨ÀïÃ棬½øÐе÷Óá£


ËÄ¡¢ µ¥Ò»Ö°ÔðÔ­Ôò

??????µ¥Ò»Ö°ÔðÔ­ÔòµÄ¶¨Ò壺²»Òª´æÔÚ¶àÓÚÒ»¸öµ¼ÖÂÀà±ä¸üµÄÔ­Òò¡£Èç¹ûÎÒÃÇÒ»¸öÀàÓÐÁ½¸öÖ°Ôð£ºÖ°Ôð1ºÍÖ°Ôð2£¬µ±ÎÒÃÇÐèÇó±ä¸üµÄʱºò£¬Ö°Ôð1ÐèÒª¸Ä±ä£¬±ä¸üµÄʱºòºÜ¿ÉÄܻᵼÖÂÔ­±¾Õý³£µÄÖ°Ôð2³öÎÊÌâ¡£ËùÒÔÒ»¸öÀà¡¢½Ó¿Ú·½·¨Ö»¸ºÔðÒ»ÏîÖ°Ôð£¬ÕâÑùÄܽµµÍÀàµÄ¸´ÔӶȣ¬Ìá¸ßÀàµÄ¿É¶ÁÐÔ£¬Ìá¸ß¿Éά»¤ÐÔ£¬½µµÍÐ޸ĴøÀ´µÄ·çÏÕ¡£ÔÚʵ¼ÊÏîÄ¿ÖУ¬ºÜ¶àÀ಻×ñÑ­µ¥Ò»Ö°ÔðÔ­Ôò£¬µ«Êǽӿںͷ½·¨Òª×öµ½µ¥Ò»Ö°Ôð¡£µ¥Ò»Ö°ÔðÔ­Ôò»¹ÓÐÒ»¸öºÜÖØÒªµÄµã¾ÍÊÇÖ°ÔðµÄ»®·Ö£¬ÓÐЩÐèÇóÕý³£Çé¿öÏÂÓжà¸öÖ°Ô𣬵«ÊÇijЩÌØÊâÇé¿öÏÂÓÖÊÇÒ»¸öÖ°Ôð£¬Ö°Ôð»®·ÖÒ²ÐèÒªÊÓʵ¼ÊÇé¿ö¶ø¶¨¡£


Îå¡¢½Ó¿Ú¸ôÀëÔ­Ôò

??????½Ó¿Ú¸ôÀëÔ­Ôò¶¨Ò壺Óöà¸öרÃŵĽӿڶø²»Ê¹Óõ¥Ò»µÄ×ܽӿڣ¬¿Í»§¶Ë²»Ó¦¸ÃÒÀÀµËü²»ÐèÒªµÄ½Ó¿Ú¡£Ò²¾ÍÊÇ˵һ¸öÀà¶ÔÁíÒ»¸öÀàµÄÒÀÀµÓ¦¸Ã½¨Á¢ÔÚ×îСµÄ½Ó¿ÚÉÏ£¬¾¡Á¿Ï¸»¯½Ó¿Ú£¬¼õÉÙ½Ó¿ÚÖеķ½·¨£¬µ«ÊÇÒ»¶¨Òª×¢ÒâÊʶȵÄÔ­Ôò£¬¹ý·Öϸ»¯½Ó¿Ú»á´øÀ´¸´ÔӶȡ£
??????±ÈÈçÎÒÃÇÓиö½Ó¿ÚIAnimalAction£¬ÃèÊö¶¯ÎïµÄÐÐΪ£¬´úÂëÈçÏ£º


public interface IAnimalAction {
void eat();
void fly();
void swim();
}

??????Õâ¸ö½Ó¿ÚÖУ¬ÎÒÃǶ¨ÒåÁËÈý¸öÐÐΪ£¬ºóÃæÐèÒªµÄ¶¯ÎïÀàʵÏÖÕâ¸ö½Ó¿Ú£¬µ«ÊÇÕâ¾Í´æÔÚÒ»¸öÎÊÌ⣬Èç¹ûijЩ¶¯Îï²»¾ß±¸½Ó¿ÚÀïÃæµÄÈý¸öÐÐΪÖеÄijһ¸ö£¬µ«ÊÇËü±ØÐëҪʵÏÖÄǸö·½·¨£¬Õâ¾ÍÎ¥±³Á˽ӿڸôÀëÔ­Ôò£¬ÕýÈ·µÄ×ö·¨Êǽ«½Ó¿ÚÖеÄÈý¸ö·½·¨¸ôÀ뿪£¬·Ö³ÉÈý¸ö½Ó¿Ú£¬ÕâÑùÓоßÌåÐÐΪµÄ¶¯ÎïʵÏÖ¾ßÌåµÄ½Ó¿Ú£¬¼õÉÙÁËñîºÏ£¬½«´úÂëÑݽø£º


public interface IEatAnimal {
void eat();
}
public interface IFlyAnimal {
void fly();
}
public interface ISwimAnimal {
void swim();
}

??????½Ó¿Ú¸ôÀëÔ­ÔòÇ¿µ÷µÄÊǽӿÚÒÀÀµ¸ôÀ룬µ¥Ò»Ö°ÔðÔ­ÔòÇ¿µ÷µÄÊÇÖ°Ôðµ¥Ò»¡£µ¥Ò»Ö°ÔðÊǶÔʵÏÖµÄÔ¼Êø£¬½Ó¿Ú¸ôÀëÔ­ÔòÊǶԳéÏóµÄÔ¼Êø¡£


Áù¡¢µÏÃ×ÌØÔ­Ôò

??????µÏÃ×ÌØÔ­ÔòÓÖ½Ð×îÉÙÖªµÀÔ­Ôò£¬¶¨ÒåÊÇ£ºÒ»¸ö¶ÔÏóÓ¦¸Ã¶ÔÆäËû¶ÔÏó±£³Ö×îÉÙµÄÁ˽⡣¼òµ¥½²¾ÍÊÇÖ»ºÍÅóÓѽ»Á÷£¬²»ºÍÄ°ÉúÈË˵»°£¬ÅóÓÑÖ¸µÄÊdzöÏÖÔÚ³ÉÔ±±äÁ¿¡¢·½·¨ÊäÈë¡¢·½·¨Êä³öÖеÄÀ࣬µ«ÊdzöÏÖÔÚ·½·¨ÄÚ²¿µÄÀ಻ÊôÓÚÅóÓÑ¡£²»Ó¦¸ÃºÍÕâÑùµÄÀà·¢Éú¹Øϵ¡£Ê¹ÓõÏÃ×ÌØÔ­Ôò¿ÉÒÔ½µµÍÀàÓëÀàÖ®¼äµÄñîºÏ£¬Ìá¸ßÀàµÄ¸´ÓÃÂÊ£¬µ«ÊÇ»¹ÊÇҪǿµ÷ÊʶȵÄÔ­Ôò£¬¹ý·ÖʹÓõÏÃ×ÌØÔ­Ôò»á²úÉú´óÁ¿µÄÖнéÀ࣬ʹϵͳ±ä¸´ÔÓ¡£
??????ÏÖÔÚÓÐÒ»¸ö³¡¾°£¬Ñ§Ð£ÀïÃæÓжà¸ö°à¼¶£¬°à¼¶ÀïÃæÓжà¸öѧÉú£¬ÎÒÃÇÏÖÔÚÒª´òÓ¡ËùÓа༶µÄËùÓÐѧÉú£¬Ò»ÖÖʵÏÖ·½Ê½ÈçÏÂ(ÕâÀォ³ÉÔ±±äÁ¿ÉèÖóÉpublicÊ¡ÂÔÁËget¡¢set·½·¨)£º


public class School {
public int id;
public String schoolName;
public List classes;
public void print(){
for(Class c : classes){
for(Student s : c.students){
System.out.println(s.studentName);
}
}
}
}
class Class{
public int id;
public String className;
public List students;
}
class Student{
public int id;
public String studentName;
}

??????ÔÚSchoolÀàÖУ¬ClassÀàÊÇËüµÄÊôÐÔ£¬Ò²¾ÍÊÇËüµÄÅóÓÑ£¬µ«ÊÇStudentÀà¼È²»ÊdzÉÔ±±äÁ¿£¬·½·¨Èë²Î£¬Ò²²»ÊÇ·½·¨·µ»ØÖµ£¬Ëü²»ÊÇSchoolÀàµÄÅóÓÑ£¬²»Ó¦°®³öÏÖÔÚ·½·¨ÄÚ²¿£¬Ó¦¸ÃÈÃClassÀà´òÓ¡±¾°à¼¶µÄѧÉú£¬´úÂëÑݽøÈçÏ£º


public class School {
public int id;
public String schoolName;
public List classes;
public void print(){
for(Class c : classes){
c.print();
}
}
}
class Class{
public int id;
public String className;
public List students;
public void print(){
for(Student s : students){
System.out.println(s.studentName);
}
}
}
class Student{
public int id;
public String studentName;
}

??????ÕâÑùSchoolÀàºÍStudent¾ÍûÓÐñîºÏÁË£¬Âß¼­Ò²ºÜÇåÎú£¬·ûºÏµÏÃ×ÌØÔ­Ôò¡£


Æß¡¢ÀïÊÏÌæ»»Ô­Ôò

??????ÀïÊÏÌæ»»Ô­ÔòµÄ¶¨ÒåÊÇ£º¶ÔÓÚÿһ¸öÀàÐÍΪT1µÄ¶ÔÏóO1£¬¶¼ÓÐÀàÐÍΪT2µÄ¶ÔÏóO2£¬Ê¹µÃÒÔT1¶¨ÒåµÄËùÓгÌÐòPÔÚËùÓжÔÏóO1Ì滻ΪO2ʱ£¬³ÌÐòPµÄÐÐΪûÓз¢Éú±ä»¯£¬ÄÇôÀàÐÍT2ÊÇÀàÐÍT1µÄ×ÓÀàÐÍ¡£Ò²¾ÍÊÇ×ÓÀàÌæ»»¸¸À࣬³ÌÐòÂß¼­²»±ä¡£ÀïÊÏÌæ»»Ô­ÔòÔ¼ÊøÁ˼̳У¬¼Ì³ÐÔÚ³ÌÐòÉè¼ÆÖÐÄܹ»¸´ÓôúÂ뵫ÊǶԳÌÐòÊÇÓÐÈëÇֵģ¬ÒòΪ×ÓÀàĬÈϾÍÓµÓи¸ÀàµÄÐÐΪ£¬¶øÇÒÔö¼ÓÁËñîºÏ¡£
??????Ôڼ̳ÐÖÐÈçºÎ×ñÊØÀïÊÏÌæ»»Ô­Ôò£¿Ê×ÏÈ×ÓÀà¿ÉÒÔÀ©Õ¹¸¸ÀàµÄ¹¦ÄÜ£¬µ«²»ÄܸıäÔ­ÓеŦÄÜ£¬×ÓÀà¿ÉÒÔʵÏÖ¸¸ÀàµÄ³éÏó·½·¨£¬µ«²»Äܸ²¸Ç¸¸ÀàµÄ·Ç³éÏó·½·¨£¬Èç¹ûÖØдÁË£¬ÄÇôÓÃ×ÓÀàÌæ»»¸¸Ààʱ£¬³ÌÐò»áµ÷ÓÃ×ÓÀàµÄ·½·¨£¨·ñÔòÖØд¾ÍûÓÐÒâÒåÁË£©£¬Ò²¾Íµ¼Ö³ÌÐòµÄÐÐΪ·¢Éú±ä»¯¡£»¹ÓоÍÊÇ×ÓÀàÖØÔØ£¨²»ÊÇÖØд£©¸¸Àà·½·¨Ê±£¬·½·¨µÄÇ°ÖÃÌõ¼þ£¨·½·¨Èë²Î£©Òª±È¸¸Àà¸ü¿íËɱÈÈ縸ÀàµÄ²ÎÊýÊÇHashMap£¬×ÓÀàµÄ»°²ÎÊý¿ÉÒÔÊÇMap£¬¸ü¿íËɵĻ°Ìæ»»»ò²»Ìæ»»³ÌÐò¶¼»áµ÷Óø¸ÀàµÄ·½·¨£¬³ÌÐòµÄÐÐΪҲ¾Í²»»á¸Ä±ä£¬·ûºÏÀïÊÏÌæ»»Ô­Ôò¡£Í¬Àí£¬·½·¨µÄºóÖ㨷½·¨·µ»ØÖµ£©Ìõ¼þÒª±È¸¸Àà¸üÑϸñ¡£Ê¹ÓÃÀïÊÏÌæ»»Ô­Ôò£¬¿ÉÒÔ±ÜÃâ×ÓÀàÖØд¸¸ÀàµÄ·½·¨£¬½µµÍ´úÂë³ö´íµÄ¿ÉÄÜÐÔ¡£


°Ë¡¢ºÏ³É¸´ÓÃÔ­Ôò

??????ºÏ³É¸´ÓÃÔ­ÔòµÄ¶¨ÒåÊÇ£º¾¡Á¿Ê¹ÓöÔÏóµÄ×éºÏ/¾ÛºÏ£¬¶ø²»ÊǼ̳йØϵ´ïµ½Èí¼þ¸´ÓõÄÄ¿µÄ¡£
??????×éºÏÊÇcontains-AµÄ¹Øϵ£¬±ÈÈçÒ»¸öÈ˵ÄÊÖ¡¢½Å¾ÍÊÇ×éºÏ¹Øϵ£¬ÕâÊÇÒ»ÖÖÇ¿¹Øϵ£¬ÆäÖÐÒ»²¿·Ö²»´æÔÚÁË£¬ËùÓеĶ¼²»´æÔÚÁË£¬¾ÛºÏÊÇhas-AµÄ¹Øϵ£¬ÊÇÒ»ÖÖÈõµÄ¹Øϵ£¬ÈËȺÖеÄÈ˾ÍÊǾۺϹØϵ£¬ÆäÖÐÒ»¸öÈËÀ뿪ÁË£¬ÈËȺ»¹ÊÇ´æÔڵģ¬Í¨¹ý×éºÏ¾ÛºÏÒ²¿ÉÒÔ´ïµ½¸´ÓõÄÄ¿µÄ£¬µ«ÊÇÕâÖÖ¸´ÓÃÊǺÚÏ临Ó㬲»ÐèÒªÖªµÀϸ½Ú£¬¼Ì³ÐµÄ¸´ÓÃÊÇ°×Ï临Ó㬸¸ÀàµÄϸ½Ú»á±©Â¶¸ø×ÓÀà¡£¾¡Á¿Ê¹ÓÃ×éºÏ/¾ÛºÏÀ´ÊµÏÖÈí¼þ¸´Óò¢²»ÊÇ˵Å×Æú¼Ì³Ð£¬Èç¹ûÁ½¸öʵÌåÊÇis-AµÄ¹Øϵʱ£¬¿ÉÒÔʹÓü̳С£
??????ÏÖÔÚÓиö³¡¾°¾ÍÊÇÊý¾Ý·ÃÎʲãÒª²Ù×÷Êý¾Ý£¬ÐèÒªÏÈ»ñµÃÊý¾Ý¿âÁ¬½Ó£¬ÎÒÃÇн¨Á½¸öÀࣺ


public class DBConnection {
public String getConnection() {
return "»ñµÃÊý¾Ý¿âÁ¬½Ó";
}
}
public class ProductDao extends DBConnection {
private void addProduct(){
getConnection();
System.out.println("²Ù×÷Êý¾Ý¿â£¡");
}
}

??????ͨ¹ý¼Ì³ÐÎÒÃÇʵÏÖÁË»ñÈ¡Êý¾Ý¿âÁ¬½Ó£¬µ«ÊÇÈç¹ûÎÒÃÇÒª¸ü»»Ò»ÖÖÊý¾Ý¿â£¬ÄÇô¾ÍÒªÐÞ¸ÄDBConnectionÀ࣬Υ±³ÁË¿ª±ÕÔ­Ôò£¬ÏÖÔÚÎÒÃÇ¿ÉÒÔͨ¹ý³éÏó¼Ó×éºÏµÄ·½Ê½À´ÊµÏÖ±ä¸üºóµÄÐèÇ󣬴úÂëÑݽøÈçÏ£º


public abstract class DBConnection {
public abstract String getConnection();
}
public class MySQLConnection extends DBConnection {
@Override
public String getConnection() {
return "MySQLµÄÊý¾Ý¿âÁ¬½Ó";
}
}
public class OracleConnection extends DBConnection {
@Override
public String getConnection() {
return "OracleÊý¾Ý¿âÁ¬½Ó";
}
}
public class ProductDao{

private DBConnection dbConnection;

ProductDao(DBConnection dbConnection){
this.dbConnection = dbConnection;
}
public void addProduct(){
String con = dbConnection.getConnection();
System.out.println("ʹÓÃ"+con + "Ôö¼ÓÒ»¸ö²úÆ·");
}
}

??????ÕâÑù£¬µ±ÎÒÃÇÐÂÔöÒ»ÖÖÊý¾Ý¿âÁ¬½ÓµÄʱºò£¬Ö»Òª¼Ì³ÐDBConnectionÕâ¸ö³éÏóÀà¾Í¿ÉÒÔÁË£¬°´ÎÒÃÇʵ¼Ê´«ÈëµÄÀàÐÍ£¬ProductDao»áµ÷ÓöÔÓ¦µÄÊý¾Ý¿âÁ¬½ÓÀ´²Ù×÷Êý¾Ý¿â£¬´ËʱµÄUMLÊÇÕâÑùµÄ¡£


相关推荐


友情链接: