Tuesday 11 January 2011

Basics of software design

What are the characteristics of good design? How can we identify the gaps in design? How to review other designs? We shall try to find answers to those questions.
The fowling characteristics are considered to be adhered in a good design.

• Strong cohesion
• Loose coupling
• No redundancy
• Testability of all the features by itself.

Strong cohesion

In computer programming, cohesion is a measure of how strongly-related the functionality expressed by the source code of a software module is. Cohesion of class/method is about having single responsibility and fulfilling it. It is not about how strongly they are related to each other.

Loose coupling

In computing and systems design a loosely coupled system is one where each of its components has, or makes use of, little or no knowledge of the definitions of other separate components.
The coupling can be observed in the code wherever (as class variables, method parameters or return types or method variables) class is accessed from other class. Worst form of coupling is one class accessing base type and sub type of a class hierarchy). Except while constructing the object, everywhere else the base type should be used.

let us continue...


No redundancy

Redundancy of relationships, code should be avoided. This is where we can use different patterns of design.
If similar functional code is used in multiples places in the depot, it needs attention. If you are switching in the code, on the same values in multiple paces, then the design needs to be relooked.

If(x==value1)
Do this
Else If(x== value2)
Do this
…..
If(x==value1)
Do this
Else If(x== value2)
Do this

Testability

If all the features/ modules/methods/ classes are testable for their functionality we can call it well designed code. If this can be achieved by using some mocks in case of modules/features. It the application doesn’t allow some unit test to be written for any of the above then we can relook the design.
Just think about the difference between Static method and class method. The former needs class and later needs object. Similarly the class should be testable itself - construct the class and call the methods in right order. Similarly create the module to construct the classes, use mocks for other modules etc.

No comments:

Post a Comment