k.p.h
k.p.h

Reputation: 69

MVC Confused about where to put logic.

So I am currently modelling a MVC type system, total noob to this pattern and I'm trying to figure out a couple of things but one thing particular I can't figure out how to handle.

In my system I create e.g a Customer Class & DAO with CRUD functionality which I understand (to an extent ) etc...

I have a table in my database that log's data, this table is never accessed by the user only the extent that they can view calculations/results from the data in this table.

How do I represent this in my design, I have no need for CRUD functionality only just to return results from SQL (e.g Select average/total/ etc).

I obviously need to access the data but I'm not sure if I need a class that models the table or just somewhere to put the logic.

Any help or pointers would be much appreciated

Upvotes: 0

Views: 150

Answers (3)

Aravind Yarram
Aravind Yarram

Reputation: 80176

View (JSP or JSF that displays the Model) -> Service Layer (business code that starts the transaction, uses DAO etc, populates the Model) -> Data access layer (your doa and data mapper here) -> DB

  • Make sure your Model reflects what user wants.
  • Perform Transaction demarcation in service layer
  • Perform DB access and data mapping in the Data access layer

NOTE: None of this requires Spring. Pure Java EE is more than enough.

Upvotes: 2

Pankaj
Pankaj

Reputation: 5250

You should use some framework to implement MVC, like Struts or Spring. For your scenario, Struts will be good and business logic should be in the normal java classes.

Front controller should send the request to model classes with business logic and tables should be implemented using Java Beans.

Upvotes: 0

dark_gf
dark_gf

Reputation: 726

If u want strict MVC then u must create class that represents your table, and dont access directly to table.

PS this class may contain only one method, that is ok.

Upvotes: 0

Related Questions