This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Having just read Head First's Design patterns, I am seeing opportunities for patterns everywhere! Would an MVC pattern be appropriate for the following situation?
- A text-based roleplaying game has a series of 'ability' objects which all implement an execute method. Said method does its ability-specific chore, talking to the subject object (the performer of the ability), target object (if applicable), and the Display class, which functions to spit the narrative out onto a jtextpane in a coherent form. -
Having just picked up JUnit, I attempted to create a test-case for some of my ability objects. This exercise quickly revealed to me just how many 'stub' or 'mock' objects I would need to create in order to perform even the simplest of tests! Especially since the ability's 'subject' and 'target' have to be given room objects, and names, and genders, etc. etc. etc.
It seems to me that this is an example of a low-cohesion highly-coupled program? Or is it simply permissable in a large-ish program for a lot of classes to know about each other simply due to the nature of how complex things get? (For example, using once again the RPG, the abilities need to know about the creatures performing them, the static algorithmic classes which perform the math, and the display class in order to transmit a narrative of the ability to the player, if said player is in the room). In this example, it makes sense for the abilities to know about the math involved, and potentially even the creatures, but wouldnt a liasion 'model' component be helpful for communicating with the 'view' component?
Or perhaps not? Would the passing of a string to a 'model' before going to the 'view' merely be an unnecessary formality?