Re: MVC and subClass
From: Leslie Saffrey (lsaffrey_at_myrealbox.com)
Date: 06/07/04
- Next message: Vaidas Gasiunas: "Re: Is Modularity a Useful Concept?"
- Previous message: Leslie Saffrey: "Re: MVC and subClass"
- In reply to: Robert C. Martin: "Re: MVC and subClass"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 7 Jun 2004 09:17:32 +0100
Hi Martin,
I now have two principles/pattern to look at, the visitor and observer pattern.
Thanks for that link.
>>> Robert C. Martin<unclebob@objectmentor.com> 06/07/04 05:05am >>>
On 6 Jun 2004 16:00:58 +0100, Leslie Saffrey<lsaffrey@myrealbox.com>
wrote:
>Hi,
>
>I'm trying to write a java program that uses the Model-View-Controller pattern and I've come across something I don't like.
>The View is simply text input/output and no is gui is involved at this stage. I believe the model should not be aware of the view and therefore should not access System.out directly.
>My problem is this:
>
>Class D1 and D2 etc are subclass of class B, D1 and D2 has extra attributes and methods to class B.
>Class C being the controller has a list of D1 and D2 objects
>The View has to print the list of objects, but I also want the extra info in the subclasses.
>I can only do this by using instanceof and if/else statements which I believe is bad when more subclasses are added to the system. I don't really want to and a show method in class B because of MVC principles.
>
>Is there some way of overcoming this?
Yes. This is what the Visitor pattern is good for.
See:
http://www.objectmentor.com/resources/articles/visitor
This is the Visitor chapter from: "Agile Software Development:
Principles, Patterns, and Practices", Robert C. Martin, Prentice Hall,
2002
-----
Robert C. Martin (Uncle Bob)
Object Mentor Inc.
unclebob @ objectmentor . com
800-338-6716
"The aim of science is not to open the door to infinite wisdom,
but to set a limit to infinite error."
-- Bertolt Brecht, Life of Galileo
- Next message: Vaidas Gasiunas: "Re: Is Modularity a Useful Concept?"
- Previous message: Leslie Saffrey: "Re: MVC and subClass"
- In reply to: Robert C. Martin: "Re: MVC and subClass"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|