Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
I am confused with those topics, so i hope i get some clarification here. Layers are meant to use like this there is database, view and controller layer. I say it's called MVC but yes there are n-layer application is this same ?
So what's wrapper, my easy definition would be it's own easier version and you don't need to write same code over and over. Mainly used for database queries, connections and so on?
I am trying to do some small app, which needs to make some db queries. I am going to use mysqli so I dont know do i need make wrapper for that or that would be overkill ?
Yes, a wrapper is really just a standard Adapter to provide an alternate interface around something. In MVC, the Model is in the Domain Layer, and the View and Controller are in the Presentation Layer.
I would say a wrapper is more source code centric applied to objects or functions. Whereas a layer is more a description of a sub-system in a architecural diagram.
You can think of a layer like a partition. Layer separates different 'categories' or types of logic. For instance most would agree presentation logic should be a separated from business logic. Layer is a fancy way of saying separate the code.
A wrapper is an easier way to use a set of complex operations but can be considered as a layer depending on the case. For example, several object libraries exist in PHP to wrap the functionnality of the mysql and mysqli functions that tend to be overwhelming.
A layer is really a physical barrier that you should not pass through. For example, the HAL for windows is a layer (Hence the L in HAL). Windows doesn't want you to access the hardware directly so it made the HAL to wrap up the usage of peripherials in a global and unique way. And at the same time, forces you to go through it to access the hardware. So it is a wrapper and a layer.
Directx is a technology to access the hardware in a super efficient way to be able to draw graphics and 3D. Althought it is not required to use DirectX to output 3D or 2D graphics (You could render yourself through the HAL or directly using OpenGL). In this case, DirectX is only a wrapper of video functions but is not required to draw stuff on the screen...
They're using a wrapper to proxy the interface of the layer, for talking to it from another layer, this is a service layer or facade if you want to be specific, technically though I guess a service layer could be considered a wrapper, but a wrapper isn't a layer necessarily
Ok, I didn't want to make new topic because there's need for that. I am back to this question again, but this time i got to use the design as well.
I try to rewrite my problem as i suppose no one didn't understand what I wrote. Basically I try to implement the OO design, but there come problems with class relation. How would i use the database class, should i make some DAL or use directly the PDO ? How should i pass in the database object ? Registry pattern, pass by parameter or any other choice?
Here's what i think currently, ill make this as data layer and add it to other classes by parameter.
kaisellgren wrote:Personally I would not include other files within class files.
Why? Do you require what ever loads that class to also load its dependencies? And how do you lazy load classes if you don't include inside class methods?
I agree in this case that Config should be loaded, but passed. Did you mean that or the general case?
arborint wrote:Do you require what ever loads that class to also load its dependencies?
Yup if it is an important file that is part of the core like configs and bootstraps. Individual files required by the class can be included in its own file though.