PersonMaintenance would be the class driving the process. That is, it would have the start() method and that would call the printMenuoptions() from UserInterface (you will need an instance of the class unless you make the method static). PersonMaintenance would have the enterMenuOption() method in it and so on. So PersonMaintenance would have all the logic to "maintain" a Person (add a Person, search, etc.) Then printing "not found" or "phone not found" would be calls to UserInterface.
Lisa Austin wrote:
NOW
But with the suggestion to have PersonMaintenance drive , how can I get UserInterface to call a method on PersonMaintenance without creating a new PersonMaintenance object ? Is there a way I can pass the current PersonMaintenance object over to UserInterface?
Junilu Lacar wrote:
Lisa Austin wrote:
NOW
But with the suggestion to have PersonMaintenance drive , how can I get UserInterface to call a method on PersonMaintenance without creating a new PersonMaintenance object ? Is there a way I can pass the current PersonMaintenance object over to UserInterface?
There is a way but I doubt that's a good idea. If PersonMaintenance knows about UserInterface, then it's not a good idea to have UserInterface know about PersonMaintenance. Rethink your idea about UserInterface accessing anything that has to do with PersonMaintenance. If you do that, you create a two-way dependency: PersonMaintenance is dependent on UserInterface and UserInterface is dependent on PersonMaintenance. That kind of design, one where you have circular dependencies, tends to create problems.
Lisa Austin wrote:I'll keep thinking.
Junilu Lacar wrote:More problematic is the fact that if I decided to change the menu option to "Q to quit", then I'd have to go to UserInterface to do that. However, I'd also need to go to PersonMaintenance and change the condition to check for "Q" instead of "x".
you wrote:The program is supposed to have 8 commands . 1 - 7 does different things, 8 is to quit.
Junilu Lacar wrote:
Junilu Lacar wrote:More problematic is the fact that if I decided to change the menu option to "Q to quit", then I'd have to go to UserInterface to do that. However, I'd also need to go to PersonMaintenance and change the condition to check for "Q" instead of "x".
And in fact, in the other thread,
you wrote:The program is supposed to have 8 commands . 1 - 7 does different things, 8 is to quit.
Junilu Lacar wrote:Comments are not the solution to a structural/organization problem. That's like putting a sticky note on your refrigerator saying "Make sure to set the thermostat to 75 to make the microwave oven work."
In fact, comments like those you are suggesting would be considered a "code smell."
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|