Tech Titbits

August 22, 2008

Code Reusablity…

Filed under: Code Reusability — Mahesh Tabib @ 8:13 pm

Rusability has always been an interesting topic. When determining how best to tackle the large amounts of variations in the application, several factors have to be considered.  These factors include code maintainability, code reuse, development effort, etc.  Reusable code requires an effective combination of two points…
1.    Properly defined interface definitions
2.    Efficiently defined class structures and inheritance
One benefit of establishing interface definitions is that every class that implements an interface must adhere to that interface’s functional requirements.  The fact that multiple sets of variations can share a given class implementation demonstrates how implementation logic can be reused in the system.
The interfaces must be defined in such a way as to maximize its ability to be reused.  Large interface definitions (too many functions) can render an implementation class virtually impossible to reuse.  Whereas a single function interface can lead to a class proliferation problem (too many classes).  The balance must be struck somewhere in between with medium sized interfaces (fewer functions).
In addition, more code sharing occurs within each implementation class.  Based on the class structure established at development time the implementation classes can be organized according to their interface group type and can allow inheritance to access common logic.  By extending implementation classes from a categorized base class a developer can “promote” common logic to the parent class thus reducing the amount of redundant code.  When promotion of common code to a parent class starts to become impossible it might be time to re-evaluate the size of the underlying interface.
The combination of inheritance along with composition reduces the amount of duplicate code present in the system. Interface modifications may be required in the ongoing effort to balance the amount of logic that can be promoted to base classes as the number of implementation classes increases. Make a code reusable and avoid redundant code, isn’t this great.

Advertisement

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.