Design principles of software development

Source: Internet
Author: User

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

Related Article

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.