> > Delegation is good if users of F generally remain unaware of all Es in
the
program. This is an example of "decoupling".
Delegation is bad if F has no other reason to exist, or if users of F could have used E and simplified the program. Maybe F should be unaware of E.
Notice that in class F, there's no instance of class E, but a pointer.
Then inside Draw_F() function Draw_E() is called with a statement "e->Draw_E."
Is this good way to do delegation? Is this good coding in C++ in general?
No. Always use the simplest and weakest thing.
Agent Mulder pointed out you had no E instance, so he added 'new'.
You could also fix that by removing the *, and replacing the -> with a dot .
In terms of OO design theory, delegation does not require *, or . ; only
that F know an E ready for the job. "Know" means "can access".
In terms of program stability, don't point without overwhelming need. Prefer
actual things, and pass them by reference. Don't point to character arrays -
use std::string. Don't point to arrays - use std::list or std::vector.
So your simplest delegation lets F have a member of type E.
--
Phlip