DESIGN PATTERNS in PHP

In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design. The advantage of knowing and using these patterns is save time as well as give developers a common language in software design. Here I discuss the implementation of some common design patterns that are easily adapted to PHP.

1. Strategy Pattern:

The strategy pattern is typically used when your programmer’s algorithm
should be interchangeable with different variations of the algorithm. For
example, if you have code that creates an image, under certain circumstances, you might want to create JPEGs and under other circumstances, you might want to create GIF files.
The strategy pattern is usually implemented by declaring an abstract
base class with an algorithm method, which is then implemented by inheriting concrete classes. At some point in the code, it is decided what concrete strategy is relevant; it would then be instantiated and used wherever relevant.
Our example shows how a download server can use a different file selection
strategy according to the web client accessing it. When creating the
HTML with the download links, it will create download links to either .tar.gz
files or .zip files according to the browser’s OS identification. Of course, this
means that files need to be available in both formats on the server. For simplicity’s sake, assume that if the word “Win” exists in $_SERVER[“HTTP_
USER_AGENT”], we are dealing with a Windows system and want to create .zip
links; otherwise, we are dealing with systems that prefer .tar.gz.
In this example, we would have two strategies: the .tar.gz strategy and
the .zip strategy, which is reflected as the following strategy hierarchy (see
Figure 1).


Figure 1: Strategy hierarchy.

The following code snippet should give you an idea of how to use such a
strategy pattern:
abstract class FileNamingStrategy {
abstract function createLinkName($filename);
}
class ZipFileNamingStrategy extends FileNamingStrategy {
function createLinkName($filename)
{
return “http://downloads.foo.bar/$filename.zip”;
}
}
class TarGzFileNamingStrategy extends FileNamingStrategy {
function createLinkName($filename)
{
return “http://downloads.foo.bar/$filename.tar.gz”;
}
}
if (strstr($_SERVER[“HTTP_USER_AGENT”], “Win”)) {
$fileNamingObj = new ZipFileNamingStrategy();
} else {
$fileNamingObj = new TarGzFileNamingStrategy();
}
$calc_filename = $fileNamingObj->createLinkName(“Calc101”);
$stat_filename = $fileNamingObj->createLinkName(“Stat2000″);
print <<<EOF
<h1>The following is a list of great downloads<</h1>
<br>
<a href=”$calc_filename”>A great calculator</a><br>
<a href=”$stat_filename”>The best statistics application</a><br>
<br>
EOF;
Accessing this script from a Windows system gives you the following
HTML output:
<h1>The following is a list of great downloads<</h1>
<br>
<a href=”http://downloads.foo.bar/Calc101.zip”>A great calculator<
/a><br>
<a href=”http://downloads.foo.bar/Stat2000.zip”>The best statistics
application</a><br>
<br>

Tip: The strategy pattern is often used with the factory pattern, which is
described later in this section. The factory pattern selects the correct strategy.

2. Singleton Pattern:
The singleton pattern is probably one of the best-known design patterns.
You have probably encountered many situations where you have an object that
handles some centralized operation in your application, such as a logger
object. In such cases, it is usually preferred for only one such application-wide
instance to exist and for all application code to have the ability to access it.
Specifically, in a logger object, you would want every place in the application
that wants to print something to the log to have access to it, and let the centralized
logging mechanism handle the filtering of log messages according to
log level settings. For this kind of situation, the singleton pattern exists.
Making your class a singleton class is usually done by implementing a
static class method getInstance(), which returns the only single instance of
the class. The first time you call this method, it creates an instance, saves it in
a private static variable, and returns you the instance. The subsequent
times, it just returns you a handle to the already created instance.
Here’s an example:
class Logger {
static function getInstance()
{
if (self::$instance == NULL) {
self::$instance = new Logger();
}
return self::$instance;
}
private function __construct()
{
}
private function __clone()
{
}
function Log($str)
{
// Take care of logging
}
static private $instance = NULL;
}
Logger::getInstance()->Log(“Checkpoint”);

The essence of this pattern is Logger::getInstance(), which gives you
access to the logging object from anywhere in your application, whether it is
from a function, a method, or the global scope.
In this example, the constructor and clone methods are defined as private.
This is done so that a developer can’t mistakenly create a second
instance of the Logger class using the new or clone operators; therefore, getInstance() is the only way to access the singleton class instance.

3. Factory Pattern:

Polymorphism and the use of base class is really the center of OOP. However,
at some stage, a concrete instance of the base class’s subclasses must be created.
This is usually done using the factory pattern. A Factory class has a
static method that receives some input and, according to that input, it decides
what class instance to create (usually a subclass).
Say that on your web site, different kinds of users can log in. Some are
guests, some are regular customers, and others are administrators. In a common
scenario, you would have a base class User and have three subclasses:
GuestUser, CustomerUser, and AdminUser. Likely User and its subclasses would
contain methods to retrieve information about the user (for example, permissions
on what they can access on the web site and their personal preferences).
The best way for you to write your web application is to use the base class
User as much as possible, so that the code would be generic and that it would
be easy to add additional kinds of users when the need arises.
The following example shows a possible implementation for the four User
classes, and the UserFactory class that is used to create the correct user object
according to the username:
abstract class User {
function __construct($name)
{
$this->name = $name;
}
function getName()
{
return $this->name;
}
// Permission methods
function hasReadPermission()
{
return true;
}
function hasModifyPermission()
{
return false;

}
function hasDeletePermission()
{
return false;
}
// Customization methods
function wantsFlashInterface()
{
return true;
}
protected $name = NULL;
}
class GuestUser extends User {
}
class CustomerUser extends User {
function hasModifyPermission()
{
return true;
}
}
class AdminUser extends User {
function hasModifyPermission()
{
return true;
}
function hasDeletePermission()
{
return true;
}
function wantsFlashInterface()
{
return false;
}
}
class UserFactory {
private static $users = array(“Andi”=>”admin”, “Stig”=>”guest”,
“Derick”=>”customer”);
static function Create($name)
{
if (!isset(self::$users[$name])) {
// Error out because the user doesn’t exist
}
switch (self::$users[$name]) {

case “guest”: return new GuestUser($name);
case “customer”: return new CustomerUser($name);
case “admin”: return new AdminUser($name);
default: // Error out because the user kind doesn’t exist
}
}
}
function boolToStr($b)
{
if ($b == true) {
return “Yes\n”;
} else {
return “No\n”;
}
}
function displayPermissions(User $obj)
{
print $obj->getName() . “‘s permissions:\n”;
print “Read: ” . boolToStr($obj->hasReadPermission());
print “Modify: ” . boolToStr($obj->hasModifyPermission());
print “Delete: ” . boolToStr($obj->hasDeletePermission());
}
function displayRequirements(User $obj)
{
if ($obj->wantsFlashInterface()) {
print $obj->getName() . ” requires Flash\n”;
}
}
$logins = array(“Andi”, “Stig”, “Derick”);
foreach($logins as $login) {
displayPermissions(UserFactory::Create($login));
displayRequirements(UserFactory::Create($login));
}
Running this code outputs
Andi’s permissions:
Read: Yes
Modify: Yes
Delete: Yes
Stig’s permissions:
Read: Yes
Modify: No
Delete: No
Stig requires Flash
Derick’s permissions:
Read: Yes
Modify: Yes
Delete: No
Derick requires Flash
This code snippet is a classic example of a factory pattern. You have a class
hierarchy (in this case, the User hierarchy), which your code such as displayPermissions() treats identically. The only place where treatment of the classes differ is in the factory itself, which constructs these instances. In this example, the factory checks what kind of user the username belongs to and creates its class accordingly. In real life, instead of saving the user to user-kind mapping in a static array, you would probably save it in a database or a configuration file.

Tip: Besides Create(), you will often find other names used for the factory
method, such as factory(), factoryMethod(), or createInstance().

4. Observer Pattern:

PHP applications, usually manipulate data. In many cases, changes to one
piece of data can affect many different parts of your application’s code. For
example, the price of each product item displayed on an e-commerce site in the
customer’s local currency is affected by the current exchange rate. Now,
assume that each product item is represented by a PHP object that most likely
originates from a database; the exchange rate itself is most probably being
taken from a different source and is not part of the item’s database entry. Let’s
also assume that each such object has a display() method that outputs the
HTML relevant to this product.
The observer pattern allows for objects to register on certain events
and/or data, and when such an event or change in data occurs, it is automatically
notified. In this way, you could develop the product item to be an observer
on the currency exchange rate, and before printing out the list of items, you
could trigger an event that updates all the registered objects with the correct
rate. Doing so gives the objects a chance to update themselves and take the
new data into account in their display() method.
Usually, the observer pattern is implemented using an interface called
Observer, which the class that is interested in acting as an observer must
implement.
For example:

interface Observer {
function notify($obj);
}
An object that wants to be “observable” usually has a register method
that allows the Observer object to register itself. For example, the following
might be our exchange rate class:

class ExchangeRate {
static private $instance = NULL;
private $observers = array();
private $exchange_rate;
private function ExchangeRate() {
}
static public function getInstance() {
if (self::$instance == NULL) {
self::$instance = new ExchangeRate();
}
return self::$instance;
}
public function getExchangeRate() {
return $this->$exchange_rate;
}
public function setExchangeRate($new_rate) {
$this->$exchange_rate = $new_rate;
$this->notifyObservers();
}
public function registerObserver($obj) {
$this->observers[] = $obj;
}
function notifyObservers() {
foreach($this->observers as $obj) {
$obj->notify($this);
}
}
}
class ProductItem implements Observer {
public function __construct() {
ExchangeRate::getInstance()->registerObserver($this);
}
public function notify($obj) {
if ($obj instanceof ExchangeRate) {
// Update exchange rate data
print “Received update!\n”;
}
}
}
$product1 = new ProductItem();
$product2 = new ProductItem();
ExchangeRate::getInstance()->setExchangeRate(4.5);
This code prints
Received update!
Received update!

Although the example isn’t complete (the ProductItem class doesn’t do
anything useful), when the last line executes (the setExchangeRate() method), both $product1 and $product2 are notified via their notify() methods with the new exchange rate value, allowing them to recalculate their cost.
This pattern can be used in many cases; specifically in web development,
it can be used to create an infrastructure of objects representing data that
might be affected by cookies, GET, POST, and other input variables.

Thanks to the advances of PHP 5, using common OO methodologies, such as
design patterns, has now become more of a reality than with past PHP versions. For more you can visit http://www.cetus-links.org/.

Advertisements

Some Ajax Tutorial Links

Modern web-applications can be designed with enhanced user interfaces and functionalities, which used to be the privelege of professional desktop-applications. Web-developers can create amazing web-applications with AJAX. Here I give some links below for developers:

Asynchronous JavaScript and XML isn’t a new programming language, as it is often mistakingly called. Basically, AJAX is a set of XHTML, CSS, DOM, XMLHttpRequest and XML, put together and used together for the same purpose – to improve the user-server-interaction.

There is a list with useful AJAX-based techniques you should always have ready to hand developing AJAX-based web-applications:

1. AJAX AutoSuggest:

2. AJAX Autocompleter / script.aculo.us library

3. AJAX AutoCompleter

4. Ajax autosuggest/autocomplete from database

5. Ajax dynamic list

6. AJAX inline text edit 2.0

7. AJAX & CSS Flickr-like Editing Fields

8. AJAX Instant Edit

9. 14 Tab-Based Interface Techniques

10. AJAX Menu Widget

11. AJAX Accordion Navigation:

12. AJAX Dialogs, Menus, Grids, Trees and Views

13. AJAX Tab Module – Closeable Implementation

14. Ajax Tabs Content

15. AJAX Tabbed Content

16. MooTabs – Tiny tab class for MooTools

17. Dynamically loaded articles

18. AJAX Datetime Toolbocks – Intuitive Date Input Selection

19. AJAX Calendars

20. AJAX Floating Windows

21. AJAX Star Rating Bar

22. Ajax poller

23. AJAX HistoryManager, Pagination

24. AJAX Login System Demo

25. AJAX image preloader

26. AJAX Tooltips: Nice Titles revised | Blog | 1976design.com

27. 40+ Tooltips Scripts With AJAX, JavaScript & CSS | Smashing Magazine

28. AJAX Web Controls

29. AJAX syntaxhighlighter

30. GMail Ajax Style Username Signup

31. Gmail Ajax Style Check Username

32. Transparent Message

33. ModalBox — An easy way to create popups and wizards

34. AJAX File Uploads progress bar

35. Chained select boxes

36. Fly to basket

37. AJAX Key Events Signal

38. Disable form submit on enter keypress

39. AJAX Instant Completion

40. Novemberborn: Event Cache

41. Altering CSS Class Attributes with JavaScript

42. Select Some Checkboxes JavaScript Function

43. AJAX Emprise Charts

44. amCharts: customizable flash Pie & Donut chart

45. PJ Hyett : The Lightbox Effect without Lightbox

46. AJAX Upload Form

47. An AJAX contact form

48. AJAX contact form

49. Ajax.Form: mootools demo

50. Ajax form validation

51. Really easy field validation

52. AJAX fValidate

53. Ajax newsletter form

54. wForms

55. Data Grids with AJAX, DHTML and JavaScript | Smashing Magazine

56. Grid3 Example

57. AJAX Table Sort Script (revisited)

58. AJAX Sortable Tables

59. AJAX TableKit

60. 30 Scripts For Galleries, Slideshows and Lightboxes | Smashing Magazine

61. AJAX LightBox, Sexy Box, Thick Box

62. AJAX Lightbox JS

63. AJAX Unobtrusive Popup – GreyBox

64. SmoothGallery: Mootools Mojo for Images | Full gallery

65. AJAX Libraries and Frameworks

66. How to Create Digg Comment Style Sliding DIVs with Javascript and CSS

67. How to Create a Collapsible DIV with Javascript and CSS

68. How to Create an Animated, Sliding, Collapsible DIV with Javascript and CSS

69. AJAX Shopcart

70. Draggable content

71. Dragable RSS boxes

72. AJAX Pull Down Effect

73. AJAX Animation Effects

74. Combination Effects in scriptaculous wiki

75. AJAX Motion Transition

76. 9 Javascript(s) you better not miss !!

77. Top 10 custom JavaScript functions of all time

78. Hyperdisc Materials: JavaScript: Top 10: Automatic Breadcrumb Trail

79. JavaScript: Top 10 Most Useful JavaScripts

80. My Favorite Javascripts for Designers: Blakems.com ?

81. MiniAjax.com

82. Ajax Rain

83. Max Kiesler – mHub : Ajax and rails examples & how-to’s

84. Ajax Resources

85. DZone Snippets: Store, sort and share source code, with tag goodness

86. Mocha UI

87. An Accessible Slider

88. Facebook Style Input Box

89. Rich Text Editor

90. iCarousel

91. Coda Popup Bubbles

92. FancyUpload

93. Moo Wheel

94. Product Slider

95. Taggify Tooltips

96. Relay – Ajax Directory Manager

97. GlassBox

98. qGallery

99. Amberjack

100. GWT-Ext Widget Library

101. Flexigrid

102. cforms II

103. Custom Checkbox with jQuery

104. NicEdit is a Javascript/AJAX inline content editor

105. Tablecloth

106. Unobtrusive Table Actions Script

107. FancyForm

108. Starbox

109. Carousel

110. minishowcase

111. Displaying source code with Ajax

112. mooSocialize – ajax based social bookmark widget

113. Lightview

114. lightWindow

115. DatePicker using Prototype and Scriptaculous

116. New unobtrusive dynamic flickr badge

117. Step by Step – Show and explain visitors what your page has for them

118. Facebox

119. ClickHeat

120. Maillist

Some excellent websites to learn CSS

Some excellent websites are given below to learn CSS within short time:

Site name Description

70 Expert Ideas For Better CSS Coding

To learn more about professional CSS coding, you should visit this site.

53 CSS-Techniques You Couldn’t Live Without.

To to get a powerful and handy CSS-Toolbox for your future projects, you can use this site.

CSS Basics

CSS Basics is formatted like a book with 18 chapters dedicated to educating readers about fundamental CSS concepts. The writing is clear and succinct – making it a great resource for those just starting out. All 18 chapters can be printed or downloaded in PDF format.

W3CSchools CSS Tutorial

W3CSchools has a CSS section that covers the very basics of CSS up to more advanced topics.

css Zen Garden

css Zen Garden is a showcase of the things you can do CSS. Most importantly, it highlights the concept of separating content from presentation. Using the same HTML file, designers submit external stylesheets to style the HTML file. I suggest using the Web Developer Tool to inspect how the layouts work and what styles affect certain elements of the page.

CSS at MaxDesign

At MaxDesign, you can find Russ Weakley’s brilliant set of CSS-related tutorials. Some things to expect here are: Listmatic – which shows you a variety of ways you can use CSS to style lists, and Floatutorial – which goes through the fundamentals of floating elements.

CSSeasy.com

CSSEasy.com’s slogan is “learn CSS the modern way”. The site promotes learning by experience, with the idea that if you inspect the source code and see how things fit together as a whole, you’ll gain a better understanding of CSS. The Web Developer Tool will also come in handy on this website.

CSS-Discuss

CSS-Discuss is a community of CSS enthusiasts. The CSS-Discuss Wiki is a comprehensive collection of real-world usage of CSS.

Web Design from Scratch: CSS

Ben Hunt’s Web Design from Scratch has an excellent section on CSS that covers basic concepts about CSS. I highly recommend beginners start off with Introduction to CSS, a quick but very informative starting point to getting your hands dirty with CSS.

CSSDog

CSSDog has a section for both beginners and more advanced developers. Aside from CSS lessons, their CSS Reference section – which lists quick guides and color references – are very helpful.

CSS on Delicious

The CSS tag on Delicious is a great way to find popular links that relate to CSS. It allows you to see what people are currently reading.

SitePoint CSS Reference

SitePoint has a CSS reference section that discusses introductory level CSS topics. You can get a crash course on general CSS syntax and nomenclature onto slightly more advanced topics such as CSS hacks and filters.

A List Apart CSS Topics

A List Apart, the premier site to read articles about web design and best practices, has a collection of articles on the topic of CSS dating back to 1999. Most articles are geared towards intermediate to advanced developers who put a strong emphasize on standards-compliant designs.

CSS Help Pile

CSS Help Pile is an aggregate of CSS resources, tips, and how-to’s. The site is well-organized and a wonderful resource for any level of expertise. There’s a category for beginners, browser bugs, and short reviews of CSS books.

Eric Meyer: CSS

Here’s a collection of works by Eric Meyer (acclaimed web professional and author). Some resources you’ll find on this page are css/edge (Eric Meyers experiments on CSS) and CSS reference.

Holy CSS Zeldman!

Holy CSS Zeldman (not a site by Jeffrey Zeldman) is a useful collection of resources that link to standards-based CSS tutorials, tools, and layouts.

456 Berea Street – CSS category

Roger Johansson’s 456 Berea Street has over 300 posts under the CSS category. Some posts talk choosing an image replacement method while others teach you CSS techniques.

/* Position Is Everything */

Those just getting their hands around authoring CSS code will quickly realize that a significant chunk of time (and frustration) stems from getting rid of browser bugs. Position Is Everything discusses known browser bugs and shares CSS methods that work across browsers. Here, you can read about the one true layout or learn what happens when you nest absolutely-positioned div’s.

HTML Dog CSS Tutorials

HTML Dog is a tutorial website dedicated to teaching XHTML and CSS best practices. There’s three CSS tutorial sections: Beginner, Intermediate, and Advanced.

Andy Budd CSS/Web Standards Links

Andy Budd (directory of Clearleft, CSS guru, and author of one of my favorite books – CSS Mastery) has a set of CSS/web standards links to help you find reliable, useful information about CSS.

Learn CSS Positioning in Ten Steps

Positioning elements using CSS can be a tricky concept at first. If you’re having a hard time understanding the fundamentals of CSS positioning, check out this 10-step tutorial to get you positioning stuff in no time!

CSS-Tricks

CSS-Tricks is a blog dedicated to the topic of CSS. You’ll find helpful posts such as what CSS Sprites are (in a nut shell), techniques for image replacements, and even screencasts on topics like conditional stylesheets.

Smashing Magazine

A great site for CSS learners.

CSSPlay

This site will help newcomers to CSS and show old hands that it is more than just a mechanism for styling your documents.

web design dashboard

It’s got a ton of stuff on CSS and also other random web design resources!

Quirks Mode

It contains about 120 pages with CSS and JavaScript tips and tricks, and is one of the best sources on the WWW for studying and defeating browser incompatibilities.

How you make an OOP Website in PHP

Object-oriented programming (OOP) is a programming paradigm that uses “objects” and their interactions to design applications and computer programs. Programming techniques may include features such as encapsulation, modularity, polymorphism, and inheritance. It was not commonly used in mainstream software application development until the early 1990s. Many modern programming languages now support OOP.

Fundamental Concepts of OOP which takes from Wikipedia:

Class
Defines the abstract characteristics of a thing (object), including the thing’s characteristics (its attributes, fields or properties) and the thing’s behaviors (the things it can do, or methods, operations or features). One might say that a class is a blueprint or factory that describes the nature of something. For example, the class Dog would consist of traits shared by all dogs, such as breed and fur color (characteristics), and the ability to bark and sit (behaviors). Classes provide modularity and structure in an object-oriented computer program. A class should typically be recognizable to a non-programmer familiar with the problem domain, meaning that the characteristics of the class should make sense in context. Also, the code for a class should be relatively self-contained (generally using encapsulation). Collectively, the properties and methods defined by a class are called members.
Object
A pattern (exemplar) of a class. The class of Dog defines all possible dogs by listing the characteristics and behaviors they can have; the object Lassie is one particular dog, with particular versions of the characteristics. A Dog has fur; Lassie has brown-and-white fur.
Instance
One can have an instance of a class or a particular object. The instance is the actual object created at runtime. In programmer jargon, the Lassie object is an instance of the Dog class. The set of values of the attributes of a particular object is called its state. The object consists of state and the behaviour that’s defined in the object’s class.
Method
An object’s abilities. In language, methods are verbs. Lassie, being a Dog, has the ability to bark. So bark() is one of Lassie‘s methods. She may have other methods as well, for example sit() or eat() or walk() or save_timmy(). Within the program, using a method usually affects only one particular object; all Dogs can bark, but you need only one particular dog to do the barking.
Message passing
“The process by which an object sends data to another object or asks the other object to invoke a method.” [2] Also known to some programming languages as interfacing. E.g. the object called Breeder may tell the Lassie object to sit by passing a ‘sit’ message which invokes Lassie’s ‘sit’ method. The syntax varies between languages, for example: [Lassie sit] in Objective-C. In Java code-level message passing corresponds to “method calling”. Some dynamic languages use double-dispatch or multi-dispatch to find and pass messages.
Inheritance
‘Subclasses’ are more specialized versions of a class, which inherit attributes and behaviors from their parent classes, and can introduce their own.
For example, the class Dog might have sub-classes called Collie, Chihuahua, and GoldenRetriever. In this case, Lassie would be an instance of the Collie subclass. Suppose the Dog class defines a method called bark() and a property called furColor. Each of its sub-classes (Collie, Chihuahua, and GoldenRetriever) will inherit these members, meaning that the programmer only needs to write the code for them once.
Each subclass can alter its inherited traits. For example, the Collie class might specify that the default furColor for a collie is brown-and-white. The Chihuahua subclass might specify that the bark() method produces a high pitch by default. Subclasses can also add new members. The Chihuahua subclass could add a method called tremble(). So an individual chihuahua instance would use a high-pitched bark() from the Chihuahua subclass, which in turn inherited the usual bark() from Dog. The chihuahua object would also have the tremble() method, but Lassie would not, because she is a Collie, not a Chihuahua. In fact, inheritance is an ‘is-a’ relationship: Lassie is a Collie. A Collie is a Dog. Thus, Lassie inherits the methods of both Collies and Dogs.
Multiple inheritance is inheritance from more than one ancestor class, neither of these ancestors being an ancestor of the other. For example, independent classes could define Dogs and Cats, and a Chimera object could be created from these two which inherits all the (multiple) behavior of cats and dogs. This is not always supported, as it can be hard both to implement and to use well.
Abstraction
Abstraction is simplifying complex reality by modelling classes appropriate to the problem, and working at the most appropriate level of inheritance for a given aspect of the problem.
For example, Lassie the Dog may be treated as a Dog much of the time, a Collie when necessary to access Collie-specific attributes or behaviors, and as an Animal (perhaps the parent class of Dog) when counting Timmy’s pets.
Abstraction is also achieved through Composition. For example, a class Car would be made up of an Engine, Gearbox, Steering objects, and many more components. To build the Car class, one does not need to know how the different components work internally, but only how to interface with them, i.e., send messages to them, receive messages from them, and perhaps make the different objects composing the class interact with each other.
Encapsulation
Encapsulation conceals the functional details of a class from objects that send messages to it.
For example, the Dog class has a bark() method. The code for the bark() method defines exactly how a bark happens (e.g., by inhale() and then exhale(), at a particular pitch and volume). Timmy, Lassie‘s friend, however, does not need to know exactly how she barks. Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface — those members accessible to that class. The reason for encapsulation is to prevent clients of an interface from depending on those parts of the implementation that are likely to change in future, thereby allowing those changes to be made more easily, that is, without changes to clients. For example, an interface can ensure that puppies can only be added to an object of the class Dog by code in that class. Members are often specified as public, protected or private, determining whether they are available to all classes, sub-classes or only the defining class. Some languages go further: Java uses the default access modifier to restrict access also to classes in the same package, C# and VB.NET reserve some members to classes in the same assembly using keywords internal (C#) or Friend (VB.NET), and Eiffel and C++ allow one to specify which classes may access any member.
Polymorphism
Polymorphism allows the programmer to treat derived class members just like their parent class’ members. More precisely, Polymorphism in object-oriented programming is the ability of objects belonging to different data types to respond to method calls of methods of the same name, each one according to an appropriate type-specific behavior. One method, or an operator such as +, -, or *, can be abstractly applied in many different situations. If a Dog is commanded to speak(), this may elicit a bark(). However, if a Pig is commanded to speak(), this may elicit an oink(). They both inherit speak() from Animal, but their derived class methods override the methods of the parent class; this is Overriding Polymorphism. Overloading Polymorphism is the use of one method signature, or one operator such as ‘+’, to perform several different functions depending on the implementation. The ‘+’ operator, for example, may be used to perform integer addition, float addition, list concatenation, or string concatenation. Any two subclasses of Number, such as Integer and Double, are expected to add together properly in an OOP language. The language must therefore overload the concatenation operator, ‘+’, to work this way. This helps improve code readability. How this is implemented varies from language to language, but most OOP languages support at least some level of overloading polymorphism. Many OOP languages also support Parametric Polymorphism, where code is written without mention of any specific type and thus can be used transparently with any number of new types. Pointers are an example of a simple polymorphic routine that can be used with many different types of objects.[3]
Decoupling
Decoupling allows for the separation of object interactions from classes and inheritance into distinct layers of abstraction. A common use of decoupling is to polymorphically decouple the encapsulation, which is the practice of using reusable code to prevent discrete code modules from interacting with each other.

Not all of the above concepts are to be found in all object-oriented programming languages, and so object-oriented programming that uses classes is called sometimes class-based programming. In particular, prototype-based programming does not typically use classes. As a result, a significantly different yet analogous terminology is used to define the concepts of object and instance, although there are no objects in these languages.

PHP5 also support OOP now. Here we find how we could make a website using OOP technique. The first thing we’re going to look at is make your site object-oriented in a very simple way – we’ll make a site class and a page class. Then we’ll move onto looking at how we could subclass the page class so that we can have different types of page rendering differently.

index.php code:

<?php
include 'config.php';

$site = new csite();

// this is a function specific to this site!
initialise_site($site);

$page = new cpage("Magnolia Shoping cart");
$site->setPage($page);

$content = <<<EOT
Welcome to my Magnolia Shoping Cart!
EOT;
$page->setContent($content);

$site->render();
?>

The config.php file will contain the site-specific information – all the information that shouldn’t be inside our classes and shouldn’t be repeated in every page. We set $site to be an instance of our site, and then call a function called initialise_site() to set it up with our basic, site-specific settings – that function will be in config.php.
Next we create a cpage object, passing into the constructor the title of the page, then use the setPage() function of our csite class to add the page to our site for rendering.
config.php code:
<?php
function __autoload($class) {
include
"$class.php";
}

function

initialise_site(csite $site) {
$site->addHeader("header.php");
$site->addFooter("footer.php");
}
?>

The __autoload() function will load the pages dynamically and in initialise_site() function we add site-specific header and footer files for this site. ote that the __autoload() function will look for csite.php and cpage.php, so we need to supply those two.
csite.php code:
<?php
class csite {
private
$headers;
private
$footers;
private
$page;

public function

__construct() {
$this->headers = array();
$this->footers = array();
}

public function

__destruct() {
// clean up here
}

public function

render() {
foreach(
$this->headers as $header) {
include
$header;
}

$this->page->render();

foreach(

$this->footers as $footer) {
include
$footer;
}
}

public function

addHeader($file) {
$this->headers[] = $file;
}

public function

addFooter($file) {
$this->footers[] = $file;
}

public function

setPage(cpage $page) {
$this->page = $page;
}
}
?>

The cpage.php code:
<?php
class cpage {
private
$title;
private
$content;

public function

__construct($title) {
$this->title = $title;
}

public function

__destruct() {
// clean up here
}

public function

render() {
echo
"<H1>{$this->title}</H1>";

include("body.php");
echo
$this->content;
}

public function

setContent($content) {
$this->content = $content;
}
}
?>

So we’ve got $title and $content variables there.
The header.php file is site-specific, and so could be anything you want. Here’s an example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>My Website</TITLE>
</HEAD>

<BODY>

<table width="100%" border="0" cellspacing="0" align="center" height="28">
<tr>
<td><img src="images/header.gif" width="100%"></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" align="center" height="28">
<tr>
<td align="center"><h2>Magnolia Shoping cart</h2></td>
</tr>
</table>

Here’s a body.php example also:
<table id=”AutoNumber1″ style=”border-collapse: collapse;” border=”0″ cellspacing=”0″ cellpadding=”0″ width=”100%” bordercolor=”#111111″>
<tbody>
<tr>
<td colspan=”3″></td>
</tr>
<tr>
<td width=”23%”><img src=”images/jol3-5.gif” border=”0″ alt=”” width=”86″ height=”100″ /></td>
<td width=”2%” valign=”top”>
<p style=”margin-top: 2px; margin-bottom: 2px;”><strong> </strong></p>
</td>
<td valign=”top”>
<p style=”margin-top: 2px; margin-bottom: 2px;”><strong><span style=”font-family: Verdana; color: #cc3300; font-size: x-small;”>Joy of Learning-I</span></strong></p>

<p style=”text-align: justify; line-height: 12pt; margin-top: 2px; margin-bottom: 2px;”><span style=”letter-spacing: -0.15pt;”><span style=”font-size: x-small;”> <span style=”font-family: Verdana;”>A handbook of 75 activities to help children understand different facets of the environment, developed for the National Council for Educational Research and Training (NCERT). Each activity is presented in a user-friendly format with suggestions as to the subjects in which the activity can be introduced; variations/extensions; ideas for evaluation, etc. Useful for teachers of standards 3 to 5. Pages 88
</span></span></span>
<p class=”MsoNormal” style=”text-align: center; line-height: 12pt; margin-top: 2px; margin-bottom: 2px;”><span style=”font-family: Verdana; font-size: xx-small;”> <a href=”http://www.edutechindia.org/currency.asp?id=1&amp;catid=1&amp;p=m”&gt; Add to Cart </a></span></p>
</td>
</tr>
<tr>
<td colspan=”3″><hr size=”1″ noshade=”noshade” /></td>
</tr>
<tr>
<td width=”23%”><img src=”images/nsins.gif” border=”0″ alt=”” width=”86″ height=”100″ /></td>
<td width=”2%” valign=”top”>
<p style=”margin-top: 2px; margin-bottom: 2px;”><strong> </strong></p>
</td>
<td valign=”top”>
<p style=”margin-top: 2px; margin-bottom: 2px;”><strong><span style=”font-family: Verdana; color: #cc3300; font-size: x-small;”>Nature Scope -Incredible Insects</span></strong></p>

<p style=”text-align: justify; line-height: 12pt; margin-top: 2px; margin-bottom: 2px;”><span style=”letter-spacing: -0.15pt;”><span style=”font-size: x-small;”> <span style=”font-family: Verdana;”>NatureScope India is a creative education series dedicated to inspiring children towards an understanding and appreciation of the natural world while developing the skills they will need to make responsible decisions about the environment. Divided into different sections, each section deals with an insect theme and includes background information and activities related to that theme.In English Pages: 51
</span></span></span>
<p class=”MsoNormal” style=”text-align: center; line-height: 12pt; margin-top: 2px; margin-bottom: 2px;”><span style=”font-family: Verdana; font-size: xx-small;”> <a href=”http://www.edutechindia.org/currency.asp?id=148&amp;catid=1&amp;p=m”&gt; Add to Cart </a></span></p>
</td>
</tr>
<tr>
<td colspan=”3″><hr size=”1″ noshade=”noshade” /></td>
</tr>
<tr>
<td width=”23%”><img src=”images/clothfold.gif” border=”0″ alt=”” width=”86″ height=”100″ /></td>
<td width=”2%” valign=”top”>
<p style=”margin-top: 2px; margin-bottom: 2px;”><strong> </strong></p>
</td>
<td valign=”top”>
<p style=”margin-top: 2px; margin-bottom: 2px;”><strong><span style=”font-family: Verdana; color: #cc3300; font-size: x-small;”>Handmade Seminar Folder with Cloth Covering</span></strong></p>

<p style=”text-align: justify; line-height: 12pt; margin-top: 2px; margin-bottom: 2px;”><span style=”letter-spacing: -0.15pt;”><span style=”font-size: x-small;”> <span style=”font-family: Verdana;”>Available in different colours, designs and patterns. Price Rs. 50.00 onwards.
</span></span></span>
<p class=”MsoNormal” style=”text-align: center; line-height: 12pt; margin-top: 2px; margin-bottom: 2px;”><span style=”font-family: Verdana; font-size: xx-small;”> <a href=”http://www.edutechindia.org/currency.asp?id=158&amp;catid=21&amp;p=m”&gt; Add to Cart </a></span></p>
</td>
</tr>
<tr>
<td colspan=”3″><hr size=”1″ noshade=”noshade” /></td>
</tr>
<tr>
<td width=”23%”><img src=”images/sclabelbirds.gif” border=”0″ alt=”” width=”86″ height=”100″ /></td>
<td width=”2%” valign=”top”>
<p style=”margin-top: 2px; margin-bottom: 2px;”><strong> </strong></p>
</td>
<td valign=”top”>
<p style=”margin-top: 2px; margin-bottom: 2px;”><strong><span style=”font-family: Verdana; color: #cc3300; font-size: x-small;”>School Labels – Birds</span></strong></p>

<p style=”text-align: justify; line-height: 12pt; margin-top: 2px; margin-bottom: 2px;”><span style=”letter-spacing: -0.15pt;”><span style=”font-size: x-small;”> <span style=”font-family: Verdana;”>Sheet of 36 labels
</span></span></span>
<p class=”MsoNormal” style=”text-align: center; line-height: 12pt; margin-top: 2px; margin-bottom: 2px;”><span style=”font-family: Verdana; font-size: xx-small;”> <a href=”http://www.edutechindia.org/currency.asp?id=160&amp;catid=21&amp;p=m”&gt; Add to Cart </a></span></p>
</td>
</tr>
</tbody></table>

Here’s a footer.php example also:
<table width=”100%” border=”0″ cellspacing=”0″ align=”center” height=”28″>
<tr>
<td><img src=”images/footer-toptile.gif”></td>
</tr>
</table>
</BODY>
</HTML>
Now all works complete. Run it to see a very simple site.
Your website is totally developed in OOP way. What a great feelings.

Call Center in Bangladesh

https://i0.wp.com/www.commpartnersconnect.com/images/call_center.jpg

call center:

A call center is a physical place where customer and other phone calls are handled by a live person or persons, organization, usually with some amount of computer automation. Usually, a call center or call centre has the ability to handle a considerable volume of calls at the same time, to screen calls to multi level and forward them to someone experience and qualified to handle those incoming call, and to log calls. Call centers are used by phone, skype, msn massenger, yahoo massenger, mail order catalog organizations, telemarketing companies, computer product help desks, and large companies that uses the telephone to sell products and services or provide information or help customer to resolve an problem. Some most popular terms of call centers are virtual call center and contact center.

A call centre is operated by a company to administer incoming product support or information inquiries from consumers. Outgoing calls for telemarketing, product marketing, product or service feedback, and debt collection are also made. In addition to a call centre, collective handling of any kind of live personal help with the voice communication.

call center in Bangladesh:

Bangladesh is now trying hard to grab a share of the multi billion dollar outsourcing pie by gearing up to join the bandwagon. Licenses for the country’s first-ever telephone-based call centers are issued in February 2008. The Bangladesh Telecommunication Regulatory Commission (BTRC), which is the licensing authority has invited individuals and firms to apply. Bangladesh is also planning to have first of its own telephone based call center in country. The ministry and the corporate figures of country is amazed by the growth and the wealth generated by its neighbor India by this Call Centre, BPO industry.

The list of call centers, contact centers, BPO, VOIP companies in Bangladesh are given below:

Name Description

24 Hours Call

24 Hours Call provides outsourcing call center services to their call center customers with cost effective pricing module and quality output. 24 Hours Call has the resources, technology and operating …

Aeon Technologies

Aeon Technologies provides International (Inbound) and Domestic Call Center/Contact Center Services. Aeon Technologies is a new generation outsourcing company formed by the joint venture of U.S. outso…

Alvee Telecom

Alvee Telecom is a leading provider of Internet telephony solutions to consumers, resellers and service providers worldwide. Alvee Telecom offers a wide range of Voice over IP (VoIP) services includin…

Bangladesh Professional Training Institute

In early 2006, BPTI has entered into the skill development sector of Bangladesh with the platform of R&G Group. BPTI has earned the reputation of being a cost effective and career oriented training in…

Concord InfoTech

Concord InfoTech provides outsourced telephone based customer service and sales from Bangladesh for USA, UK, Canada, Australia and South African markets. Concord InfoTech Bangladesh is strongly posit…

Dial Management

Dial Management is a consultant organization providing different solutions for entrepreneurs intending to start call centre business. Dial has tied up with TechMark Solutions Limited and with DIAL to …

HMC Technology

HMC Technology is your one stop Hosted Call Center Service Provider. At HMC you will find professional call Agents, helpful and diligent individuals who specialize in ensuring quality Telemarketing an…

Imam Network

Imam Network offered the call center structure that is for the corporations to communicate with customers by advanced communication technology. It realizes customer services, sales and market deployme…

Institute of Call Center technologies (ICCT)

Institute of Call Center Technologies is the leading training and development organization in our country. Driven by a vision to provide cutting edge learning solutions to organizations and individual…

MinutesXchange Communications

MinutesXchange Communications is a global provider of advanced voice and data communication services into deregulated, rapid growth and emerging markets offering international carriers and service pro…

Nihan Technologies and Consultancy Ltd.

Nihan Technologies and Consultancy Ltd. (NTCL) a visionary and goal-oriented professional IT Organization established in 2002 with demonstrated technical skills and broad experience in planning, devel…

OneCall

OneCall is the first Indepent Call Centre In Bangladesh. They at OneCall believe in the organization wide mantra of “Quality Drives Performance” OneCall is always striving to set new standards…

REVE Systems

REVE Systems is a privately held company registered in Bangladesh. It takes IP based communication as the core segment for its working area since the beginning. Being very much focused on IP based com…

RT Telecom and IT Services

RT Telecom and IT Services Ltd is one of the newest call centers in the Bangladesh. They are globally progressive outsourced telemarketing company trusted by their affiliated companies, mostly based…

SysTel Communications

SysTel Communications provides International (Inbound) and Domestic Call Center/Contact Center Services. SysTel Communications is a new generation outsourcing company formed by the joint venture …

TZCalling

It is the mission of TZCalling to provide clients with top quality call centre services 24 hours-a-day. A service, that provides our clients with the greatest chance of communicating with their end customer.

VocalLogic

Vocallogic is a company with global presence geared towards providing affordable VoIP, networking and communication technology solutions. Based in Minneapolis, Minnesota Vocallogic currently operates …

Wave Consortium Limited

Wave Consortium Limited has set up its mission with the aim of providing IT solutions, Complete Call Center Solutions, software development, outsourcing, and IT solution provider.

Xways Soft Pvt Ltd.

XWAYS SOFT (PVT) LTD is one of the leading Bangladesh Telecommunication Regulatory Commission (BTRC) Approved VSAT provider in Bangladesh, It has the vision to become a pioneer information Technology …

Zamir Telecom Limited

Zamir Telecom is one of Bangladesh`s most promising VOIP solutions provider of the present time. Zamir Telecom Ltd is the only VOIP termination provider to make way in Telehouse Europe Data centre at …

Wanna start a new call center:

Call Center Diagram in Bangladesh By BTRC

CALL-CENTER-DIAGRAM-bangladesh-1

International Call Center

call-center-diagram-bangladesh-2

Domestic Call Center

You can start call center by opensource software. You can buy any call center software or develop your own software by using some opensource software.

Nortel http://www.nortel.com/
Avaya http://www.avaya.com/
Cisco http://www.cisco.com
Digisoft http://www.digisoft.com/

You also find a list of Business Call Center Software in the following link: http://www.business.com/directory/telecommunications/call_centers/software/

If you wanna start a call center now you can read this article written by Dr. Mashiur Rahman which will help you a lot: http://mashiur.biggani.org//images/mashiur/open_source_and_call_center.pdf

Olympics 2008- Medals Table

24th August was the closing day of Beijin Olympic games 2008. Here is the medals table where you can see the country wise performance:

Rank Country Gold Silver Bronze TOTAL
1 China 51 21 28 100
2 USA 36 38 36 110
3 Russia 23 21 28 72
4 Great Britain 19 13 15 47
5 Germany 16 10 15 41
6 Australia 14 15 17 46
7 South Korea 13 10 8 31
8 Japan 9 6 10 25
9 Italy 8 10 10 28
10 France 7 16 17 40
11 Ukraine 7 5 15 27
12 Netherlands 7 5 4 16
13 Jamaica 6 3 2 11
14 Spain 5 10 3 18
15 Kenya 5 5 4 14
16 Belarus 4 5 10 19
17 Romania 4 1 3 8
18 Ethiopia 4 1 2 7
19 Canada 3 9 6 18
20 Poland 3 6 1 10
21 Hungary 3 5 2 10
22 Norway 3 5 2 10
23 Brazil 3 4 8 15
24 Czech Republic 3 3 0 6
25 Slovakia 3 2 1 6
26 New Zealand 3 1 5 9
27 Georgia 3 0 3 6
28 Cuba 2 11 11 24
29 Kazakhstan 2 4 7 13
30 Denmark 2 2 3 7
31 Mongolia 2 2 0 4
32 Thailand 2 2 0 4
33 DPR Korea 2 1 3 6
34 Argentina 2 0 4 6
35 Argentina 2 0 4 6
36 Mexico 2 0 1 3
37 Turkey 1 4 3 8
38 Zimbabwe 1 3 0 4
39 Azerbaijan 1 2 4 7
40 Uzbekistan 1 2 3 6
41 Slovenia 1 2 2 5
42 Bulgaria 1 1 3 5
43 Indonesia 1 1 3 5
44 Finland 1 1 2 4
45 Latvia 1 1 1 3
46 Belgium 1 1 0 2
47 Dominican Rep 1 1 0 2
48 Estonia 1 1 0 2
49 Portugal 1 1 0 2
50 India 1 0 2 3
51 Iran 1 0 1 2
52 Bahrain 1 0 0 1
53 Cameroon 1 0 0 1
54 Panama 1 0 0 1
55 Tunisia 1 0 0 1
56 Sweden 0 4 1 5
57 Croatia 0 2 3 5
58 Lithuania 0 2 3 5
59 Greece 0 2 2 4
60 Trinidad & Tob 0 2 0 2
61 Nigeria 0 1 3 4
62 Austria 0 1 2 3
63 Ireland 0 1 2 3
64 Serbia 0 1 2 3
65 Algeria 0 1 1 2
66 Bahamas 0 1 1 2
67 Colombia 0 1 1 2
68 Kyrgyzstan 0 1 1 2
69 Morocco 0 1 1 2
70 Tajikistan 0 1 1 2
71 Chile 0 1 0 1
72 Ecuador 0 1 0 1
73 Iceland 0 1 0 1
74 Malaysia 0 1 0 1
75 Singapore 0 1 0 1
76 South Africa 0 1 0 1
77 Sudan 0 1 0 1
78 Vietnam 0 1 0 1
79 Armenia 0 0 6 6
80 Chinese Taipei 0 0 4 4
81 Afghanistan 0 0 1 1
82 Egypt 0 0 1 1
83 Israel 0 0 1 1
84 Mauritius 0 0 1 1
85 Rep of Moldova 0 0 1 1
86 Togo 0 0 1 1
87 Venezuela 0 0 1 1

Source:Full interactive medal table

Living With Technology: Secure yourself

Hi Pals,
How can you protecting yourself while living with technology? CNET suggest you something below:
Protecting yourself is hard in these tech times. From ID theft to data breaches, computer crimes are skyrocketing, and there are conflicting reports on the best ways to secure your own information. Get a little peace of mind with CNET’s guide to the best ways to secure yourself and your data.