TTFN,<br /> <br />-bd-<br /> <br /><a href="http://www.amazon.com/exec/obidos/ASIN/0471449156/qid=1064343733/sr=2-1/ref=sr_2_1/002-8375300-3666449" target="_blank" rel="nofollow">Jakarta Pitfalls</a> | <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0471146153/qid=1064343733/sr=1-2/ref=sr_1_2/002-8375300-3666449?v=glance&s=books" target="_blank" rel="nofollow">J2EE AntiPatterns</a> | <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0471462071/qid=1064343733/sr=1-3/ref=sr_1_3/002-8375300-3666449?v=glance&s=books" target="_blank" rel="nofollow">Mastering JavaServer Faces</a> | <a href="http://bill.dudney.net/roller/page/bill" target="_blank" rel="nofollow">Blog</a> | <a href="http://www.jroller.com/page/BillDudney" target="_blank" rel="nofollow">Eclipse Blog</a> | <a href="http://www.sourcebeat.com/TitleAction.do?id=2" target="_blank" rel="nofollow">Eclipse 3 Live</a>
Read about me at frankcarver.me ~ LinkedIn ~ Frank's PhD research
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
SCJP2. Please Indent your code using UBB Code
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Frank Carver:
I read that a view should only have one controller and vice-versa
I'd be interested to find out where you read this, because it seems fundamentally at odds with what I though MVC is all about. MVC (as I have used it) is an architectural pattern specifically designed to support multiple views on the same data.
For a real code examples, demonstrating what I mean, see this older thread.
Originally posted by Marie Mazerolle:
The book I'm using ("Teach yourself Object Oriented programming in 21 days") says that a model may have many views, and a view may have many models, but the relationship between the controller and the view should be 1-1.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
Does the book also say *why*?
Originally posted by Marie Mazerolle:
Unfortunately, no. In the chapter about OO and User Interface Programming, it says: "The view and controller are also closely related to one another. a controller is almost always used exclusively with a specific view. You can try to find reuse through careful design; but even if you don't, the MVC pattern still provides a good division of responsibility between the objects. OO is not simply a means for reuse."
42
If they're so closely coupled why not simply combine them and save a few object creations and method calls?
Read about me at frankcarver.me ~ LinkedIn ~ Frank's PhD research
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I initially thought that several views could share the same controller instance, but from what I've read and from looking again at my code, it doesn't seem possible because the controller instance is not passed to the view's constructor, it is instantiated in the view's constructor.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Stan James:
That certainly works, but it's not the only way, of course. I did a little app where the main() method did nothing but create the model, view and controller, give them the appropriate pointers to each other, and call controller.start(). The MVC classes all have compile-time dependencies on interfaces and not concrete classes.
Read about me at frankcarver.me ~ LinkedIn ~ Frank's PhD research
Originally posted by Marie Mazerolle:
But in my controller class, my views are (or will be) stored in an ArrayList. When I call view.disableNavigationButtons, how do I know which view to use? Do I have to check the object type before I make the call? I imagine not because it would then violate the Open-Closed Principle described in "Agile Software Development" by Robert Martin.
Which brings another question that maybe I should ask in another thread: How did you learn OOAD & OOP (and design patterns)? If you're self-taught (and even if you're not), then you have my respect because the more I study, the more I find it's a complex subject.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Frank Carver:
user changes a company name on panel 1. panel 1 notes that the field has changed user clicks "save" button on panel 3 panel 3 tells its controller (controller.saveChanges() or whatever) controller fetches any changed data from all panels and updates model
[/QB]
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Read about me at frankcarver.me ~ LinkedIn ~ Frank's PhD research
Originally posted by Frank Carver:
Although there may be a MVC-like architecture happening within the UI API, or within the web browser, the important thing is that our application doesn't care. The MVC that our code implements can be at a courser-grained level. Our "view" canbe thought of as the "model" of the API layer.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
Why don't you just call disableNavigationButtons on *every* view? Those without buttons would simply do nothing...
Originally posted by Frank Carver:
[QB]I feel that one point of misunderstanding might be that you seem to want to communicate direct from view-to-view (or maybe view-controller-view).
[QB]
In a real MVC system, all communication between views is done via the model.
Originally posted by Marie Mazerolle:
I don't understand how I should change my code to fit that description.![]()
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Marie Mazerolle:
Is that correct? Or is just one way to do build the app?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Marie Mazerolle:
I did think of that, Ilja, but I didn't think it would be an acceptable approach to have methods that don't do anything just so my code wouln't break.
But I'm the uneducated one here, so is that how you would do it?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Frank Carver:
In a real MVC system, all communication between views is done via the model.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
That depends on *why* you want to disable the buttons. Why do you?
Originally posted by Ilja Preuss:
Remember that *every* pattern is *not* good in itself - you always need to consider the context it is used in.
MVC is valuable when you need to change the way information is put into the system, how that data is processed and how the result is presented to the user independently of each other. If you won't need to do that, it might just add unnecessary complexety.
Alternatice approaches are Model View Presenter, Document View etc. and even combinations.
Originally posted by Marie Mazerolle:
I just want to make sure that if the user changes, let's say, a company phone number, he/she must save before looking at another company's information.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
So the appropriate part of the model could have a property "was modified after last save" and could notify the view if that property changes state?