Web Application Performance Design Inspection Questions - Coupling and Cohesion

From Guidance Share

Jump to: navigation, search

- J.D. Meier, Srinath Vasireddy, Ashish Babbar, Rico Mariani, and Alex Mackman


Contents

Coupling and Cohesion Issues

Issues

Implications

Not using logical layers

Mixing functionally different logic (such as presentation and business) without clear, logical partitioning limits scalability options.

Object-based communication across boundaries

Chatty interfaces lead to multiple round trips.


Use the following questions to assess coupling and cohesion within your design:

  • Is your design loosely coupled?
  • How cohesive is your design?
  • Do you use late binding?


Is Your Design Loosely Coupled?

Loose coupling helps to provide implementation independence and versioning independence. A tightly coupled system is more difficult to maintain and scale. Techniques that encourage loose coupling include the following:

  • Interface-based programming. The interfaces define the methods that encapsulate business logic complexity.
  • Statelessness. The data sent in a single call by the client is sufficient to complete a logical operation; as a result, there is no need to persist state across calls.


How Cohesive Is Your Design?

Review your design to ensure that logically related entities, such as classes and methods, are appropriately grouped together. For example, check that your classes contain a logically related set of methods. Check that your assemblies contain logically related classes. Weak cohesion can lead to increased round trips because classes are not bundled logically and may end up residing in different physical tiers.

Noncohesive designs often require a mixture of local and remote calls to complete an operation. This can be avoided if the logically related methods are kept close to each other and do not require a complex sequence of interaction between various components. Consider the following guidelines for high cohesion:

  • Partition your application in logical layers.
  • Organize components in such a way that the classes that contribute to performing a particular logical operation are kept together in a component.
  • Ensure that the public interfaces exposed by an object perform a single coherent operation on the data owned by the object.


Do You Use Late Binding?

Review your design to ensure that, if you use late binding, you do so for the appropriate reasons and where you really need to. For example, it might be appropriate to load an object based on configuration information maintained in a configuration file. For example, a database-agnostic data access layer might load different objects, depending on the currently configured database.

If you do use late binding, be aware of the performance implications. Late binding internally uses reflection, which should be avoided in performance-critical code. Late binding defers type identification until run time and requires extra processing. Some examples of late binding include using Activator.CreateInstance to load a library at run time, or using Type.InvokeMember to invoke a method on a class.

Personal tools