2024-07-08
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
This article describes the following directions:
1. Object-oriented and process-oriented
Object-oriented: Create objects for the black and white sides to be responsible for calculation, the object for the chessboard is responsible for the canvas, and the object for the rules is responsible for judgment. From the example, we can see that object-oriented pays more attention to not reinventing the wheel, that is, create it once and reuse it.
Process-oriented: start - black moves - board - judgement - white moves - board - judgement - loop. You only need to focus on how to implement each step.
2. Three characteristics and five basic principles of object-oriented
Encapsulation
Encapsulation means encapsulating objective things into abstract classes, and the class can only allow trusted classes or objects to operate its own data and methods, and hide information from untrusted ones.
Encapsulation is one of the characteristics of object-oriented programming and is the main feature of the concept of objects and classes. Simply put, a class is a logical entity that encapsulates data and the code that operates on this data. Inside an object, some code or some data can be private and cannot be accessed by the outside world. In this way, objects provide different levels of protection for internal data to prevent unrelated parts of the program from accidentally changing or incorrectly using the private parts of the object.
Inheritance
Inheritance refers to the ability to use all the functionality of an existing class and extend it without rewriting the original class.
The new class created through inheritance is called a "subclass" or "derived class", and the inherited class is called a "base class", "parent class" or "super class". The process of inheritance is a process from general to specific.
There are two ways to implement the concept of inheritance: implementation inheritance and interface inheritance. Implementation inheritance refers to the ability to directly use the properties and methods of the base class without additional coding; interface inheritance refers to the ability to use only the names of properties and methods, but the subclass must provide the implementation.
Polymorphism
Polymorphism means that the same method of a class instance has different expressions in different situations. The polymorphism mechanism enables objects with different internal structures to share the same external interface. This means that although the specific operations for different objects are different, they (those operations) are shared through a common class.