I. Opening and closing principle
Open to extensions to modify close
1, more use the way of inheritance to modify the original behavior, rather than directly modify, define the extension in the subclass method
2, multi-state of the form, to reuse (the parent class with virtual definition polymorphism method, subclass with override override method, instantiate to the subclass of the parent class object, call method can achieve polymorphism)
3, a variable we do not directly to modify, but in the form of a method
Ii. Single principle
With only one cause of change, too much responsibility for coupling reduction can also affect reusability
1, class, method to do only one kind of things
2, Interface single principle interface (with multiple inheritance methods to inherit multiple interfaces, the interface internal method alone, to avoid interface waste)
Iii. Principles of Dimitri (minimum knowledge principle)
A module or object is less interacting with other entities than possible
1, only the functional part of their own operation, using the middle class to change it
Iv. Principles of Synthetic multiplexing
An object that uses some of its own objects or combinations of objects do not use inheritance
1, multi-inheritance relations become complex
2, abstract a kind of ha-a relationship is-a relationship
Summarize:
A game is divided into many modules, according to a single principle, the function module separation clearly, each module below a lot of functions, each function to follow the Dimitri principle, the different functions of different scripts, easy to modify. For a single script, we use the inheritance method to modify, for the method, we use a polymorphic way to modify, for variables, we use more methods, rather than directly modify. Finally, the naming convention is important, class name: First letter uppercase, variable: first letter lowercase, other first letter uppercase, abide by the Hungarian naming convention. According to these principles, many design patterns have been defined.
Design principles of software development