What should be in my model and what should be in my controler?

We are writing a system with a sort of quasi-MVC structure (it was never stated as that, but that’s what it is). I’m building up a full knowledge of the system and the controller will have to make calls to me to update it; they system itself is something similar to a graph.

We need to have a sense of a path between multiple nodes, and a way to identify the original node. I receive connections between two nodes in my original graph building, so knowledge of the full path, and the origin node, is not read in directly but obviously can be inferred once I finish building the graph.

My instinct was to write a basic path tracing sort of logic into my model. Every new edge we would infer the path’s that exist and any original input nodes by tracing the path forward and backwards as appropriate. Tracing the path forward or backward does require a bit more knowledge of a system the connection between edges and nodes are a little more complicated then just edge 1 connect node A to B.

My question is, would doing this still be within the realm of the model? If I do all this path tracing, determining input nodes, identifying paths etc am I doing too much work which I should really be storing in the controller for easier modification later? I need to have some tracing capability to build the original graph before the controller is even initialized, but of course I could have the controller provide methods I call to do path tracing and the like an use the controller implementation when building the graph. I don’t think the logic for the graph itself will change, only the way we use it for tasking, and doing things in the model makes it easier because the model can modify it’s quasi-immutable objects directly while I’m not allowing the controller to do that without calls to the model (package scope variables).

Try to fit as much in the model as you can. Controllers are just for business actions, which are usually just variations of CRUD (create, read, update, delete). Models are for doing the advanced logic. For example, business requires that I view the path from A to B. The controller action for viewing a path would tell the model to find and trace the path for it. Then the controller would pass the data back to the view. Controllers mostly just pass data back and forth.

Here’s a good analogy: http://nuts-and-bolts-of-cakephp.com/2009/01/06/another-way-to-think-about-mvc/. It’s for CakePHP, but it should be true for all MVC.

Your model contains information that your view needs to display. This includes:

  • Data bound fields
  • Various results
  • Generated text

In your context, consider the model to be populated with data that is needed to be displayed from within the view.

With regards to the controller, an action in a controller does the following:

  • Perform any entry validation
  • Perform any business logic
  • Populate the model
  • Return the view, populated with the model.

The exception to the above is for languages that support annotations where you can have your validation on model fields.

My question is, would doing this still be within the realm of the model?

Potentially. It’s likely to be a poll type answer, but in my opinion it is acceptable to have methods within a model that transforms data already present within the model. It should be purely transformative, and not have any external consequences.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật