I'd like to propose my problem [sorry for my english!!!]
I'm implementing the concept of time range that is something having
start, end date and duration.
I started defining a class called "Slot" with three properties:
Start, End, Duration, with their relative "setter" and "getter", and a
static method to compute the intersection between two Slot.
Than I discovered that I need the "concept" of read-only Slot (an
invariable time-range), so I removed the setters from Slot and I moved
them to a derived class called "ModifiableSlot".
So I decided to make my Slot class to be abstract and inherit from it
two class: "ReadOnlySlot" and "ModifiableSlot".
Making this I had a problem with my static method used to compute the
Intersection... How can it create an instance of Slot and which kind
of Slot? Since the class is now abstract I cannot create any instance
of it! I may create a new abstract "factory" method and the intersect
method should call this, but... I don't think this is a good solution,
because I need an instance of Slot to create a new Slot!!!
static Slot ComputeIntersection( Slot slot0, Slot slot1 )
{
...
return slot0.CreateNewSlot( intersectionStart,
intersectionStart ); // I could use slot1.CreateNewSlot... Mmmh, it
doesn't seem a good solution!
}
Using the Abstract Factory Method pattern I need to move all
operations that create a instance of Slot in the Factory (is it
true?), so "ComputeIntersection" (and all other operations on Slot
resulting to a new Slot) should be moved to the factory. But I think
it's a little annoying having a reference to a factory just to compute
an 'simple' operation.
What do you think? Could anyone give me a suggestion?
Thank you.