Inheritance abuse in Java

Problem: I am going through the code, Written by somebody else.

public interface FileManipulator
public abstract class FileRepository implements FileManipulator
public class CommonFileRepository extends FileRepository
public class Project1FileRepository extends CommonFileRepository
Some where else they encapsulated Project1FileRepository class.

Given requirement: Program need to read license agreement for project only once. It is not going to change across the project.

Solution:

public class ProjectLicense
{
public static String getLicenseText()
{
// Read the license text from file and return.
// Better to put in static variable and avoid reading again.
}
}

-o-

Interesting facts about Inheritance depth in Java.

http://www.javaspecialists.eu/archive/Issue121.html
http://www.javaspecialists.eu/records/index.jsp

Advertisements

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 )

Google+ photo

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

Connecting to %s