Page 1 of 1

Layer or wrapper ?

Posted: Wed Oct 15, 2008 10:52 am
by staar2
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 ? :|

Re: Layer or wrapper ?

Posted: Wed Oct 15, 2008 2:16 pm
by Christopher
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.

Re: Layer or wrapper ?

Posted: Wed Oct 15, 2008 6:23 pm
by alex.barylski
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.

Re: Layer or wrapper ?

Posted: Thu Oct 23, 2008 1:03 pm
by josh
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.

Re: Layer or wrapper ?

Posted: Tue Oct 28, 2008 11:00 am
by crazycoders
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...

Re: Layer or wrapper ?

Posted: Wed Oct 29, 2008 3:37 am
by josh
crazycoders wrote:So it is a wrapper and a layer.
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

Re: Layer or wrapper ?

Posted: Sat May 09, 2009 4:41 am
by staar2
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. :roll:

Code: Select all

 
<?php
require_once('Config.php');
 
class Database {
 
    private $db;
 
    public function __construct() {
        try {
            $this->db = new PDO(Config::DNS, Config::USER, Config::Pass);
            return $db;
        } catch(Exception $e) {
            die($e->getMessage());
        }   
    }
 
 
}
?>
 

Re: Layer or wrapper ?

Posted: Mon May 18, 2009 5:36 am
by staar2
Ok i have rewrite my problem, so any suggestions tips ?

Re: Layer or wrapper ?

Posted: Thu May 21, 2009 6:06 pm
by kaisellgren
Personally I would not include other files within class files.

Re: Layer or wrapper ?

Posted: Thu May 21, 2009 7:18 pm
by Christopher
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?

Re: Layer or wrapper ?

Posted: Fri May 22, 2009 3:41 pm
by kaisellgren
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.