Wednesday 12 March 2014

Programming to Interface not to Implementation

 "Use interfaces (pure abstract) classes during development instead of concrete classes. And provide their implementations through concrete classes."

Architectural and Design Prospect

"Programming to Interface not to Implementation" is an architectural and design concept in software engineering. When architects go to design an application then they break the application in following units

  • Main Components
  • Sub Components
  • Communication between main components
  • Inter-communication of sub-components inside the components
Architects don't care how these components will be implemented regardless the technology. They just take care of following factors

  • Performance in real scenarios
  • Extensibility of application
  • Customization in future
  • Maintainability of application
  • Minimal coupling
  • Many other factors

If we just think about these factors then we can easily understand the importance of  "Programming to Interface not to Implementation" concept.
When design phase comes in action then just signature and contract interfaces with reference methods are introduced. The implementations of these interfaces are left provide during development of application.
The interfaces are used because all factors like performance,maintainability, customization can be achieved.

When design is completed and prototype is developed then dummy implementation of designed interfaces is provided. Actual implementation can be provided during actual development

Benefits of 'Programming to Interface not to Implementation'

Here are some benefits of this approach
  1. Performance in real scenarios
  2. Scalability
  3. Customization in future
  4. Maintainability
  5. Minimal coupling
  6. Easy to understand
  7. Transfer of Knowledge
  8. Test-ability
Here some of the above are explained to introductory level

1. Performance in real scenarios

Performance is the key and most vital issue for both internet, enterprise and small applications.
How interfaces help the program to boost its performance. As we know interfaces are pure abstract classes by default and can not be instantiated and they have no methods definitions. So no memory allocation is needed for interfaces.
When interfaces are used formal arguments during the development then compiler and run-time environments understands that their implementations will be received at execution time, either these actual implementations of interfaces are present in the memory or are initialized at execution time.
Compiler and interpreter just uses name references of methods not actual implementations.
These approaches take off too much headache from interpreter and run-time environments.

2. Scalability

Scalability is a great and tough challenge for any application. Suppose currently you have provided implementations those supported 1000 devices after one year your system expands and supports 1 million devices for which you need new implementations. Now you have no worry just replace the concrete implementations with new implementations and you have no worry about about components dependencies.

3. Customization of code

If you want to introduce or remove some functionalities from existing code, then just add or remove the methods from interfaces and whole code will point you to make changes where needed.
You also can change the implementation code without dependencies worry.

4-Easy to understand

If the working software engineers are shuffled then its too much easy for new ones to understand existing code and application dependency scenarios.

No comments:

Post a Comment