What is object, why is object-oriented? How can this problem be solved?

Source: Internet
Author: User

ViewArticleIndex Via http://www.cnblogs.com/seesea125/archive/2012/04/17/2453256.html

 

I. Object-oriented. What is this object?

 

 This object is not an example in C #. in C #, we call an instance of a class as an object. Such an object should strictly be an object in Object-Oriented Programming implementation (OOP, object-Oriented programming is not a class-oriented instance programming. The definition of an object is anything that people want to study. From the simplest integer to the complex aircraft, it can be regarded as an object. It not only represents a specific thing, it can also represent abstract rules, plans, or events. Some are also defined as "Everything is an object". However, object-oriented programming cannot be simply understood as anything else? Joke.

Therefore, the object-oriented object refers to the object. Objects refer to objective object entities and subjective abstraction concepts.

 

2. Why is object-oriented?

 

Object-oriented is designed to solve the maintainability, scalability, and reusability of the system. Let's further think about why object-oriented can solve the maintainability, scalability, and reusability of the system?

There are two historical reasons for object-oriented development:

1. Computers help people solve problems. However, after all, a computer is a machine.Code, Step by step, and finally get the result, regardlessProgramThe complexity of the computer is always easy to cope with. Structured Programming is the code written according to the computer's thinking. However, people cannot maintain and expand such complicated logic.

2. structured design is to design and construct an application system with the goal of functionality, the real world composed of objects has to be mapped to the solution space composed of functional modules. This conversion process deviates from the basic idea of observing and solving problems.

It can be seen that structured design cannot solve the reuse, maintenance, and expansion problems when designing the system. It also leads to complicated logic and obscure code. So people thought, could they let computers directly simulate the real environment and design corresponding applications using human ideas, habits, and steps to solve problems? Such a program is easier to understand when people are reading it, and there is no need to switch back and forth between the real world and the program world.

At the same time, people found that objects in the real world are the protagonists in the problem domain. Objects refer to objective object entities and subjective abstract concepts. Objects have attributes and behaviors, the object is stable, the behavior is unstable, and there are various relationships between objects. Therefore, object-oriented programming is more stable than behavior-oriented programming, in the face of frequent changes in demand, behavior is often changed, and objects do not need to be changed. Therefore, we encapsulate the behavior. In this way, we only need to change the behavior, the main architecture remains stable.

So object-oriented is generated.

However, how is the system maintainability, scalability, and reusability pursued by people embodied in Object-Oriented Systems?

First, let's take a look at the three features of object-oriented:

Encapsulation: Find the change and encapsulate it. You can modify or extend the encapsulated change without affecting other parts. This is the basis of all design patterns, it is encapsulation changes. Therefore, the function of encapsulation solves the scalability of the program.

Inheritance: Child classes inherit the parent class and can inherit the methods and attributes of the parent class to achieve polymorphism and code reuse. This also solves the reusability and scalability of the system, but inheritance destroys encapsulation, because it is open to sub-classes, modifying the parent class will lead to changes to all sub-classes. Therefore, inheritance damages the scalability of the system to a certain extent, so inheritance must be used with caution, only a clear IS-A relationship can be used, and inheritance in the Process of Program Development refactoring, rather than the use of inheritance at the beginning of program design, many object-oriented developers abuse inheritance, as a result, the later Code cannot solve the changes in requirements. Therefore, combination is preferred, rather than inheritance, which is an important experience in object-oriented development.

Polymorphism: multiple implementation methods of interfaces are polymorphism. The interface is an abstraction of behavior. As mentioned in encapsulation just now, find and encapsulate the changes. But after encapsulation, how can we adapt to the following changes? This is exactly the role of the interface. The main purpose of the interface is to provide general processing services for irrelevant classes. We can imagine it. For example, the bird can fly, but Superman can also fly. Through the flying interface, we can allow both the bird and Superman to implement this interface, which realizes the maintainability and scalability of the system.

Therefore, object-oriented systems can achieve system maintainability, scalability, and reusability. Object-oriented is a programming idea. At first, "object-oriented" refers to the use of encapsulation, inheritance, polymorphism, and other design methods in programming, however, the idea of Object-oriented has already involved various aspects of software development. For example, the concept of Object-Oriented Analysis (OOA), object-oriented design (OOD ), object-Oriented Programming (OOP)

 

3. What are the steps for object programming?

 

Object-oriented is an idea that allows us to turn our thinking and focus to the objects in reality when analyzing and solving problems, and then clarify the relationships between these objects through UML tools, finally, we use an object-oriented language to implement the connection between such objects and objects. It consists of three major steps: Object-Oriented Analysis (OOA), object-oriented design (OOD), and object-oriented programming implementation (OOP.

1. First, analyze the demand. First, do not think about how to use the program to implement it. First, analyze what the stable and unchanged objects in the demand are and what the relationships between these objects are.

2. the requirements analyzed in the first step are further expanded into a cost-effective, modular, low-coupling, and high cohesion model.

3. Use an object-oriented Implementation Model

 

4. How can we change process-oriented to object-oriented thinking? 

 

When we get used to process-oriented programming, we find that there is no need for Object-Oriented in the Process of the program. The main reason is that the thinking has not changed. When a programmer obtains a requirement, the first response is how to implement it. This is a typical process-oriented thinking process and may soon be implemented. Object-oriented is the object. The first step is not to consider how to implement the requirements, but to analyze the needs. It is to find the objects based on the needs and then find the relationships between these objects. Therefore, the key point of process-oriented and object-oriented thinking transformation is to design in the first step. After obtaining the requirement, do not consider how to implement it, but use UML modeling, then implement it according to the UML model. This transformation may require a process.

 

5. Differences between object-oriented and Object-based 

 

Both "Object-Oriented" and "Object-based" implement the concept of "encapsulation", but object-oriented implements "inheritance and polymorphism", while "Object-based" does not. Therefore, in our web development and general layer-3 development, Object-based implementation is basically implemented, because only encapsulation is implemented, but inheritance and polymorphism are not used, but this is also normal, in web development, most of the functions are simple addition, deletion, modification, and query. The bll layer in the middle is basically the return of a New DAL instance, and the relational database has done a lot of work for us, therefore, most of the work is to simply read and display it. Therefore, when there is no complicated requirement, there is nothing wrong with the process-based approach, and there is nothing wrong with the process-oriented approach, practicality is an overwhelming factor.

 

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.