Thursday, March 21, 2013

Design Patterns - Composite Pattern

Introduction

A design pattern is a specific way of solving a particular problem. They are not simply about reusing code; they are more abstract and generalized than that. They are about using reusing ideas.

Composite Pattern

The next figure shows the general case for the composite:

The composite pattern has two parts: the Component abstract class and the Composite, which is a concrete implementation of the Component class. All Composite objects descend from the abstract Component class. Any Component can contain other Components. A Component with no children can be thought of as an empty Composite.

Moving back from the general case, it will be necessary to make a change in the design and switch the Instrument interface to an abstract class. Interfaces and abstract classes are similar because neither one can be used directly to instantiate an object. The key difference is that an abstract class can have some fully implemented methods, whereas interfaces just have method declarations.

All text and images above is from the book:"Professional PHP5" ISBN: 0-7645-7282-2 (Lecky-Thompson et al., 2005)

Monday, March 11, 2013

Commands Vi/Vim editor

As system administrator, I have needed to edit configuration files of some services such as DNS (Domain Name System), LDAP (Lightweight Directory Access Protcol) and etc.

The editor I was using frequently was nano and rarely I used pico. All those editors were used on Ubuntu. When I decided to fit in CentOS, I noticed that I had to install package nano. But I did not want to! I wanted to vary and then I searched and found editor Vi (also it is equal to Vim, although Vim has more features than Vi). I confess, at first time, it was very confused. I did not know what commands to edit file and much less how to save the changes and exit. So I googled and found some commands useful to edit files.

Hereafter, you will see a list of commands to Vi/Vim editor:

CommandDescription
:wqSave the file and exit
:wSave the file
:qQuit and Vi/Vim refuses to exit if any changes was made
:!qQuit without changes to save
:aAppend after cursor
:iInsert after cursor
ESCExit insert/overwrite mode and go back to command mode