0

I'm sorry if my question is duplicated, I searched a lot and didn't find my answer.

I'm using VO on a project Spring-MVC, then its very difficult to me to find what I need.

It's okay to use a VO object that contains the representation of all fields of view (jsp), and the state of page (editing, including, excluding etc) ?

I need to store changed addresses, included, excluded, because on the page the addresses are editable.

This VO is holding for example, all addresses, emails, contacts of customer, these information aren't in the view, but is information used in the Controller.

On the page there are pop-ups to edit/add/delete addresses, emails, phones.

The page contains a grid with others informations, and I store in the VO.

In short, I use a VO to store the state of the page and informations needed to work with the view. I use this to not need to go to Hibernate a lot of times during the page life cycle.

This is a good pattern?

I'm ignoring Hibernate cache?

A VO with class scope at the Controller breaks good patterns of OOP?

If I don't pass the VO by parameter in the methods, and use the "this" reference breaks the encapsulation?

This page is very complex, and the Controller has around 30 methods and 1000 lines.

danilo
  • 7,680
  • 7
  • 43
  • 46

1 Answers1

1

This page is very complex, and the Controller has around 30 methods and 1000 lines.

Firstly I don't know what you have in your controller, but with 1000 lines I guess you put logic up there. That's big mistake, controller should receive information from outside and push that information to interested parts. There should be no logic at all.

I'm starting with DDD, VO, Spring-MVC, then its very dificult to me to find what I need.

It's okay to use a VO object that contains the representation of all fields of view (jsp), and the state of page (editing, including, excluding etc) ?

I don't see any information about domain layer and application layer in your post. I hope you did implement it. How to do it, is not part of the answer for your question.

This VO is holding for example, all addresses, emails, contacts of customer, these information aren't in the view, but is information used in the Controller.

Pattern, that you're talking about is not called Value Object, but DTO (Data Transfer Object), which sends immutable data from application layer to upper layers for example your MVC Framework. DTO and VO are basically the same, except the fact that VO can have logic and DTO is just stupid data container.

In short, I use a VO to store the state of the page and informations needed to work with the view. I use this to not need to go to Hibernate a lot of times during the page life cycle.

Mostly you don't want to use your ORM/ODM framework for read data. You can go for clear sql queries and skip your whole domain layer, thanks to that.

In short, I use a VO to store the state of the page and informations needed to work with the view (...) A VO with class scope at the Controller breaks good patterns of OOP?

I don't really see why would you do that. DTO comes from another layer, your's controller responsibility is to push it to the client (+ transform it to json for example), nothing more.

Dariss
  • 1,258
  • 1
  • 12
  • 27