Java object-oriented-progress 2

Source: Internet
Author: User

1. Five basic principles of object-oriented

Three basic elements:

1. Encapsulation: Encapsulation is to surround the process and data, access to data only through the defined interface. Object-oriented computing begins with this basic concept that the real world can be portrayed as a series of fully autonomous, encapsulated objects that access other objects through a protected interface.
2. Inheritance: Inheritance is a hierarchical model of a junction class and allows and encourages the reuse of classes, which provides a way to articulate commonalities. A new class of objects can be derived from existing classes, a process known as class inheritance. The new class inherits the attributes of the original class, which is called the derived class (subclass) of the original class, and the original class is called the base class of the new class (The parent Class). Derived classes can inherit methods and instance variables from their base classes, and classes can modify or add new methods to make them more suitable for special needs.
3. Polymorphism: Polymorphism means that objects of different classes are allowed to respond to the same message. Polymorphism consists of parameterized polymorphism and inclusion polymorphism. Polymorphism language has the advantage of flexibility, abstraction, behavior sharing and code sharing, which solves the problem of application function with the same name.

The function of virtual function in C + + is mainly to realize the mechanism of polymorphism. In terms of polymorphism, in short, a pointer to the parent type points to an instance of its child class, and then invokes the member function of the actual subclass through a pointer to the parent class. This technique allows the parent class to have a "multiple form" pointer, which is a generic technique. The so-called generic technology, plainly, is trying to use immutable code to implement a mutable algorithm . For example: template technology, RTTI technology, virtual function technology, either try to do at compile time resolution, or try to achieve runtime resolution.


Five basic principles:
① single Duty Principle (Single-resposibilityprinciple): A class, it is best to do only one thing, only a change that causes it. The principle of single responsibility can be regarded as the extension of low coupling, cohesion in object-oriented principle, defining responsibility as the cause of change, in order to improve cohesion to reduce the cause of change.
② Open Closure principle (open-closed principle): Software entities should be extensible and non-modifiable. That is, open to the extension, to modify the closed.
③liskov substitution principle (liskov-substituionprinciple): Subclasses must be able to replace their base classes. This idea is embodied in the constraints of inheritance mechanism, only the subclass can replace the base class, it can ensure that the system in the runtime to identify the subclass, which is the basis of ensuring inheritance reuse.
④ dependency Inversion principle (dependecy-inversionprinciple): dependent on abstraction. In particular, high-level modules do not rely on the underlying modules, both of which are dependent on abstraction;
⑤ Interface Isolation principle (interface-segregationprinciple): Use multiple small, dedicated interfaces instead of a large total interface.

Java object-oriented-progress 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.