OO Design question

Hi,

this is my question:

I have some heterogen classes lets say:

class A, class B, class C and class D

class A implements

method a

method b

method c

method d

method z

class B implements

method e

method f

method c

method d

method z

class C implements

method g

method h

method i

method j

method z

class C implements

method k

method l

method i

method j

method z

I'd like to group all common methods in a single class. How can i do this?

Thanks a lot.

[632 byte] By [nereidahoxhaja] at [2007-10-2 10:33:39]
# 1

Hardly a patterns question, and not very advanced, either.

You have a couple of choices, depending on whether you prefer inheritance or composition. You can have three interfaces or abstract classes:

public interface CDInterface

{

void c();

void d();

}

public interface ZInterface

{

void z();

}

public interface IJInterface

{

void i();

void j();

}

Now your classes look like this:

class A implements CDInterface, ZInterface

{

public void a();

public void b();

public void c();

public void d();

public void z();

}

Class B implements CDInterface and ZInterface

Class C implements IJInterface and ZInterface

Class D implements IJInterface and ZInterface

If they all share implementation, make those interfaces abstract classes.

I don't know what this buys you.

%

duffymoa at 2007-7-13 2:19:24 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
> Hardly a patterns questionI realized it is not a patterns question that's why i decided to post it at Programming Forum.Thanks anyway
nereidahoxhaja at 2007-7-13 2:19:24 > top of Java-index,Other Topics,Patterns & OO Design...
# 3

> > Hardly a patterns question

>

> I realized it is not a patterns question that's why i

> decided to post it at Programming Forum.

Don't post it twice.

> Thanks anyway

What's this? You don't like the answer? Not what you had in mind? This is a perfectly good reply. "Thanks anyway" implies "this wasn't helpful". If that's so, what else could you be looking for?

It's a better answer than your question deserves.

%

duffymoa at 2007-7-13 2:19:24 > top of Java-index,Other Topics,Patterns & OO Design...
# 4
> I'd like to group all common methods in a single> class. How can i do this?There's also a why. A class or an interface preferrably is a coherent type with a specific behaviour, and not just an arbitrary collection of unrelated methods.
duffymoa at 2007-7-13 2:19:24 > top of Java-index,Other Topics,Patterns & OO Design...