When the motherboard is designed, a PCI slot is reserved for connecting the network card, sound card, mouse, keyboard and other hardware to extend the function of the motherboard.
Such as:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6D/9B/wKioL1Vny17BiAnQAACX4eZ9G3A348.jpg "title=" Motherboard example. png "alt=" wkiol1vny17bianqaacx4ez9g3a348.jpg "/>
package object-oriented, public class mainboarddemo {/** * @ motherboard design Design pattern Code implementation */public static void main (String[] args) {// TODO Auto-generated method Stubmainboard mb = new mainboard ();//Create Motherboard instance Mb.run ();//Start Motherboard Mb.usepci (New networkcard () )///Connect the NIC Mb.usepci (New soundcard ());//Connect the sound card}}//motherboard class Class mainboard{public void run ()//Turn on motherboard { System.out.println ("Mainboard run");} PUBLIC VOID USEPCI (PCI P)//Use polymorphism to extend the function {if (p!=null) {if (P instanceof networkcard) { networkcard nwc = (Networkcard) P;nwc.open (); Nwc.close ();} Else if (P instanceof soundcard) {soundcard sc = (SoundCard) P;sc.open (); Sc.close () ;}}}} PCI interface, external exposure principle interface pci{public abstract void open ();//Open Hardware Public abstract void close ();//Turn off hardware}//Nic class Class networkcard implements pci{public void open () {System.out. println ("Networkcard run");} Public void close () {System.out.println ("Networkcard close");}} Sound card class Class soundcard implements pci{public void open () {System.out.println ("soundcard fun ");} Public void close () {System.out.println ("Soundcard close");}}
The results of the program run are as follows:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6D/A0/wKiom1Vn0G_QKHi1AADDlVE8BYM944.jpg "title=" 1234. PNG "alt=" Wkiom1vn0g_qkhi1aaddlve8bym944.jpg "/>
This motherboard design will be multi-state, interface and other knowledge points are very natural application. So the Java features of inheritance and interface are the essence of Java and need to be carefully understood.
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Examples of the benefits of interfaces 2: Different database operations
Package object-oriented; public class Operatejdbc {/** * @param args */public static void main (string[] args) {//TODO auto-generated Method Stubuser user = new User ();D atadao dd = new D1 ();//If you want to change to a different database, change D1 directly to D2. Dd.add (user);dd. Delete (user);}} Interface datadao//Different database has the function of adding and removing, but the function content is inconsistent, so it is extracted as an interface. {public void Add (user user);p ublic void Delete (user user);} Class D1 implements datadao//database 1{public void Add (user user) {//Specific implementation code}public void Delete (user user) {//implementation code}}class D2 I mplements datadao//database 2{public void Add (user user) {//implementation code}public void Delete (user user) {//Concrete implementation Code}}
This article is from the "line of the World" blog, please be sure to keep this source http://4259297.blog.51cto.com/4249297/1656220
The idea of Java programming-motherboard design