Re: Separation of concerns
- From: "Daniel T." <daniel_t@xxxxxxxxxxxxx>
- Date: Wed, 28 Mar 2007 19:26:44 GMT
"Thomas Kowalski" <th-ko@xxxxxx> wrote:
I am currently quite confused about the separation of concerns things
and search here for enlightenment.
It means to keep variables, functions, objects, abstractions as focused
as possible.
I have some classes. lets say A and B that shall implement a certain
interface (e.g. Drawable).
Now it would not be very nice if A and B would implement then directly
or?
Should I subclass like A_Draw and B_Draw or what is the current
pattern to solve this?
The best pattern depends on the context. How different are A and B's
draw method? How alike are they? Chances are you should have a separate
class that serves as a drawing helper.
If using a dynamic-typed language:
class Drawer:
def helpDrawBegin(self):
def helpDrawEnd(self):
class A (Drawer):
def draw(self):
class B (Drawer):
def draw(self):
if using a static-typed language:
interface Drawable {
void draw();
}
class Drawer {
void helpDrawBegin();
void helpDrawEnd();
}
class A implements Drawable {
private Drawer drawer = new Drawer();
void draw() {
// use drawer
}
}
class B implements Drawable {
private Drawer drawer = new Drawer();
void draw() {
// use drawer
}
}
.
- Follow-Ups:
- Re: Separation of concerns
- From: Thomas Kowalski
- Re: Separation of concerns
- References:
- Separation of concerns
- From: Thomas Kowalski
- Separation of concerns
- Prev by Date: Re: Separation of concerns
- Next by Date: Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- Previous by thread: Re: Separation of concerns
- Next by thread: Re: Separation of concerns
- Index(es):