----

Friday, August 2, 2013

OOPS Design Principles

Why Object Oriented Design Principles(OOPS)?


Software design principles represent a set of guidelines that helps us to avoid having a bad code or design. These are GRASP and SOLID. Programming is full of acronyms like these.
Other examples are : DRY (Don’t Repeat Yourself!) and KISS (Keep It Simple, Stupid!).
But there obviously are many, many more, some of them will be listed here.

Object Oriented Design (OOD) Guidelines:
During the design process, as we go from requirement and use-case to a system component, each component must satisfy that requirement, without affecting other requirements. Following are points to avoid Design hazard during the analysis and design process.
  • Inheritance
  • Coupling Types and Degree
  • Cohesion 
  • Optimization Techniques
  • Restructure (Refactoring) Consideration
It is said that 'Don't be STUPID: Be GRASP & SOLID!'
Ever heard of SOLID code? Probably: It is a term used by Robert Martin for describing a collection of design principles for "good and clean" code. 

To start understanding of these design principles, why not approach the problem from the other side for once? Looking at what makes up bad code.

Sorry, but your code is STUPID!
Nobody likes to hear that their code is stupid. It is offending. Don’t say it. But honestly: Most of the code being written around the globe is an unmaintainable, unreusable mess.

So what characterizes such code? What makes code STUPID?
  • Singleton
  • Tight coupling
  • Untestability
  • Premature Optimization
  • Indescriptive Naming
  • Duplication

So what are the alternatives to writing STUPID code?
The answer is, make it Simple, SOLID and GRASP.

What are SOLID rules?

  • Single responsibility principle
  • Open/closed principle
  • Liskov substitution principle
  • Interface segregation principle
  • Dependency inversion principle

What is GRASP ? 
GRASP stands for General Responsibility Assignment Software Principles / Patterns, which are the following:

  • Information Expert
  • Creator
  • Controller
  • Low Coupling
  • High Cohesion
  • Polymorphism
  • Pure Fabrication
  • Indirection
  • Protected Variations
OOPS design principles are explained in details in next section.

1 comment :