Code Design - Choosing Abstract or Interface - Level 100

More often we wont get a chance to work on these aspects in early stage of your career. Even at the time of mid career getting a work related to API designing/Development is bit difficult. Unless you have a very good mentor in your initial career you will never get to know the real time. And you will end up in theoretical knowledge if you are computers academics. Others need to witness nightmares :-)

Always try to implement good design in your day to day work. Never try to concentrate on these concepts for the matter of career growth. Only the passion to write a good code lets you to remember things. Design patterns are not meant for only senior programmers. You need to have a little bit knowledge on nitty-gritty of OOP/OOD concepts.

And I need to say that continuous practice only lets you to excel further in OOP/OOD concepts irrespective of your experience levels.

Here are some basic recommendations to help you to decide whether to use an interface or an abstract class to provide polymorphism for your components.

  1. If you anticipate creating multiple versions of your component, create an abstract class. Abstract classes provide a simple and easy way to version your components. By updating the base class, all inheriting classes are automatically updated with the change. Interfaces, on the other hand, cannot be changed once created. If a new version of an interface is required, you must create a whole new interface.
  2. If the functionality you are creating will be useful across a wide range of disparate objects, use an interface. Abstract classes should be used primarily for objects that are closely related, whereas interfaces are best suited for providing common functionality to unrelated classes.
  3. If you are designing small, concise bits of functionality, use interfaces. If you are designing large functional units, use an abstract class.
  4. If you want to provide common, implemented functionality among all implementations of your component, use an abstract class. Abstract classes allow you to partially implement your class, whereas interfaces contain no implementation for any members.

Remember there is nothing like ideal code base design. There will be always a scope of improvisations and caveats as well. 

Comments

Popular posts from this blog

Download file using WCF REST services

server side printing / PDF conversions using c# and asp.net/wcf service

Finding file size in bytes on serverside using c#