I am trying to find a ood example of MVC design pattern in java.
This is what i understood from reading about it, please correct me if I am wrong:
I have the Model part which is the logic behind the program, let’s say if we have a phonebook, so adding and removing contact from the Array will be the model.
The Gui is the view and it contains buttons that upon clicking them, the model is changing.
What I am trying to undersand what is the controller part, is it the ActionListeners? how to you seperate those modules in practice.
thank you
I’ve used MVC for a long time and find it to be a fantastic mechanism for approaching software design. My advice while you’re learning it is to make everything a controller at first. In other words, create a class that has members that contain state (model) and also members that display and manipulate that state (views). Make the functions of your class take input from the views, modify the data, and then update the views (controller).
This obviously doesn’t embody the separation that the design pattern intends, but it will help you learn quickly to identify what is a clear view component and what is a clear model component. Then take some time to separate out into separate files/objects independent model objects (which is easiest) and later independent view objects.
After you do this for a project or two, the separation will begin to be more natural and obvious and as you start new projects you’ll know before you start writing code (design phase) what sorts of things go where.
From personal experience I think you’re more apt to overthink things and do too much work if you try to categorize everything without some real development experience first. You’ll find if you spend some time writing a project in a natural way and then breaking things down as you go or afterwords that it will make more sense.