last day (97 days later) » 

8:48 AM
 
what's that?
 
@FrontpageExpert Something I posted in the wrong room :P
 
is that mvc?
my views aren't aware of services
 
@SecondRikudo why view directly interact with model , isnt it work of controller
 
@FrontpageExpert How do they get data then? :P
@NullPoiиteя In my view, controller only ever changes the model, and view only ever queries information from the model.
 
8:55 AM
in my "mvc" the controller fills the view with data
 
@FrontpageExpert In that case your controller does two things
It makes changes to the model, but it also collects data for the view.
 
@SecondRikudo so controller only care about create , update , delete to model and model dothe view things :/ why everyone say different things about mvc and keep other confused :/
 
it doesn't collect data, it injects data into the view
 
@FrontpageExpert And where does the controller get the data to inject to the view?
 
from the services
 
8:56 AM
@FrontpageExpert a.k.a. it collects data for the view :P
 
@NullPoiиteя I agree with that. I was taught that the controller handles all communication 'tween the view and the model :/
 
@SecondRikudo what does "sometimes aware of" means?
 
@Gemtastic dont know but afaik symphony and laravel do the same it call controller which load the view :/
 
@FrontpageExpert Depends on the level of control you need, you can make the controller return the view class (in java with SomeView.class, or in PHP with a string, etc).
The Controller doesn't instantiate the view, and it doesn't have a direct dependency for the view
But it "knows it's there"
 
@SecondRikudo isnt mvc in software programming is different form web ?
 
8:58 AM
@NullPoiиteя Not really.
MVC in web just means different controllers and views.
Model doesn't change. (and that's the bulk of your application)
PHP MVC doesn't count. PHP is weird.
 
In the case I was taught the controller does not instantiate the view either, but it handles the data sent to and from it. The view in web-context is displaying the template which the controller sent it
 
@SecondRikudo you know that mvc for web is very subjective. i was sure views were only aware of their own data. because this is how the so called gurus taught me
 
@FrontpageExpert In PHP, that makes sense.
 
there's a lot of misinformation on the web about programming
 
PHP doesn't have persistent memory. So maintaining the entire object graph in the Model for each request isn't really practical.
 
@NullPoiиteя It's a less detailed version of what I have.
 
services are part of the model @NullPoiиteя so it's the same thing
in my usual design views are aware only of their own. they don't communicate at all with the controller even
they are very dumb
 
@FrontpageExpert it's a question of what you want to have reusable.
 
i just want to know why view directly interact with model isnt it only work of controller .. like view ---> controller --->model and model-->controller-->view
 
I think controllers and services being reusable is more useful than having the views reusable.
If your Controller depends on ServiceA, ServiceB and SomeModel, it's harder to reuse than if it only needed the Services.
 
9:05 AM
we agree on that. what isn't reusable in my design?
 
@FrontpageExpert Your controller is not reusable without the view.
It's understandable for a controller to talk with services in the model, but why does it need to concern itself with output logic?
@NullPoiиteя Consider the following example, you have an entity, a Car. You have a database storage filled with cars, and you want CRUD operations.
 
well, the controller isn't about output logic after all?
 
You want to insert a car, then render a full list of cars in the form of an HTML <table> back in the browser.
 
otherwise it's just an higher level service
 
@FrontpageExpert No, it most certainly is not.
Controller is about input, View is about output, and Model is about business logic.
@NullPoiиteя If your view is only aware of the data, your workflow would be something like...
 
9:08 AM
i will revisit the design in this new project i'm working on
but it makes sense. i admit i didn't focus on controllers and views much yet
 
- Controller gets invoked with web request
- Controller does sanity validations to data
- Controller invokes Service to add a car to storage
- Service does its thing, returns success signal
- Controller then asks model for list of all cars
- Controller invokes View with list of all cars
- View selects template and fills in the details
But now the controller knows how to perform output logic
 
@SecondRikudo thanks, now i got it :)
 
- Controller then asks model for list of all cars -> isn't this collecting
 
@FrontpageExpert collecting, querying, grabbing, whatever you want to call it.
 
i mean you said controller shouldn't do that
 
9:11 AM
@FrontpageExpert It shouldn't.
 
aaaah you were making a wrong example? :P
 
The workflow I described is the bad one
The better workflow would be...
- Controller gets invoked with web request
- Controller does sanity validations to data
- Controller invokes Service to add a car to storage
- Service does its thing, returns success signal
- Controller returns View class to be invoked back to higher level
- Higher level invokes View with dependant services
- View asks model for list of all cars
- View selects template and fills in the details
 
higher level?
 
@FrontpageExpert In PHP's case, bootstrap.
 
ah you mean the view class name string
 
9:14 AM
Yes
public function someAction(Request $request) {
    // Talk to services, blah blah blah

    return "OtherView";
}
Then at some higher level
 
makes sense. you have no idea. like everything i did read in the past is totally wrong
 
$viewName = invoke($controller, $actionName, $request);
$view = createNew($viewName);
 
this is the best explanation i've been reading in years lol
 
i have too ... never understand MVC correctly :D ... lets thanks Madara
 
but what if the controller has grabbed some data to share in the view as well?
 
9:19 AM
@FrontpageExpert Why would it do that?
That violates the separation of concerns.
 
wait i'm thinking
atm my services' methods return not only the result of operations as boolean, but also the entities state
i do this primarily for avoiding multiple database calls
$newUserState = $userService->update($userChanges);
$newUserState is computed in memory
while having to do $userService->getUser($id) again would call it from the db instead
lemme reword. $userService->update($userChanges); doesn't return a boolean but instead the changed user instance because it wouldn't make sense do in a later moment $userService->getByID($userIDthatWasJustChanged)
i guess this must be solved with a caching mechanism in the repositories
right?
 
No
If you have $userService->update($userChanges);
Why would $userService->getByID($userID) make a DB call?
It already exists in memory.
 
yes that's what i meant. it's already stored in the repository
correct?
 
@FrontpageExpert Yes
But like I said, in PHP it's a little weird
Because you don't have persistent memory.
 
so $userService->getByID($id) does $userRepository->getByID($id) which is loaded from memory - not from db
 
9:30 AM
In io.js for instance, you can have the entire object graph in memory throughout the lifecycle of the server
This minimizes database calls greatly, because if two users ask for the same resource, only the first one will have to go through the database, the second user will load it from memory.
 
i am scared of caching instances in repositories. maintaining all the references and things
 
@FrontpageExpert Why?
 
i am very confused about it
@SecondRikudo i am missing some points. people design repositories aggregate-centric. means that a repository operates on a whole cluster of entities. but what if i have two or more aggregates collecting the same instances?
 
@FrontpageExpert What's wrong with it?
 
$user->getOwnThreads();
$forum->getThreads();
$userRepository->update($user); // updates also the threads
$forumRepository->update($forum); // updates also the threads
where are the Threads instance cached?
this is why i was thinking to make repositories entity-centered instead
and maybe have aggregate repositories, like new UserAggregateRepository($userRepository, $threadRepository)
95 messages moved from HTML / CSS / WebDesign
13 messages moved from HTML / CSS / WebDesign
welcome ppl :D
 
I'm an owner?
 
you ok? required skill level is "noob"
 
hey I am a noob too
 
@SecondRikudo did you read about the aggregates thing
 
10:11 AM
I'm not entirely a n00b when it comes to OOP :P
 
me too, but i'm not as pretentious as you @Gemtastic :D
 
Pretentious?
 
actually, i suck :D
@Gemtastic was joking
@Gemtastic are you confident with the repository pattern
 
@FrontpageExpert Fairly
 
10:14 AM
But I know the Java way. I can't answer for any other OOP language
 
it's the same i guess. do you design them aggregate-centered or entity-centered?
 
concept of oop is same everywhere .. i cann't say i know oop in c++ way since i learned with it :P
 
10:34 AM
@FrontpageExpert The way I've been taught is entety-centered
 
10:47 AM
that's what i was thinking too. but services aren't necessarily entity-centered (in fact they are often aggregate centered) so the update/create service methods has to loop over aggregate collection instances and call the relevant repository method?
 
 
13 hours later…
11:47 PM
13 hours silence? :D
 

  last day (97 days later) »