Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Re: MVC

 
Rina Magro
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From HFSJ pg 731:

The problem we had in the dating app was that we had many specialized controllers which sounded good from an OO perspective, but left us with duplicate code across all the different controllers in our app, and
didn't give us a nice happy feeling about maintainability and flexibility.


I am still unsure the best way to solve this problem- how to call the specific model from the controller without having to code a lot of controllers, can somebody help me please ?

thanks a lot
Regards
Rina
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example, passing a parameter (command) to the main controller ? You can read this article from the Javaranch Journal.
 
Rina Magro
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Myself in a recent app I developed, I used a ServletContextListener to map all the Data Access Objects (Model) to the ServletContext attributes. All the Data Access Objects implemented the same interface so I needed ONLY 1 controller for all and used this line of code to retreive relevant DAO(Model) object:




Is this acceptable please?

thanks
Regards
Rina
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rina Magro:
Is this acceptable please?

It's more complicated than it needs to be. Is there a good reason you aren't simply doing this?:
PageDAO pageDAO = new PageDAO();

If you're worried about creating too many DAO objects (memory paranoid), you could retrieve it with a static method instead of a constructor:
PageDAO pageDAO = PageDAO.getInstance();
 
Rina Magro
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Christophe
can you please show me a sample code so I can understand what you mean by passing the Model value as a parameter please, cos I am still confused
thanks lots
regards
Rin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic