What are the relative advantages / disadvantages of chaining classes together (or rather; using the results of one class to generate another), compared to nesting classes?
I'm trying to restructure my user / authentication system and am wondering whether;
- myAuthClass should act as a utility and if log-in is successful, simply create a new myUserClass object
- or whether the myAuthClass should create the myUserClass internally (ie $this->user = new myUserClass)
- or even if myUserClass should just call myAuthClass when necessary (ie when a user tries to log in) and update its internal structure (new emails, favourites, cart, etc) as necessary.
As you can tell I'm a bit of an OOP n00b. Concpetually I seem to be able to make a case for each of the methods, so I'm interested in hearing from other people regarding the +ves/-ves of the various approaches.
Cheers.