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.