javase--object-oriented and process-oriented, classes and objects, (properties, methods, constructors), etc.

Source: Internet
Author: User

One: Object-oriented and process-oriented

Both are a kind of thought, object-oriented is relative to the process-oriented.

Process oriented:

1. Process-oriented thinking emphasizes the process (action).

2. In the process-oriented development, it is actually facing the specific steps and processes, each step and process is completed, however, these functional methods call each other to complete the requirements.

3. The typical representative language for the process is: C language.

Object-oriented:

1. Package The steps and methods, according to different functions, carry out different encapsulation, when using, find the corresponding class can be.

2. Encapsulate the function into the object, emphasizing the object with the function. This is the idea of object-oriented. The typical language is: C++,java.

3. Object-oriented more emphasis on the use of human thought in the daily logic of thinking and principles, such as abstraction, classification, inheritance, aggregation, polymorphism and so on.

① features of object-oriented thinking:

    • is a thought that is more in line with our thought habits.
    • Can simplify complicated things.
    • Is that we turn from the executor to the conductor, and the role changes.

② when the requirements are fulfilled, we should do so according to the object-oriented thinking:

    • First, we look for objects that have the required functionality to use.
    • If there are no such objects, then we should create an object with the required functionality.
    • This can improve the reusability of code and simplify development.
Example:

People put elephants in refrigerators

Process oriented: 1. Open the refrigerator----->2. Put the elephant in the refrigerator------>3. Shut the refrigerator door.

Object-oriented: person {1. Open (refrigerator) {refrigerator]. Open the door ();     2. Operation (elephant) {elephant. Enter ();} 3. Close (refrigerator) {refrigerator. Close ();}}

Refrigerator {Open Door () {} close () {}}

Elephant {Enter () {}}

 Public classdemo1{/*put the elephant in the refrigerator. */       Public Static voidMain (string[] args) {/*process oriented: 1, open the refrigerator door.                       2. Put the elephant in the bag. 3, close the refrigerator door*/          //process-oriented, call method:open ();          In ();                    Close (); /*Object-oriented: How to think to be more consistent with object-oriented?                         1. What are the classes?                         2. What does each class have?             3. What is the relationship between classes and classes? Put the elephant in the refrigerator. Analysis (noun extraction) A, how many classes?                             Elephant, refrigerator, demo Class B, what's in each class? ———— Elephant: Go in ———— refrigerator: On, off ———— Demo:main method*/          //Object- oriented, object creation, object invocation methodsBeer Beer =NewBeer (); Icebox Box=Newicebox ();          Box.open ();          Beer.in ();      Box.close (); }             Public Static voidOpen () {System.out.println ("Process oriented: Open the refrigerator"); }       Public Static voidIn () {System.out.println ("Process oriented: put elephants in the fridge." "); }       Public Static voidClose () {System.out.println ("Process-oriented: off the refrigerator"); }  }  classbeer{ Public Static voidIn () {System.out.println ("Object oriented: Loading elephants in"); }  }  classicebox{ Public Static voidOpen () {System.out.println ("Object oriented: Open the refrigerator"); }       Public Static voidClose () {System.out.println ("Object-oriented: Close the refrigerator"); }  }  

In object-oriented development, we are constantly creating objects, using objects, and directing objects to do things. The object-oriented design process, in fact, is to manage and maintain the relationship between objects.
③ Object-Oriented thinking method

    • Determine who will do it first, and then decide what to do.
    • The first consideration is the whole, followed by the partial.
    • The first consideration is abstraction, followed by consideration is concrete.

Three features of ④ object-oriented
There are three main characteristics of object-oriented: encapsulation (encapsulation), Inheritance (inheritance), polymorphism (polymorphism). If you want to answer four, you can add the characteristics of abstraction.

1. 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.

2. Package:
Encapsulation is the process and data is surrounded, 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.

3. Polymorphism:
Polymorphism refers to allowing objects of different classes 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.

4. Abstraction:
Abstraction is about ignoring aspects of a topic that are not related to the current goal, so that you can more fully focus on the aspects that are relevant to the current goal. Abstractions do not intend to understand all of the problems, but simply select one part of them, temporarily without some detail. Abstract includes two aspects, one is the process abstraction, the other is the data abstraction.

II: Classes and objects

Three: Properties, methods

Four: Constructors

javase--Object-oriented and process-oriented, classes and objects, (properties, methods, constructors), and so on

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.