(Original) Java objects and classes (OOP)

Source: Internet
Author: User
Three main features of an object:

The behavior of an object. Which operations can be performed on the object or the methods that can be applied to the object.

The state of the object. How does the object respond when the method is applied.

The identity of an object.

Relationships between classes:

Dependency ("Uses-A") if a class method is used to manipulate the object of another class, we will say that one class depends on another class.

Minimize the number of dependent classes, even if the coupling between classes is the least.

Aggregate ("has-a") objects of Class A include objects of Class B.

Inheritance ("is-a") Class A inherits class B. Class A not only contains methods inherited from Class B, but also has some additional functions.

Comparison between OOP and traditional procedural programming technologies:

In procedural programming

First, determine the task to complete;

Then:

1. Use the process of gradual refinement: the tasks to be completed are divided into several tasks, and the subtasks are then divided into smaller subtasks, until the subtask is small enough to be directly implemented (this is the top-down method ).

2. Compile methods for solving simple tasks and assemble them into more complex processes until the functions to be implemented are completed (this is a bottom-up method ).

In procedural programming, the methods for determining a process are basically the same as those for determining a method in OOP, that is, to view verbs or actions in the Problem description. The most important difference in OOP is to first separate classes from projects and then find out which methods need to be defined in this class. Another difference is that in OOP, each method is associated with the class responsible for executing this operation.

It is more appropriate to use a procedural method with a small scale;

Large-scale usage classes and methods will bring two benefits:

1. classes provide a mechanism to facilitate the aggregation of many methods;

2. The class encapsulation mechanism will help hide data representation for other class methods;

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.