I'm looking for the "correct" way to handle object creation and update in java web apps.
Say I have an architecture with 3 levels: Web UI, Domain and Database.
I also have a class WebPage
(title, description, url), with a hibernate mapping.
Clearly i need to use WebPage
at least in the Database level, and most likely also at Domain level.
Object creation:
But at what level should i create the object?
I see two options:
1:
__WebUI__ -> createWebsite(title, description, url) __Domain__
and domain creates the objects and passes it to the **Database** level.
Option 2:
__WebUI__[_creates the website_] -> saveWebsite(website) __Domain__
and domain passes it to the Database level.
The first one clearly seems the most reasonable.
Object update:
And what if i need to update the Website's informations?
Option 1:
__WebUI__ -> updateTitle(title) __Domain__
__WebUI__ -> updateDescription(desc) __Domain__
__WebUI__ -> updateUrl(url) __Domain__
Option 2:
WebUI sends an updated version of the object to the domain level.
Is there a specific pattern to follow?