N
Nick Keighley
Hi,
I'm curious about best practice for protected members.
Consider this code fragment:-
class Patch
{
public:
Patch ();
virtual void draw (Page, int x, int y) = 0;
protected:
unsigned size () const { return size_; }
void set_size (unsigned size) { size_ = size; }
private:
unsigned size_;
};
class Plain_patch: public Patch
{
public:
Plain_Patch ();
virtual void draw (Page, int x, int y);
};
Plain_Patch::draw (Page page, int x, int y)
{
// uses size() function
}
In order for the derived class to implement its draw() method it needs
to know the size. Protected data seems to be frowned on. So is my only
choice protected get() and set() methods? Or public?
I'm curious about best practice for protected members.
Consider this code fragment:-
class Patch
{
public:
Patch ();
virtual void draw (Page, int x, int y) = 0;
protected:
unsigned size () const { return size_; }
void set_size (unsigned size) { size_ = size; }
private:
unsigned size_;
};
class Plain_patch: public Patch
{
public:
Plain_Patch ();
virtual void draw (Page, int x, int y);
};
Plain_Patch::draw (Page page, int x, int y)
{
// uses size() function
}
In order for the derived class to implement its draw() method it needs
to know the size. Protected data seems to be frowned on. So is my only
choice protected get() and set() methods? Or public?