Object-oriented chaos (2)

Source: Internet
Author: User

Next, let's talk about the object concept.

Let's start with the theme of sumtec. Object-oriented is the development from the dynamic object structure to the primary object structure. Sumtec's article is very thoughtful.

The structure of the subject and the object is more vivid in describing the world. Both the subject and object are objects. From this we expand the abstraction, note that we are the abstraction of objects. For example:

James opens a fluorescent lamp.

James TurnOn (fluorescent lamp );

(This example is not very good, but in this example, do you see any strange things? I have another idea. I feel that in most cases, we still use the dynamic object structure, the behavior is often in the object. I will talk about it next time, but it may be a mess)

Then we started the abstract big method. Abstract The fluorescent lamp and abstract the ITurnable interface. NOTE: In the case of chaos (1)

I also mentioned this example. At that time, I had a question, and now I can have an answer. That is why we have two interfaces for the fluorescent lamp: ILightable and ITurnable. The answer is behavior! Abstract An object. The basis of abstraction is behavior and responsibility. The behaviors and responsibilities of this object can be abstracted based on our needs. For example, I have another behavior requirement for the fluorescent lamp. If I want it to be serialized, We will abstract the ISerializable interface.

Object-oriented is abstract-oriented, and interface-oriented. We can see that the abstraction here is for objects, based on behavioral responsibility. Therefore, the essence of object-oriented is that object-oriented abstraction is interface-oriented. Why is it called object-oriented? Because the abstract and interfaces both come from objects.

Now I started to play around. Everyone knows that the role of abstraction is to not change the original system when new objects are added later. If we add new behaviors to the original system, our object-oriented abstraction is useless. So what is the process extension like object-oriented? What if we abstract behavior and responsibility? What is the basis of abstraction? I can't figure it out myself. It comes to mind the function pointer. You may have made comments.

So what do you think of objects? Is the object a noun? Is function plus data? A better view should be an entity with certain behaviors and responsibilities. Those actions and entities are the basis of our abstraction.

Finally, let's give three sentences in <Design Patterns Explained>.

Design to interfaces.

Find what varies and encapsulate it.

Favor composition over inheritance

.

I think these three sentences are the three classic quotes of objects. You can always think about them when 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.