Re: Separation of concerns



"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
}
}
.