The base class wouldn't implement resize/move. They'd be defined as pure virtual. The language will enforce that Rectangle, Circle provide implementations.
It's conventional to think of BaseShape as an interface. That is, it defines methods that all derived classes will implement, but itself doesn't implement anything.
How should the Rectangle and Triangle set their Position?
i guess that's up to you dude :)
if your talking 2d objects (rectangle, triangle etc), not sure why you'd want a z coordinate on your setPosition() method.
The thing is that setPosition should be public and not protected, as the user may want to change the position of the Rectangle as well.
regarding setPosition: do you want this to do different things depending on the shape? if yes, all derived classes need a (protected?) setPosition() in the same was as your resize and move methods. if have one impl in your shape class.
Position is something that should be handled by the base class, actually, and is one of my arguments against Java-style interfaces. Deriving classes should not be able to change the behavior of setting and getting the position.
regarding setPosition: do you want this to do different things depending on the shape? if yes, all derived classes need a (protected?) setPosition() in the same was as your resize and move methods. if have one impl in your shape class.
I think I got you.
You say that if I want only derived-classes, as Rectangle, Triangle, to be able to set their position, then the
If the method is protected in Shape, then if you have a pointer to a Shape (because you're using polymorphism), then other code won't be able to call setPosition().
Normally, non-polymorphic "forwarder" functions are public and the polymorphic virtual functions are private (or protected if they should be able to be called without the forwarder from the deriving classes).
I have additional design question please regarding protected.
Why not moving all the Private Data members / Private methods of the Base Class into Protected?
I mean, why is it better to put the Private Data members / Private methods of the Base in Private, and provide methods to get / set the Data Members in Protected?
As I studied, the Encapsulation of OO is to not expose the implementation details (e.g. data members) to the User.
However, The Class's Implementation (Both Base Class and Derived Class) is not part of the User space, but part of the Developer Space.
Therefore, why not letting the Derived Classes' developer to have direct access to the data members of the Derived Classes? (while keeping the user out of reach of these data members)
You misunderstand - the goal of encapsulation is not to hide implementation details from the user or developer - the goal is to hide implementation details from other code. If code A does not know about code B, then code B should not know how code A is implemented internally and should only use code A's provided interface.
So, a deriving class is considered other code, and therefore should not know about the implementation details of its parent class.
The logical reason? To avoid code duplication. All code that works on a set of data should be grouped together (e.g. in a class) so that ways to access and manipulate that data exist all in one place and without duplication.
When you allow any other code to handle implementation details, you are duplicating existing code (which is bad) and you are doing it away from the existing code (also bad).
It doesn't matter whether you are a user, developer, or deriving class - you should always keep implementation details hidden.
And in case I didn't make it clear enough, protected data members should be considered part of a class' public interface - the only reason to make them protected instead of public is to indicate to the person writing the code "this is meant to be used only by the deriving class and not just arbitrary code".