java-Motherboard Loading Kit case

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.