Option two. The business rule that the Room should be occupied to allow the Window to close should have nothing to do with the Window.
On Thu, Feb 12, 2009 at 1:49 PM, Henry <[email protected]> wrote: > > Let's say.. there's a Room. Room has Window, and Door. Room has a > state (empty, not empty). And this Room is smart that it only lets > you close the Window when it is not empty. > > So.. we have: > > Room.isEmpty() > Window.open() > Window.close() > > > Now... since Window.close() needs to check if room is empty first, > what should be a better solution? > > // Solution1: > Room.init() > Window.init(room) // window has reference to Room > Window.close() // checks if Room is empty first by calling > room.isEmpty() > > > Room.getWindow().close() > > > // Solution2: > Room.init(Window window) > Window.init() // window has no reference to Room > Window.close() // will close itself w/o checking > > > Room.closeWindow() // Room object checks if it isEmpty(), if yes, then > it calls window.close() > > > What do you guys think? Which one is the better solution? Why? base > on which OO principle? > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CFCDev" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cfcdev?hl=en -~----------~----~----~----~------~----~------~--~---
