"Android Source design mode"----object-oriented six principles

Source: Internet
Author: User

1. Single-respoonsibility Principle (SRP)--Package

2. Opening and closing principle open Close Principle (OCP)--open for expansion, closed for modification

3. Liskov Substitution Principle (LSP)-all references to base classes must be able to transparently use objects of their subclasses

4. Dependency inversion (dependency inversion) dependence inversion Principle (DIP)-dependent on abstraction, not on detail (i.e., the parameter of the transfer is an interface or abstract class, not a specific instance class)

5. Interface isolation principle Interface segregation principles (ISP)--The client should not rely on the interface it does not need to make the interface as small as possible

6. Dimitri principle (minimum knowledge principle) Law of Demeter (LOD)--a class that knows the least of the classes that it needs to be coupled or called, and how the interior is implemented without any control

NO1:

Abstract refers to an interface or abstract class, both of which cannot be instantiated directly.

No2:

More than 100 classes, such as OutputStream and cursor objects, inherit the Closeable interface, meaning that the close () method is called each time it is used, and a common tool class can be written

 Public Final classcloseutils{Privatecloseutils{}/** Close Closeable object*/     Public Static voidclosequitely (closeable closeable) {if(NULL!=closeable) {            Try{closeable.close (); }Catch() {e.printstacktrace (); }        }    }}

"Android Source design mode"----object-oriented six principles

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.