Comparison of object, class, abstract class, and interface concepts

Source: Internet
Author: User
Object. class. abstract class. these interfaces should be the basic concepts of OOP. However, when someone really asks me their meanings and differences, they will actually get into a language. It seems that I still have not really understood these concepts, in this case, let's look back and start with the basics,

1. first of all, objects (Objects: objects, goals) in English can represent everything in the world. Everything can be labeled as an object, A carrier of research. even some things in the spiritual world can be used as an object, so the object is not only actually "existent", but also perceived by us.
In our Chinese life, the object "is often used for" men and women "in modern Chinese, so I will understand it from the habits we Chinese take for granted. the target is my girlfriend (unfortunately, I can only perceive it now ...), she has many features: Beautiful beautiful, love shopping )... cry .... wait, if I use abstract thinking to understand her, then she will become a class (girlfriend class ):

2.; class:
Class mygirlfriend (){
Public appearance;
Private heart;
Private coquetry ();
Public shop ();
Public cry ();
}
Among them: "appearance, heart" is her personal characteristics (attribute: attribute), Public indicates public, outsiders can see at a glance, private indicates internal, invisible to ordinary people (maybe only I know, hey ...),
Coquetry (); shop (); cry (); is a common behavior of her. "coquetry" indicates the behavior shown during shop and cry, for example, if she wants to take you shopping, she will first give you one thing: coquetry (), in order to implement the shop method (GOAL) maybe she will call other methods (Khan ...). cry () behavior may also be a means for her to "Spoil ()" to you. in this case, the difference between private and public: If I want her to coquetry (), I am afraid it will not work. I have to propose bringing her shop () first ().

2. Let's talk about the example again. (words are forgotten ,,)
These are just my assumptions. I hope to have such a GF. If I don't have it, there is only one method: Find (new ).
If yes, a new object is successfully created. creates an instance named "mygirlfriend... if you are new, you can find a lot of girlfriends...

3. Interface: this does not seem easy to describe. Please help me to add it.
An interface is used to describe what functions you want to implement, but a class is used to describe how to implement"
Member variables cannot be defined in the interface. Only methods and static variables (can be constants) can be declared.
The interface has a "like-a" relationship with the class that implements this interface.
The modifier can only be public,
4. abstract class (class modified by AbstractA)
When you don't know what kind of girlfriend you want, you can use an abstract class.

 

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.