Sunday 10 January 2016

How to identify and design a Class?

This is an art; each designer uses different techniques to identify classes. However according to Object Oriented Design Principles, there are five principles that you must follow when design a class,
  • SRP - The Single Responsibility Principle -
    A class should have one, and only one, reason to change.

  • OCP - The Open Closed Principle -
    Should be able to extend any classes' behaviors, without modifying the classes..

  • LSP - The Liskov Substitution Principle-
    Derived classes must be substitutable for their base classes.

  • DIP - The Dependency Inversion Principle-
    Depend on abstractions, not on concretions.

  • ISP - The Interface Segregation Principle-
    Make fine grained interfaces that are client specific.


Additionally to identify a class correctly, you need to identify the full list of leaf-level functions or operations of the system (granular level use cases of the system). Then you can proceed to group each function to form classes (classes will group same types of functions or operations). However a well-defined class must be a meaningful grouping of a set of functions and should support the reusability, while increasing expandability or maintainability, of the overall system.
In software world the concept of dividing and conquering is always recommended, if you start analyzing a full system at the start, you will find it harder to manage. So the better approach is to identify the module of the system first and then dig deep in to each module separately to seek out classes.
A software system may consist of many classes. When you have many classes, it needs to be managed. Think of a big organization, with its work force exceeding several thousand employees (let’s take one employee as one class). In order to manage such a work force, you need to have proper management policies in place. Same technique can be applied to manage classes of your software system. In order to manage the classes of a software system, and to reduce the complexity, system designers use several techniques, which can be grouped under four main concepts named
1. Encapsulation
2. Abstraction
3. Inheritance
4. Polymorphism.

These concepts are the four main gods of OOP world and in software term, they are called four main Object Oriented Programming (OOP) Concepts.

No comments:

Post a Comment