On Design Patterns book, the author lists a group of functions he would use to develop his program:
virtual void Draw(Window*)
virtual void Bounds(Rect&)
virtual bool Intersects(const Point&)
virtual void Insert(Glyph*, int)
virtual void Remove(Glyph*)
virtual Glyph* Child(int)
virtual Glyph* Parent()
And he says a Rectangle subclass of Glyph might redefine Draw as follows:
void Rectangle::Draw (Windows* w) {
w->DrawRect(_x0, _y0, _x1, _y1);
}
I'm curious as to why you would pass an object by pointer in some of the cases but not others. One of the functions above is passing an object by reference. What kind of design decision would force one to write functions like the ones above? i.e. Why would someone pass some objects by pointer and the others by reference?
Also, if you allow a null pointer to be passed to Rectangle::Draw function, what happens there?