@xerzi
I can't really think of a reason why you would want to use a factory to make a maze. |
What do you mean? As in there are better approaches to building mazes?
@TheIdeasMan
Are you talking about polymorphism? As how xerzi has shown in his code?
For example if Wall is an abstract base class, we can declare a pure virtual function in Wall that returns a pointer to Wall... |
I don't get what you mean here.
1 2 3 4 5
|
class Wall
{
public:
virtual Wall* getWall() const = 0;
};
|
Like that? I don't actually understand what this would accomplish. Could you please explain?
I get the bit where they derive from Wall/Room/Door to create something more specific. It's just the part where they do this (if Wall is an abstract class)
1 2
|
virtual Wall* MakeWall() const
{ return new Wall; }
|
rather than how xerzi has shown here
virtual Wall* MakeWall() override { return new MazeWall; }
that confuses me. Leaves me wondering if Wall is a concrete class rather than abstract (as how they have done with making MazeFactory a concrete class, differing from their flowchart) or maybe it's just a "generic filler" they use and it's left to the reader to fill it in.
Edit:
@andywestken
So if there is no actual abstract classes, what does abstract even mean in this case? As in just a general interface for other classes to derive from to create something more specific?
@TheIdeasMan
I assume you have the book as well, could you please shed some light on what you think is going on with their sample code?