3

For a project I have to process a lot of information from a database and link it together. The information from the database is processed into Objects with attributes represented by information from the columns.
So far so good, but when I want to display this information to the user, I need to link the information from several objects together.
Now my question is, is it a good practice to make a new (dummy) Object with a few attributes from the other objects? A new Object that contains exactly the information I need at that moment? The information is difficult to fit into an ArrayList or Map, which was my first approach. The object can be discarded when no longer needed.
I try to make use of MVC Design Pattern, and I'm not really sure if this way of thinking fits MVC.

Century
  • 283
  • 1
  • 4
  • 22

3 Answers3

5

Sure it is. It is a design pattern known as Data Transfer Object. For more info, see this question : What is Data Transfer Object?

Community
  • 1
  • 1
jeroen_de_schutter
  • 1,843
  • 1
  • 18
  • 21
  • Thank you for your reply. My 'normal' objects are very simple objects, the model just contains getters and setters. Are they DTO's as well? But ones with a one-one-relation with their database counterparts? Do I need to make a collection for the dummy objects as well, with a controller? – Century Jan 20 '16 at 16:45
0

Seems reasonable to me, C# MVC uses this often and references them as View Models in their tutorials. Here is some inforamtion about this idea of a view model https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel

Zach
  • 1,964
  • 2
  • 17
  • 28
  • Thank you for your reply. Can you make a View Model that is not linked to one Domain Model, but to several? And do you need to make a controller for the View Model? – Century Jan 20 '16 at 16:50
0

What you are talking about can be implemented Strategy Patterns or State Patterns.

These design patterns are suited to handle and manipulate objects on the fly.

Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108