Process-oriented programming, object-oriented programming

Source: Internet
Author: User

1. Process oriented (understanding)

Learning to object-oriented, we first have to learn to process-oriented.

Process-oriented and object-oriented are two ways of thinking in solving problems in life.

Orientation: is the meaning of attention

Process-oriented: throughout the execution of the whole thing, you are the participants in the process, and you have to be self-directed to all steps.

Examples of process-oriented life:

Eat:

1. What do you think about eating first?

2. Go to the grocer's to buy vegetables.

3. Go home to pick vegetables, wash vegetables, cut vegetables.

4. Stir-fry and stew rice.

5. Eat.

6. Wash.

Process-oriented, the real manifestation in the program is the function written by the developer himself.

2. Object-oriented (understand the initial concept of object-oriented)

Understanding object-oriented thinking in life:

Object-oriented: we need to accomplish something that requires a specific result. Instead of participating in it ourselves, we look for objects with these features and then invoke their capabilities to help us fulfill our requirements. (Object-oriented focuses only on results, not on processes)

Object: is actually an entity (individual). In life, an entity is a thing that exists in reality.

Examples of object-oriented life:

Eat:

1, think first what to eat?

2. Find a hotel

A) to find the waiter to call the waiter's order function

b) The waiter will inform the chef of the customer's ordering information.

c) After the chef has cooked the dishes, the waiter is responsible for serving.

3. Eat

The second way is more in line with our thinking habits, not so hard, and we just need to command or find the appropriate function of the object to help us do things.

Understanding object-oriented thinking in Java:

Object-oriented: In fact, it is a solution to the problem. In the development, when encountering the demand, do not analyze how to solve the requirements of the function, but to find there is no already implemented to solve the requirements of the functionality of the packaging class (class encapsulated in the need to solve the function of the code [function]). Yes, just call out-of-the-box functionality to solve the problem; No, create a new class, write the code in the new type of book to solve the requirements (the code that solves the problem is written in the newly created class and can be used directly if you encounter similar requirements later). Using an object-oriented approach to solve problems in development, you can convert a developer from a contributor (worker) to a caller (the conductor)

Object-oriented, the real embodiment in the program is a class (the class encapsulates the problem-solving function).

All of the computer languages they are born with are basically used to solve problems in life:

Computer languages are also categorized:

Process-oriented language: C

Object-Oriented languages: Java, C + +, C #, etc.

Summary:

process-oriented: The constituent unit in the program is the function. is made up of several functions

Object-oriented: The constituent unit in the program is the class (the function is encapsulated in the class). is made up of several classes.

object-oriented is based on a process-oriented basis. In development, object-oriented and process-oriented are used in conjunction with

3. Object-oriented examples (understand what is different with object-oriented and process-oriented)3.1, Buy computer (group installed)

Process oriented:

1, check the parameters for 1 days

2, to the computer city offer 1 days

3, go home to choose a more cost-effective shop 1 days

4, to the computer city targeted bargaining set configuration

5, Assembly supervision

6. Installation System

7, carry home to play lol.

Throughout the problem-solving process, the person who buys the computer needs to be involved in every step of the process, need to be pro-Pro, the purchase process is more tired.

Object-oriented:

1, find a computer-savvy veteran---> Black cyclone.

2. Tell him the price he can accept

3, give money let the black cyclone Help to buy computer

4, waiting for the black cyclone to carry back the computer

In contrast to the process-oriented approach, the whole process is instantly easy to use.

3.2. Object-oriented example (interviewer version)

Interviewer You interview us, this time you are using object-oriented thinking to solve the problem. Interviewer you have a wealth of development experience, we now have a corresponding project needs to be developed, you can accomplish this task, but it may take a long time to complete, and then you need to find a group of professionals with professional development capabilities, and just then you find us. And we are those who have the professional development ability of developers, and you do not need to do the corresponding development work, and only need to direct us to complete the specific development tasks, and can efficiently and quickly complete customer needs.

3.3. Object-oriented and process-oriented differences (object-oriented benefits:)

Process-oriented and object-oriented are the way of thinking about problem solving:

Process-oriented we need to be involved, and throughout the process we are the specific participants in this event.

Object-oriented We don't need to be involved in each of these steps, we just need to find the object with the corresponding function, and then direct them to do things.

Object-oriented more in line with the current people's thinking habits.

If there are no objects that can accomplish a specific function in the actual requirement, then you create an object first and then use that object in an object-oriented manner.

Following the main ideas of learning:

How do we use a Java program to describe an object, and then create the object, and then use that object, as well as the relationship between the object and the object.

4, the use of objects in demand and practice (master a small skill: noun refining method)4.1, the use of objects in demand

Need: Put the elephant in the fridge.

General practice: After encountering the requirements, we first analyze the requirements of the nouns, basically the requirements of the noun is one of the objects (noun refining method).

When the noun is extracted, it begins to analyze what the current object's behavior and function are, or what basic data is available.

noun: elephant, refrigerator.

Describe the details of each noun (object):

Elephant

{

}

Refrigerator

{

Open ()

{

}

Storage (Elephant)

{

}

Off ()

{

}

}

After analyzing the specific objects, we need to create the real objects.

There is the concrete real thing about the elephant:

Elephant dx = new Elephant (); Created an elephant, this thing.

There's a refrigerator, this thing.

Refrigerator bx = new refrigerator (); With the fridge, this thing.

BX. open (); Opened the door to the refrigerator.

BX. Storage (DX); Put the elephant in the fridge

BX. Off ();//close the refrigerator door

When analyzing the requirements, it is important to analyze which object the current function or behavior should belong to.

4.2, the use of objects in demand practice

Analyze what objects are in the following and describe which objects the feature belongs to.

People open:

People:

Door: The function of opening belongs to the door itself.

Train driver Brakes:

Train: The brakes are the function of the train.

Driver:

Generally when we analyze the specific object, the action in the demand, generally belong to the function of an object.

5, the embodiment of the object in the code (master)

To put the specific individuals that exist in life, and some things in the end of the Java program to reflect:

The class of things in life can correspond to a class program in Java, and this class program is called a category. So all the objects of the above analysis can be encapsulated and described using classes in Java.

When we need to encapsulate and describe things in life using classes in Java:

The first thing you need to do is analyze the basic features of the things in your life (basic attributes, functions/behaviors/actions (represented by functions in Java)). The corresponding relationships are then established by analyzing the classes in Java. Finally, you can use the class description in Java.

People's Case:

We should start with a specific person, or from a few people, to analyze the common characteristics of the current human kind of things.

People have basic data: height, weight, age, name, gender ....

People have the basic functions: eating, sleeping, learning.

People

{

Height

Weight

Age

Gender

Name

Eat () {}

Sleeping () {}

Learn () {}

}

After analyzing the common features of a certain class of things, what are the basic data that should begin to consider such things should be used in Java description? And what is the basic function of things that should be described in Java?

The basic data of things, generally in life is a data, this data can be used to learn a variable to represent.

The behavior/function/action of a thing can be described using a function in Java.

Use the class in Java to describe the thing that is currently being parsed: the name of the thing, the class name in Java

Class Person

{

Double height; Height

Double weight; Weight

int age; Age

char sex; Gender

String name; Name

Describe the common behavior of such things as people

The preceding function modifier does not have to be written

void Eat ()//Eat

{

}

void sleep ()//Sleep

{

}

void study ()//Learning

{

}

}

After describing a thing, to use this thing in a Java program, you first need to use the New keyword to create the object in Java, and then you can invoke all of its features through this object.

Person p = new person (); Created a Person object

P.age = 23;

p.name = "xxx";

P.sex = ' Male ';

P.eat ();

P.sleep ();

P.study ();

Note: If the class is only intended to describe a thing, it does not need to be run independently

so you can not write the main function, if a class needs to run independently, then must write the main function

Requirements: Describe some of the attributes and behaviors (functions) of a person in Java code

Process-oriented programming, object-oriented programming

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.