Questions about "clean architecture" in case of a query

246 views
Skip to first unread message

daniphp

unread,
Oct 28, 2013, 3:40:18 PM10/28/13
to clean-code...@googlegroups.com
I have a page where I wish to display initially a list of jobs. There is also a button that adds a new job. A job has a name, user, creation_date, project_name. (This is an over simplified example from a real project)

DIsplayJobsUseCase: the viewer should see a list of jobs with all details when he opens the page
AddJobUseCase: the logged user can add a new job. The page will refresh and the new job will be visible.

1. Why are the controller and the presenter in different partitions? I would expect them to be in the same file. I know about MVC or MVP but not about MVCP.

2. How should a requestor or a responder handle a collection of objects that needs to be passed as output? In what form/structure the Job fields will be stored inside this DTO in Java?

3.What will be the difference between the ViewModel and the Response DTO in this exact case? Could the ViewModel be excluded and the DIsplayJobsReponse used directly?

4. Should I create a business object for each data structure in the database? I understand at one point business objects will be different but until then should I just create ValueObjects?


witali mik

unread,
Oct 28, 2013, 6:06:02 PM10/28/13
to clean-code...@googlegroups.com
1) i would say, your controller call the presenter to render view object from the response of your usecase
2) create a view class which collects job entities, kinda simple object which contains other objects for rendering suppose
3) the response, contains the view.. so you have to get the viewmodel from response
4) you have to forget about database.. you have to seperate database entities == resposible for persistence, business entites responsible for business logic

in your case, DIsplayJobsUseCase Request would maybe got a filter,like limit and offset, your usecase fetch data from repository and fill a view, this view will be passed inside response. you controller pick the application response, get the view from the response and render it with the presenter(i think it can happend within controller..)

the bigger Problem comes if you require a similar usecase, lets say DIsplayJobsAsPremiumUser where you can see more jobdetails..

but dont take my words too sirous;) iam just a junior developer tryin to learn Clean Code as well:D

daniphp

unread,
Oct 29, 2013, 12:46:00 AM10/29/13
to clean-code...@googlegroups.com
I found a reference to the architecture presented in on of the cleancoders episode to be on the same page

1. There is no relation between the controller and presenter
2. The view class you are talking is a Response. What simple objects can keep the detail structure for a job collection?
3. The response is the response. The presenter will build the view from the response.
4. I would forget but I'm working on an app that is already build. So should I start building Entities for each table if this is the simple logic at this point?

Thanks

witali mik

unread,
Oct 29, 2013, 3:44:42 AM10/29/13
to clean-code...@googlegroups.com
well i gues this reference is ment to display the dataflow, which parts are working together, i gues ist just not that easy to show that an instance of presenter could be within a controller/action..

as Reference i used this Repository https://github.com/igorw/doucheswag

as you can see there https://github.com/igorw/doucheswag/blob/master/src/Douche/Interactor/AuctionViewResponse.php  the response expect the view within constructor.
The Presenter cannot build views, as far as i know, the Presenter has only one job to do, render a view object with a template.
Well in this repository the Presenter are not within Controller, just because there are no controllers anyways, he directly mapped routes to interactors and converted the HTTP Requests to Application Request

About your Database, i think you dont need to create an entity for each table, you will maybe create about 80% or more of entities which looks like your tables but you dont need to make them all. i would just create entities, which are required for your application to work, while your Repositories will care about the database, which rows it has to fetch and how to convert rows into entities(joins and other stuffs includet, in some cases you can create an entity by joining multiple tables)

Idont know what Language are you using for you app, in PHP you can fill just an array or SplObjectStorage with Entities.

i hope uncle bob or someone who is familar with this image, could answer what it really means
Reply all
Reply to author
Forward
0 new messages