Let's say I want to create a software that will draw various 2D shapes to the screen and allow the user to manipulate them in real-time. So they could choose a tool (a button on a GUI or something), and drag-and-draw a rectangle. Or a triangle.
I can't help but feel like an OO approach would be the ticket here but I'm not sure how I'd implement that.
Would I have something this pseudocode?
Code:
class drawShapes {
public :
/* Here I need to be able to allow the user to draw
and manipulate multiple shapes so I figure I need to
define all the shapes. Do I use something like this? */
struct square *obj1;
struct triangle *obj2;
struct circle *obj3;
/* Would I then put all my functions here? */
};
So basically, I have no idea what I'm doing but I'm confident I can handle this abstraction with a little help.
The basic idea of the software would, create a shape and then allow the user to manipulate it with multiple tools.
In pure C, what I would do is, define a button struct with a function pointer. So there'd be a "create square" button. I guess that's the same as a class in C++.
But is there a better OOP I'm ignorant of?