"What is an object, why object-oriented, and how can it be object-oriented?" 】

Source: Internet
Author: User


A,   object-oriented What exactly is this object?

This object is not an instance of C #, C # We call an instance of a class an object, which is strictly an object in object-oriented programming implementation (OOP), object-oriented programming, or class-oriented instance programming. objects are defined as anything that people want to study, from the simplest integers to the complex planes, which can be seen as objects, not only to represent specific things, but also to represent abstract rules, plans, or events. There is also the definition of "everything is an object" but object-oriented can not be simply equivalent to the understanding of programming for anything, in the face of all programming? Joking, hehe.

Therefore object-oriented object, refers to objects. The so-called object refers to the objective entity and the subjective abstract concept.

Second, why object-oriented

object oriented is to solve the maintainability, extensibility, reusability of the system, Let's think about why object-oriented can solve the maintainability, extensibility, reusability of the system.

object-oriented historical reasons have the following two points:

1, the computer is to help people solve the problem, but the computer is eventually a machine , he will only follow the code written by the person, step-by-step execution, and finally get the results, so no matter how complex the program, the computer can always easily cope. Structured programming is the code that is written according to the computer's thinking, but when people see such complex logic, they cannot maintain and extend it.

2, structured design is to design and construct application system with function as the goal, This kind of practice leads us to design the program, we have to map the real world of the object to the solution space composed by the function module, which deviates from the basic idea of people to observe and solve the problem.

visible structural design in the design of the system, can not solve the reuse, maintenance, Extensions, and can lead to logic that is too complex and obscure in code. So people think, can let the computer directly simulate the reality of the environment, with the human problem-solving ideas, habits, steps to design the appropriate application? Such a program, when people read it, will be easier to understand, and do not need to put the real world and the program of the world back and forth between the conversion.

at the same time, it was found that The object that exists in the real world is the protagonist in the problem domain. The so-called object refers to the objective entity and the subjective abstract concept, which has attributes and behaviors, and the object is stable, the behavior is unstable, and the object has all kinds of relations, so the object-oriented programming, the system will be more stable than the behavior-oriented programming. In the face of frequent changes in demand, the change is often behavior, and the object generally does not need to change, so we encapsulate the behavior, so that the change only need to change the behavior, the main structure remains stable.

So the object-oriented is produced.

But how is the system maintainability, extensibility and reusability embodied in the object-oriented?

First look at the three main features of object-oriented:

package: Find the change and wrap it up, You can modify or extend the changed parts of the package without affecting the other parts, which is the basis of all design patterns, which is the encapsulation change, so the role of encapsulation solves the scalability of the program.

inheritance: subclasses inherit the parent class and can inherit the methods and properties of the parent class. The multi-state and code reuse are realized, so the reusability and expansibility of the system are also solved. But inheritance destroys encapsulation because he is open to subclasses, and modifying the parent class causes all subclasses to change, so inheritance is somewhat disruptive to the system's extensibility, so inheritance needs to be used with caution. Only a definite is-a relationship can be used, while inheriting in the process of program development, rather than using inheritance at the beginning of programming, many object-oriented developers abuse inheritance, resulting in later code can not solve the changes in demand. Therefore, it is an important experience in object-oriented development to prioritize the use of combinations rather than inheritance.

polymorphism: Many different implementations of interfaces are polymorphic. Interface is the abstraction of behavior, just mentioned in the encapsulation, find the change part and encapsulate it, but after encapsulation, how to adapt to the next change? This is exactly what the interface does, and the main purpose of the interface is to provide generic processing services for unrelated classes, which we can imagine. For example, a bird can fly, but Superman can fly, by flying this interface, we can let birds and Superman, both realize this interface, which realizes the system maintainability, extensibility.

So object-oriented can realize the system maintainability, extensibility that people pursue, Reusability. Object-oriented is a kind of programming idea, at first, "object-oriented" refers to the design method of encapsulation, inheritance, polymorphism and so on, but the object-oriented thought already involves all aspects of software development, such as subdivision for object-oriented analysis (OOA), Object-oriented design (OOD), Object-oriented Programming implementation (OOP)

Three, object-oriented programming, divided into several steps?

object-oriented is a kind of thought, he let us in the analysis and solve the problem, Turn the thinking and the focus to the real object, then through the UML tools to clarify the relationship between these objects, and finally use object-oriented language to achieve the relationship between the object and the object. It is divided into object-oriented analysis (OOA), Object-oriented design (OOD), object-oriented programming implementation (OOP) three large steps.

1, the first is the analysis of requirements, first of all, do not think how to use the program to achieve it, First, we analyze what is the stable object in demand, and what is the relationship between these objects.

2, the first step to analyze the needs, through the further expansion of the model into an achievable, cost-consistent, modular, low-coupling high cohesion model.

3. Using object-oriented implementation model

Four, process-oriented thinking how to change?

When we're used to process-oriented programming, The main reason to find that there is no need for object-oriented anywhere in the process is that there is no change in thinking. Programmers usually get a demand, the first reaction is how to achieve this demand, which is a typical process-oriented thinking process, and it may soon be realized. But object-oriented, the face is the object, the first step is not to consider how to achieve demand, but to carry out demand analysis, is to find the object in accordance with the needs, and then find the relationship between these objects. Therefore, the key point of the process-oriented and object-oriented thinking transformation is that in the first step design, after getting the demand, must not consider how to implement it, but through UML modeling, and then follow the UML model to implement it. This shift in thinking may require a process.

V, object-oriented and object-based differences

"Object-oriented" and "Object-based" implement the concept of "encapsulation", but object-oriented implements "inheritance and polymorphism", and "object-based" does not implement these. So in our web development, the general three-tier development, is basically object-based implementation, because only the encapsulation, but not the use of inheritance and polymorphism. However, this is normal, web development, most of the function is simple to delete and change, the middle of the BLL layer is directly new instance of the Dal to return, the relational database has done a lot of work for us, so most of the work is simply read and then show. So there is no complicated need, there is nothing wrong based on the process, there is nothing wrong with the process, and practicality is the overriding factor.

"What is an object, why object-oriented, and how can it be object-oriented?" 】

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.