Pregunta

i have to implement data structures that support abstract Numbers

Collection is a collection of numbers

sorted is a sorted collection

list is a list collection of numbers (include duplicates)

set is a collection of numbers without dup.

Linked and Array are the format of the saved data (linked meaning diffuse in the heap and array meaning a contious amount of memory)

then there are combinations of classes (a list that is array called arraylist and etc. in the picture)

a simple uml:

uml3;

each of the last four combinatios (last row in the pic) need to implement a method call sorted that make a sorted copy of their own (return Sorted type). i thought to make 4 new classes that are inheritance from sorted and the classes in the last row (for ex. an ArrayListSorted class that inheritance from Sorted class and ArrayList class) but then i have the diamond problem (in the same ex. Sorted and ArrayList are both Collection offspring)

any better idea for disign?

¿Fue útil?

Solución

In C++ the diamond problem can be solved by using virtual public inheritance. With virtual public inheritance the base class is inherited only once:

class A {...};
class B : virtual public A {...};
class C : virtual public A {...};
class D : public B, public C {...};
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top