Society leans ever heavily on computers, if you have the power to take out computers you can take out society. - cubeman372
Tuesday, January 06, 2009
Navigation
Members Online
Total Online: 29
Web Spiders: 5
Guests Online: 21
Members Online: 8

Registered Members: 37851
Newest Member: moranthon
Most Users online: 523
Latest Articles

Introduction to Multiple Layered Architecture


advertisement



website security Introduction to Multiple Layered Architecture



Introduction to Multiple Layered Architecture

Pre-require :
- Good knowledge of POO

============
Introduction
============

What is a multiple layered architecture ?

A multiple layered architecture is a way of coding that completely separate each part of the code that shouldn't interfer with each other and makes it possible to modify a layer without changing anything else to the other layer. Each layer is becomming independent of the other. This concept can be applied in many way. The most common of it is MVC (Model-View-Controller).

Where does it apply ?

For smaller code it's pretty useless to use this concept, but once your starting to code bigger thing it's the key to make your code better.

======================
How do we apply this ?
======================

For this example, I'm going to use a website.

In the first, you need to ask yourself what are your going to need for that website. Do I need a blog ? Do I need a guestbook ? etc. In this website, we are going to have a blog and an image gallery.

After, you need to ask yourself what layer are you going to need ? Do I need database ? Do I need online payment stuff ? etc. For the exemple we are online going to need database for the blog. There is going to be 1 layer for the database, 1 for the output and 1 for the model. The layer for the model is the layer in which we are going to put all code that isn't related to the other. The layer for output is generally associated to template.

How do we code this now ?

Usually each layer is coded in a class or a series of class. The best example of that is a SQL class. Everyone has seen one before or even has coded one. These kind class are independent of the rest of the code. The model is the only layer that doesn't need class. Note that the class can call each other, but they must not have code that is specific to a layer in the other layer. This means that in the class for the output, I’m not going to see something like "mysql_connect". The general looking after your coding is done is :

<?php
include('class/Database.class.php');
include('class/Output.class.php');

$template = new Template();
$template->load('main.template.html');

$db = new DatabaseConnection();
$result = $db->doThisQuery('SELECT * FROM exemple');
for ($i=0; $i<count($result); $i++) {
$template->setValue('value'.$i, $result[$i]['field']);
}

echo $template->output();
?>


After all that what does it gives ?

Let's just say your client change his mind in the middle of the project and says "I don't like MySQL, change it to PDO". If your database wasn't a layer imagine the pain ! But since we coded in layer there is no need to panic. All we need to change is the DatabaseConnection class and the rest of the code won't change at all. That's the main strength of this concept and this is why it's often used in company. One of the other strength is that all the class or layer you coded can be reused in all your project, because remember they are independent of each other. So if you want to code many website, are you going to start them all from scratch because your code isn't reusable ? If it's coded in layer, all you need to recode is your model layer.
Guest
Username

Password

Remember Me


Bookmark This Page
Affiliates
Adverts

 


By using, viewing or obtaining any information contained on this site, you agree to the disclaimer.

© HellBound Hackers 2007- 2008. Since 3rd December 2004.