I just found out a little about Composition over inheritance . I was wondering if I should apply the concept to what I wrote recently.
We previously had two classes that were almost the same, except for a couple of small differences. They contained some basic database access functions, but worked on different (but related) types of objects. So we previously had a class that was structured like this:
class BallMillDBHandler{
public BallMillDBHandler(){ ... }
public void InsertTool(BallMill tool) { ... }
public BallMill QueryTool(string toolID) { ... }
public void UpdateTool(BallMill tool) { ... }
public void DeleteTool(string toolID) { ... }
}
class DiamondToolDBHandler{
public DiamondToolDBHandler(){ ... }
public void InsertTool(DiamondTool tool) { ... }
public DiamondTool QueryTool(string toolID) { ... }
public void UpdateTool(DiamondTool tool) { ... }
public void DeleteTool(string toolID) { ... }
}
I took most of the almost duplicated methods and reorganized them into a class BaseToolDBHandler()and inherited it from the other two, providing several abstract methods and properties to handle differences in access to the database parameters themselves.
BaseToolDBHandler , , /? ?