Before we formally start discussing, how to compile a graphical interface program? Let's first talk about object-oriented programming design. Actually, the object-oriented concept appeared in the 1960s. With the appearance of modern operating systems and the development of graphical user interface, the object-oriented concept has become a necessary tool for programmers. Is it difficult to understand? Actually, no. Look. All of them are objects. Next, let's take a look at how to abstract those objects in life into "objects" in programming. In the early and middle 1990s, the object-oriented programming concept was prevalent including the currently popular C++. The currently most recognized object-oriented features are John Mitchell of Stanford University, proposed in the book entitled Concepts in Programming Languages in 2003. dynamic binding, abstraction, subclass polymorphism and inheritance, among others. Our most vivid feeling of object-oriented concept is that the real word is depicted as a series of fully autonomous and encapsulated objects. For accessing, a protected interface is utilized. Besides, object orientation has many other advantages. We'll feel them in subsequent lectures. In our course, the focus is on the two concepts, abstraction and inheritance. In this class, let's look at abstraction first. Take an animal – dog for example. There are two dogs, the upper one is named Aoao, and the lower one, Jiaojiao. The puppy Aoao has ears, nose, 4 legs, etc. able to bark, run, and have a good nose. The other puppy Jiaojiao also has ears, nose, 4 legs. able to bark, run, and have a good nose. If we observe all healthy dogs in nature, can we draw such a conclusion: all healthy dogs have ears, nose, 4 legs, able to bark, run, and have a good nose regardless of which dog it is? These described attributes are actually about the species of dog abstracted from all dogs, which are features different from other animals. Such an abstracted model representing a given class is called a "class" by us. A specific real entity belonging to this class is called an "instance" or "object". In this case, the puppies Jiaojiao and Aoao are two instances of the class "dog". For example, a dog called Wangcai, is also an instance of the class "dog". This method of abstraction into class, when applied into programming is called "object-oriented" programming. In software development, we may, based on design requirements, abstract real world entities into classes in a way similar to the case of puppies. Solving problems with such a method, is more close to the daily life and natural thinking pattern easy to improve the efficiency and quality of software development. Let's return to the graphical user interface we mentioned before. Take buttons for example to explain why graphic elements of this class ("refresh" and "quit"), are abstracted into "buttons". As we see, each of them has a text label. Despite the difference in texts, the fact that such a label exists on each button shows the usage of this button. Also, each of them has a rectangular box to mark the area of button. When this area is clicked with a mouse, the shape of border will change to indicate the confirmation of user event. They are their shared common features, Nonetheless, they have differences including label texts, button sizes and button actions after pressed. These non-essential differences will be abandoned during our abstraction process. Finally, the abstracted button should be a rectangular box with texts, generally, with decorations of something like a shadow, and, in case of occurrence of user clicking event, provide confirmation, to trigger off a given action. It's such a graphical interface element. It's distinct from other graphical interface elements, like a list box to show data, or an input box to input texts. Here again. There is a button whose label is "refresh". It's obvious that, we can create another button like "back" etc. They have their own different usages. Those real and specific entities in programming as we know, are called "instances". To sum up, the objectification of class is objects, while objects can be abstracted into classes. There's one question for you. which is a template? and which is in the category of value? Should a class be a template? It describes the features of objects, while objects are objectification of classes, so they are values. Let's look at how a class is defined. The keyword is class, immediately followed by a class name. In Python, for defining, it's often to add a pair of parentheses after the name of class, while the contents enclosed in the parentheses are the parent class of the defined class. We'll mention the concept of parent class later. If your class does not inherit any parent class, object will be the default parent class, so we call "object" the root of the class hierarchy. There are new classes in the current Python version We can remove the default brackets and objects after the class name You must be familiar with the string below. It is a DocString. Here, it is a document string for class. When inquiries about classes are made, it may provide some help information. Further below is the class field code, which includes data, and the operations available for instances in this class. Here, let's make an attempt to define an empty class for doing nothing. Then, the class field should be null. We add "pass" here, "pass" is a keyword. as a statement, to represent doing nothing. As we see here, the class "MyDate" has no specific effect indeed. We call such a situation "a class being a namespace". It's easy to understand the so-called namespace. It can be regarded as a container or a field. We add something into an empty class. During the process of abstraction, we put the shared data and behavior into the definition of class. into the definition of class. The attributes in a class define the abstracted data. We'll talk about that later. Well, what would the shared behavior be after abstraction? It is the method in class defining. Take the puppies we mentioned before for example. A class "Dog" is defined, and there is a method "greet()", which will output "Hi!" meaning that a dog will say hi. It's quite easy. After the name of method, we see a "self", which is an interesting part in Python. The defining of class method in Python requires the first argument in each method declaration to be "self". What does it mean. It means that the object calling this method, when calling, does not require an actual argument corresponding to itself. However, we should note that a method is only a function defined inside a class, and it can only be called, when the class it belongs to has instances. So, only when there exists an instance, can a method be regarded as being bound to this instance. And, as we know, a class is only a standard, a template. so, in real development, in more cases, we need to, based on this standard create instances representing objects one by one. You need to create the same quantity of instances as that of objects to represent. Let's look at the creation of instance. It's quite easy. We may use a class name, plus parentheses, to create it in such a manner. Assign its result to a variable. This variable is actually a name of instance. And, we may resort to such a mode of "instancename.method()" to call an instance method. So, in common object-oriented, programming, the several steps are like this: define a class, next, create an instance and use the attribute or method through the instance. Here, our class is Dog, the instance is dog (in the lower case), then, through such a mode "dog.greet()", use the instance method. Our example here is to use an instance method. But, much of the time we need to use attributes through the instance. For example, a puppy has its name like Wangcai or something else. Let's look at the program. After applying an instance, we may, in such a manner, transfer the argument to the formal argument. "self" points to the instance itself, Python will automatically pass the object as the first parameter to the method. "self" here refers to the dog instance Python will automatically pass "dog" to "self" of setName() What would the effect be? "self.name=name" is equivalent to "dog.name="Paul"". This is an instance attribute. In the method, we may use this instance attribute and we may also create many instances giving them different names. The result of program running is like this. It is jointly completed by the function setting the instance attribute, and the function setting the instance behavior. Generally, a method is executed only when called like the two methods of "greet()" and "setName()" here. In Python, there is a type of special methods, called "__init__()". It is a method that Python will automatically call after an object is created. Let's look at an example. After the class "Dog" has an instance, it would be automatically named. This method should be realized for each instance. So, we may put it into the method "__init__()". We only need to change the previous setName into init. The other writings are the same. Defining the "__init__()" method in a class is quite prevalent. When you write your program in future, you should carefully consider what to be put into the "__init__()" method. To sum up, when we create instances, Python often does two things, one is surely to allocate memory, and the other is to call the "__init__()" method. If it is realized, "__init__()" is similar to the "initializer" in other languages. Having so said, I'd like to ask you a question. Do you guys think attributes are only related to objects? Can any two objects share the same attribute? In fact, they can. That's the class attribute we're going to talk about next. Suppose we want to define an attribute. What is it used for? For counting the number of objects created based on a class. Let's consider it. Is this attribute irrelevant to a specific object only relevant to the class? As for the attribute with such a feature, we should define it as a class attribute also known as a static attribute. Let's look for the class attribute here. What is it? It's "counter". It can be used once the class is created. As for updating, it can be updated with the method in the class or updated in the main program. Since it is irrelevant to the instance, when the class attribute is modified, we should use the form "class name.attribute". So far, we have actually discussed most of abstraction in object oriented programming. You may recall what we have talked about class, class defining, and, as we mentioned in the middle, defining of class method, followed by instance, instance attribute, "__init__()" method and class attribute. Next, let's return to the GUI library we introduced at first. Also take the button for example. Let's have a look. In the GUI class library used in our course, wxPython, what is a real class like? In the GUI class library, the most common one is probably buttons. Let's take an instance of button class for example. Normally, a Quit button includes such attributes and methods, like "label" to represent texts on the button, "Size" to represent the button size, "Setlabel" to set the button text, Enable, to set the button in an operable status. Well, have you more thoroughly understood them.