Interface Isolation principle (Interface segregation Principle) ISP

Source: Internet
Author: User
Tags iusb

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceinterfacesegregationprinciple{//Interface Isolation principle (Interface segregation Principle) ISP//clients should not being forced to depend upon interfaces that they don's use. (The client should not rely on interfaces it does not need)//The dependency of one class to another one should depend on the smallest possible interface. (Dependencies between classes should be based on the smallest interface) 
    //A single accusation requires a single accusation of class and interface, which is the division of Business logic that focuses on accusations. The principle of interface isolation requires minimal interface methods. There should be several interfaces available to several modules, rather than creating a huge bloated interface that accommodates all customer visits.     classProgram {Static voidMain (string[] args) {Bluetoothmouse mouse=NewBluetoothmouse (); Usbmouse Usbmouse=NewUsbmouse (); }    }    //Bluetooth Mouse class, inherited the mouse interface, Bluetooth interface     Public classBluetoothmouse:imouse, Ibluetooth { Public voidLeftclick () {Throw Newnotimplementedexception (); }         Public voidRightClick () {Throw Newnotimplementedexception (); }         Public voidMove () {Throw Newnotimplementedexception (); }         Public voidBluetoothconnect () {Throw Newnotimplementedexception (); }    }    //USB Tag Class, inherited the mouse interface, USB interface     Public classUsbmouse:imouse, Iusb { Public voidLeftclick () {Throw Newnotimplementedexception (); }         Public voidRightClick () {Throw Newnotimplementedexception (); }         Public voidMove () {Throw Newnotimplementedexception (); }         Public voidUsbconnect () {Throw Newnotimplementedexception (); }    }    //the mouse interface, for the mouse itself, is sure to contain the left and right click, moving three methods of//As for the Bluetooth connection, or USB connection, this is the external connection, should be isolated (so that other devices can inherit these interfaces, to prevent code redundancy complex), and not all written in Imouse this interface//one might think that the way of move has infrared and pulley in both ways, should move also extract out interface isolated out? //This needs specific analysis, in this case is not necessary, from the mouse class application level, move is the mouse inside the method, and no external docking, even if the extraction interface, in this application level is not useful, will only increase the complexity. //If our business is to refine the mouse class (for example, to simulate manufacturing a mouse) and drill down into the module components of each mouse, it may be necessary to isolate the move's interface.      Public InterfaceImouse {voidLeftclick (); voidRightClick (); voidMove (); //The following two interfaces should be isolated because they are external interfaces//If you do not isolate, some mouse only support USB connection, you must also implement an empty Bluetooth connection method? //void Bluetoothconnect (); //void Usbconnect ();    }     Public InterfaceIbluetooth {voidBluetoothconnect (); }     Public InterfaceIusb {voidUsbconnect (); }}

Interface Isolation principle (Interface segregation Principle) ISP

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.