Hello, this is an assignment for a C++2 (beginner) level class. Regarding C++ Adapters/Code Patterns (Factory, Singleton, Object Pool)
https://www.geeksforgeeks.org/design-patterns-set-1-introduction/
https://www.geeksforgeeks.org/design-patterns-set-2-factory-method/
https://www.geeksforgeeks.org/singleton-design-pattern/
https://www.geeksforgeeks.org/object-pool-design-pattern/
--------------------------------------------------
Summary of the program:
--------------------------------------------------
I want this line to work when called in main:
BallParameters params;
params.weight = 3; params.radius = 8;
GolfBall *myBall =MemoryManager::GetInstance()->CreateBall( params);
That is a singleton factory using an object pool.
I also want this to work in main:
GolfMessage *message = new GolfMessage( GolfMessage::RAINING, myBall )
MemoryManager::GetInstance()->RegisterMessage(message );
MemoryManager::GetInstance()->Notify( GolfMessage::RAINING );
That's an observer notifying decorated GolfBall objects.(Don't use polymorphism for now.)(And there could be another singleton that just handled the messages.Like a DispatchManager.But that's a little overkill since we already have a singleton going here.)
And this would be awesome too:
MemoryManager::GetInstance()->ReleaseBall( myBall );
--------------------------------------------------
Guideline/steps for the program:
--------------------------------------------------
GolfBall is a class with radius and weight properties
BallParameters is a struct with the same properties
CreateBall grabs a free ball from its internal pool (size 10), sets the parameters, and returns it.If there are no balls in the pool, make a new one.
GolfMessage is a decorator around a ball pointer
RAINING is a public enum in GolfBall.(Along with DRY and WINDY)
RegisterMessage takes a GolfMessage and stores it, waiting for a Notify
Notify looks at all registered listeners and if they are waiting for a matching message type, then call Update() on the golf ball (this function should just cout something)
ReleaseBall puts the ball back in the pool, and removes any pending notifications going to it