Some specific questions about object oriented and MVC design.

Posted by Samn on Stack Overflow See other posts from Stack Overflow or by Samn
Published on 2010-03-28T20:11:26Z Indexed on 2010/03/28 20:13 UTC
Read the original article Hit count: 276

Filed under:
|
|

I have two objects, Users and Mail. Users create Mail objects and send them to other users.

  1. If I wanted to get all mail for a User, I could create a method like GetMail() that would return an array of Mail objects owned by that User.
  2. But if I wanted to get all mail across the system, what "type" of object would be responsible for that?
  3. To solve this problem, I usually create a Manager, which is an object responsible for dealing with a collection of a particular type of object. MailManager deals with collections of Mail objects. GetMailForUser() is one method, GetAllMail() is another method. The User objects invokes the MailManager and executes GetMailForUser(me). Is this stupid?
  4. When a user executes the controller CreateMail, a new instance of the Mail object is created. The Mail object, seeing it is creating a new Mail of type 'sent', decides to go ahead and create a second Mail object for the recipient, of type 'received'. Creating one Mail object triggers the creation of a second Mail object. Is this stupid? Should the controller have created both Mail objects, or just the first 'sent' one?
  5. When two Users are friends, the association is stored in a table of Relationships. I use a simple object for Relationships. A RelationshipManager has a method called GetFriendsForUser(). The User object has a method GetFriends(), which invokes the RelationshipManager. Is this stupid?

© Stack Overflow or respective owner

Related posts about php

Related posts about mvc