Object-oriented Benefits in Java Java interface function

Source: Internet
Author: User
Tags closure

Using object-oriented thinking for development has the following advantages:
1. Easy Maintenance
Object-oriented design of the structure, high readability, due to the existence of inheritance, even if the need to change, then maintenance is only in the local module, so maintenance is very convenient and low cost.
2. High quality
At design time, you can reuse existing classes that have been tested in the field of previous projects to make the system meet business requirements and have high quality.
3. High efficiency
In software development, according to the needs of the design of the real world of things to abstract, produce classes. Using this method to solve the problem, close to the daily life and the natural way of thinking, is bound to improve the efficiency and quality of software development.
4. Easy to expand
Due to the characteristics of inheritance, encapsulation and polymorphism, the system structure of high cohesion and low coupling is designed naturally, which makes the system more flexible, easier to expand and less cost.

Principles of object-oriented design

SRP Single Duty principle
As far as a class is concerned, there should be only one cause for it to change.

OCP Open ———— Closure principle
Software entities (classes, modules, functions, etc.) should be available, but not modifiable.

LSP Liskov Substitution principle

Subtypes must be able to replace their parent types.

DIP Dependency Inversion principle
Abstraction should not depend on detail. The details should depend on abstraction.

ISP Interface Isolation principle
Customers should not be forced to rely on methods that they do not use. The interface belongs to the customer and does not belong to the class hierarchy in which it resides.

REP Reuse Publishing Equivalence principle
The granularity of reuse is the granularity of the release

CCP Common closure principle
All classes in the package should be closed together for changes of the same class nature. If a change affects a package, it will affect all classes in the package, but not the other packages.

CRP Common Reuse principle
All classes in a package should be reused together. If one of the classes in the package is reused, then all classes in the package must be reused.

ADP non-cyclic reliance principle
The ring is not allowed in the dependency diagram of the package.

SDP Stability Dependency principle
To rely on in a stable direction

SAP Stability Abstraction principle
The degree of abstraction of a package should be consistent with its degree of stability.

 
The main function of the interface is to achieve unified access, is created when the object is created with the interface, "Interface Name" "Object Name" =new "Implementation of the interface class", so that you can use which class object to the new object, do not need to change the original code, and your USB interface, plug what read what, That's the principle. As you ask, there is a method1 method, if I use the interface, I can one.method1 (); So I am new A (), is the method of a, new B () is the method of B is this inconvenient? This is called unified access, because you implement this interface class method name is the same, but the implementation of different content I use the interface to define the object can not be unified access to it? The interface is mainly for multiple classes to implement it, if only one class can certainly not use the interface. You think, I do a USB interface, there is a read () abstract method, and then MP3 class implementation, USB drive class implementation, mobile HDD class implementation, so I use the USB a=new "class name" , so A.read (); If I write the name of the U disk, read a U disk, write MP3 study mp3, and this name can be from the properties of the file, you write which you use which, hehe.

Object-oriented Benefits in Java Java interface function

Related Article

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.