About Software Design

Source: Internet
Author: User
There is nothing mysterious about software design. As long as you understand it with your heart, everything is actually quite natural. The "path" of software design lies in its simplicity and naturalness, not in its design.
I. Layers of Software Design
It can be understood in the following layers:
1. Purpose: reusability and scalability.
This is the highest level and the need to respond to the software crisis.

2. Principles: low coupling and high aggregation.
The fundamental purpose of various software design principles, such as dependency inversion, single role principle, interface-oriented, and various design patterns, is to reduce coupling. Only low coupling can better adapt to changes, and better reuse and expansion.

3. Implementation Method: make rational use of the design mode and reduce coupling.
The design pattern is just a tool that encapsulates changes and reduces coupling. It is the product of the era of object-oriented design. Its essence is to make full use of the three characteristics of object-oriented, namely, encapsulation, inheritance and polymorphism, for flexible combination and application.

2. Coupling
1. Coupling Granularity
Coupling is inevitable. When we implement interfaces and inherit the parent class, coupling is inevitable. Coupling has different granularities. So far, I think the granularity of module reuse should prevail. Try to remove coupling between Reusable Modules or objects. The coupling within the reuse module should belong to the scope of aggregation, so do not blindly decouple it, otherwise it will fall into a misunderstanding.

2. Decoupling Principle
How can we decouple it, or why can various design patterns achieve the goal of decoupling? I think there are several ideas:
(1) Abstract specific things
(2) centralized processing of scattered things
The interfaces and inheritance in object-oriented systems provide us with such a mechanism. Through access interfaces, basic classes, or abstract classes, rather than specific implementation classes, decoupling with specific implementation classes. We can also design some control classes, like lubricants, to coordinate access between various implementation classes, or to achieve coupling.
In fact, this is the basic idea of various design patterns. The creation mode is used to remove the coupling generated when an object is created. In fact, the dependency on the class name is removed, and the structure and behavior type are used to cancel direct calls to object attributes or methods. Regardless of the design mode, access to specific implementation classes is promoted to access to interfaces, base classes, or control classes for coordination.

Iii. Interface
This section is more specific. Let's talk about interfaces, because using interfaces is an important means of software design, but it is no longer a "channel ~
1. interfaces and inheritance
An interface describes a behavior feature of an object. The use of interfaces and the use of inheritance have their own advantages and disadvantages. Subclass inheritance can inherit the features of the parent class, reflecting the spirit of reuse. The product is more flexible, because it removes the high coupling between the Child class and the parent class, and it is reflected in the spirit of flexible expansion.

2. interfaces and pure virtual classes
Theoretically, the interface can implement similar functions by pure virtual base classes. Why do we directly use virtual classes without removing the interface concept?
The reason why an interface exists is that it is more flexible, simple in relation, and easy to understand. For example, a class can implement more than a dozen or even dozens of interfaces, but the general development tool only supports single inheritance (because the multi-inheritance is too prone to confusion and conflict ), if we want to inherit more than a dozen layers, the system structure will be incomprehensible. I think this is the most important reason for the existence of interfaces. If interfaces and virtual class inheritance are used in combination, they can produce powerful power, which is also the "killer" of many design models ".

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.