I am creating an OO structure and I am facing the following problem.
Let's say that I have a Shape interface in the structure, and users can freely implement and extend (adding new functions) the Shape interface to create their own shapes, for example. Area and circle. For these new objects to be available, users must register them with a ShapeFactory by specifying the name of the form (line) and object.
In addition, the environment provides a ShapeWorker interface that defines the following function:
class ShapeWorker
{
public:
void processShape( Shape& shape ) = 0;
};
Users are free to implement the ShapeWorker interface to make a particular form worker, for example. SquareWorker and CircleWorker. For these new objects to be available, users need to register them with WorkerFactory by specifying the name of the form (line) and object.
At some point, the structure given by the string representing the name of the form creates a new Shape using a ShapeFactory, and then (elsewhere in the code) creates a new ShapeWorker using a WorkerFactory with the same shape name. Then processShape is called, providing the previously created Shape instance.
[ ... ]
Shape* myShape = shapeFactory.create( shapeName );
[ ... ]
ShapeWorker* myWorker = workerFactory.create( shapeName );
myWorker->processShape( *myShape );
[ ... ]
The fact is, by doing this, I force the user to implement, for example, SquareWorker to take a picture from Shape to Square in the processShape function in order to access the full Square interface:
class SquareWorker
{
public:
void processShape( Shape& shape )
{
Square& square = dynamic_cast< Square& >( shape );
}
};
This contradicts the Liskov signature principle.
, ? ? , processShape Shape.
, .
.