This post contains two examples of Adapter Design Pattern using PHP. I am giving these examples in order to understand more comprehend about Adapter Pattern.
First, implementation of Adapter Design Pattern statement
Convert the interface of a class into another interface clients expect.
Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.
Adapters are helpful if you want to use a class that doesn’t have quite the exact methods you need.
Second, implementation of using legacy class and you can’t change that legacy class but you want to port its method to another needful method.
An example class ‘clsProducts’ methods can be used inside many Adapter class to returns another result.
clsProducts object instance is passed as Adapter classes constructor argument and clsProducts methods are being used inside those Adapter classes.
Abstract factory pattern is to “provide an interface for creating families of related or dependent objects without specifying their concrete classes.”
For example a drawing & printing machine can process Low and High Resolution. Both have its own resolution drivers. Those drivers referred to concrete class with draw / print function. However the client implementation code asks the factory object class (not the concrete class) for a driver instance with provides information about resolution required. So this factory object return instance of concrete class.
The factory object implements an abstract class. It can instantiates a concrete class and return to client with casted to factory’s parent which is abstract Resolution driver.
The client uses the resolution driver as abstract without being aware about their concrete implementation.
Benefit of using factory pattern is in client code implementation, new resolution can be added with just providing that new resolution info as argument. So no change in client code.
Any table like objects like array and recordset have same structure. They have rows and columns.
Usually column is a key and row is a value.
A recordset that comes from database ‘select’ operation usually stored in array or OOP object variable on MVC concept or any kind of business logic and view layer.
A web page access this variable to show its data. View layer only include database and datatable class files. So web page users doesn’t access database operational directly.
With this concept, I have build a simple DataTable class to store those kind of objects.
This DataTable has functions to add columns and rows and get their values so that we can extract information from DataTable with easy and use same methods repeatedly.
Also we can get DataTable object value on another page with SESSION functionality.
Posted in PHP
Tagged DataTable, DB2, db2_close, db2_connect, db2_fetch_array, OOP, PHP, PHP Example, PHPExcel, session, web paging
Many ways to create a progress bar but in this blog post I give example on PHP Progress bar built with OOP.
The reason I use OOP is that the class can be used again for any purpose which need progress bar.
We need interface OOP object which contains three methods which are
get_max() returns maximum value that progress bar will have,
get_progress() returns current progress value or progress percentage. This progress percentage value sets progress bar value and
do_work() to do a real work like database or files operation or else.
I use JQuery to draw Progress Bar in User Interface because of simplicity to make it with JQuery. I assume that you already know basic of progress bar and JQuery.
In programming languages, polymorphism means that some code or operations or objects behave differently in different contexts.
It able to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes.
So it is overloading parent object. Child objects has all methods in their parent and childs can have more methods.
Several parent object type to support polymorphism are class, abstract and interface. In this post, I use ‘abstract’ class as parent to give polymorphism demo due to I will using it as wrapper class.
What I mean of wrapper class is I do not have to write same code over and over again in every child classes. I only have to write once in the abstract functions.
Abstract class can not have an instance or real object. It is only model of the class design but the different from ‘interface’ that abstract can have a body inside function declaration.
To explain the differences between abstract, interface and general class, look at code below: Continue reading
Many organizations use multi database software. For example an organisation’s HRD system using SQL Server and on its ERP they use DB2.
To develop an application that can connect to DB2 and SQL Server using PHP, we need database-independent connection object.
Small web application doesn’t require architecture design. It means server script, html, client script can be put on single file for one web page. On the other hand, large business and scope with much more user, change requirement occurs so many times requires good & reliable web architecture design. It is just not simple any more to put everything on single file since the web may update and grow often.
When business requirement become more complex then related web application usually consume more programmers.
Those programmers can work per module i.e. manufacturing, finance, sales, shipping modules etc. One programmer / team work on manufacturing and other programmers / team work on other modules. It depends on software designer, sometimes work module could be mix.