Re: PDO: extend or encapsulate?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Jul 15, 2012 at 5:50 AM, shiplu <shiplu.net@xxxxxxxxx> wrote:
> From OOP point of view.
>
> Use encapsulation:
> When a class has a "has-a" relation-ship with other class you should use
> encapsulation. For example, If MyDB is a class that "has-a" pdo driver in
> it, then PDO will be encapsulated inside MyDB class. This is also called
> containment. MyDB should contain PDO.
>
> Use inheritance:
> When a class has a "is-a" relation ship with other class use inheritance.
> For example,  Dog is an Animal. so Dog should extend Animal class. MyPHPDb
> is-a PHP Database Object (aka PDO). So it'll be inheritance. MyPHPDb should
> extend PDO.
>
> Think about the relation have. Then implement it.
>
>
> --
> Shiplu.Mokadd.im
> ImgSign.com | A dynamic signature machine
> Innovation distinguishes between follower and leader
>

Yes, good: "has-a" and "is-a". In some cases, the distinction seems
clear. The think in this case, the class I'm implementing "has-a" PDO
driver, rather than "is-a" PDO driver. In this case, I'm encapsulting
the PDO classes within my class to provide removal of details from the
main program for dealing with data, which isn't particularly
interested in how that data is manipulated or stored.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux