requirement One : analog computer motherboard , mouse and keyboard are plugged in the motherboard, for data interaction
implementation One : In the Install method of the motherboard class, the incoming type is written dead, which prevents the keyboard from loading.
implementation two : with interface-oriented programming, the component is extracted out of a common interface, in the install in the interface can be
Modify The install method in the motherboard class, and the DoWork method, change the parameter to the Iusb interface type, and improve the program extensibility through the idea of interface-oriented programming.
requirement two : Install printer , use only once, do not want to create printer class
implementation three : using anonymous internal classes to implement the printer class is not created, install the printer
using the anonymous inner class , the printer object directly to the install method, but only load, no way to complete the DoWork method, if the DoWork method with anonymous inner class, then the load and work is two objects, and the requirements do not meet
implementation Four : maintain a Map collection in motherboard, the component that will be loaded, the existence of the collection
in the Motherboard maintains a map collection, stores the loaded component name and type, and loops through the Swapdata () method of the component in the DoWork method
requirement three : Each installation component must modify the source code , does not conform to the Java opening and shutting principle (open to the extension, the modification is closed)
implementation Five : Put the components in the configuration file and load the components automatically after the motherboard is created
Add a static block of code to the motherboard class , read the configuration file, instantiate the component, and store the component in the collection.
java-Motherboard Loading Kit case