Java object-oriented benefits interface functions in Java

Source: Internet
Author: User

Java object-oriented benefits interface functions in Java

Using object-oriented thinking for development has the following advantages:
1. Easy to maintain
The structure is designed with an object-oriented approach, which is highly readable. Because of the existence of inheritance, maintenance is only implemented in a local module even if the requirement is changed, so it is very convenient to maintain it? A href = "http://www.bkjia.com/ OS/" target = "_ blank" class = "keylink"> how does one kill a mirror? Br> 2. High quality
Existing classes that have been tested in the field of previous projects can be reused during design so that the system meets business needs and has a high quality.
3. High Efficiency
During software development, the real-world things are abstracted according to the design needs to generate classes. Using this method to solve problems is close to the way of daily life and natural thinking, which is bound to improve the efficiency and quality of software development.
4. Easy scalability
Because of the inheritance, encapsulation, and polymorphism characteristics, the system structure with high cohesion and low coupling is designed, making the system more flexible and easy to expand, and the cost is low.

Object-Oriented Design Principles

Single SRP Responsibility Principle
For a class, there should be only one reason for its change.

OCP open-closed Principle
Software entities (classes, modules, functions, etc.) can be carried out, but cannot be modified.

LSP Liskov replacement principle

Child types must be able to replace their parent types.

DIP Dependency inversion principle
Abstraction should not depend on details. Details should depend on abstraction.

ISP interface isolation principle
Customers should not be forced to rely on methods they do not need. An interface belongs to a customer and does not belong to its class hierarchy.

REP reuse publishing Equivalence Principle
The granularity of reuse is the publishing granularity.

CCP principle of Joint Closure
All classes in the package should be closed for changes to the same class nature. If a change affects a package, it will affect all classes in the package, without affecting other packages.

CRP Reuse Principle
All classes in a package should be reused together. If a class in the package is reused, all classes in the package must be reused.

ADP environment-free dependency Principle
The package dependency graph does not allow loops.

SDP stable dependency Principle
Dependency in a stable direction

SAP stable abstraction principles
The abstraction level of the package should be consistent with its stability.

 
The main function of an interface is to achieve unified access, that is, to create an object with an interface, [interface name] [Object Name] = new [Interface Class ], in this way, you can use a new object like a class object. without modifying the original code, just like your USB interface, this principle is what you insert and read. As you asked, there is a method1 method. If I use an interface, I can use one. method1 (); right? In this case, new a (); is the method of a, and new B () is the method of B, is it inconvenient? This is called unified access, because the method names of the classes that you implement this interface are the same, but different implementation content cannot be accessed if I use interfaces to define objects? The interface is mainly implemented for multiple classes. If there is only one class, the interface is not needed. you think like this, I made a USB interface with a read () abstract method, then mp3 class implementation, USB flash drive class implementation, mobile hard disk class implementation, in this way, I use USB a = new [class name];. read (); if I write a USB flash drive in the class name, read a USB flash drive, write mp3 to read mp3 files, and this name can be read from the attribute file, you can use it if you write it.

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.