Java Design Ideas (2)

Source: Internet
Author: User

Part 1:                                                                    

Basic Principles of Java Programming 2

I. Opening and closing principle

The simple point is that the new open, the modification is closed. And you should try to do without modifying the module's source code, you can change the behavior of the module.

Ii. The principle of dependency inversion

The principle is to rely on abstraction rather than on concrete implementations.

third, the principle of interface isolation

The principle is not to use generic interfaces, but to use different interfaces for different users.

iv. principle of substitution

The principle is that subclasses should be able to replace the parent class and appear anywhere the parent class can appear.


Part 2:

Basic experience in class design

one, the class to be single

This means that the class function is designed to be single, and a class should be a kind of extremely relevant property and method.

second, strengthen the cohesion, loose coupling

meaning refers to a class, can be implemented within their own internal implementation of the function, do not adjust other classes, as far as possible to reduce the dependency relationship with other classes.

Three, good encapsulation

It means that there is no need to open up the part. If you do not determine the property permissions, first set the properties of the class to private, use the time to open again.

Four, the granularity of the class should be reasonable

That means The Java specification suggests that a class should not be larger than 1000 rows, and that the size of a method should not exceed 100 rows.

the implementation class cannot rely on its use class

This means that one class relies on (or invokes) another class, and in another class, it cannot be relied upon to rely on the current class in turn.

Vi. flexibility should be considered, that is, configurable, maintainable

This means that the user's needs will be constantly changing, and later modification and maintenance is unavoidable, so software development should consider flexibility.

Vii. Consider performance and scalability

The idea is to weigh the relationship between speed and resource consumption, and consider the software to be scalable within a certain range.

consider possible future changes, i.e. scalability

This means that extensibility means that the application can easily add new functionality.

Nine, to consider a reasonable re-use

It means to consider reuse as much as possible, but not to consider reuse, and not to throw away other design principles.

10, to reasonably consider the use of interfaces and abstract classes

This means that the interface is preferred, and if you want to constrain the behavior of subclasses and provide the public functions for subclasses, abstract classes are used.

11. Minimizing the number of interactions and interactions between classes and collaboration classes

It means that the class should not be called repeatedly, do not pass a lot of data each time.

12, the parent class should not know the information of the child class, the subclass must know the information of the parent class

13, access to the object must pass through the interface, can not bypass the interface directly to access




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java Design Ideas (2)

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.