[UPHPU] classes drive me nuts
Steve Dibb
sdibb at wonkabar.org
Mon Jun 21 16:39:03 MDT 2004
Ah, thank you Dustin -- #3 was what I was trying to remember how to do, and it works! :)
steve
> You can accomplish a few different ways. First, you
> could have your class inherit the PEAR DB class and
> then just call the methods you want from within your
> own classes methods [Example 1]. This, most of the
> time, is regarded as poor OOP style although on
> occasion it can be justified.
>
> Another option is to create a member variable in your
> class and in the constructor set it equal to a new DB
> object. [Example 2]
>
> But it sounds to me like you plan on creating a DB
> object and passing it around to the various objects
> that may need it. If that's the case I would just pass
> a reference to the object into the constructor of my
> custom class and store it in a member variable.
> [Example 3] For completeness I should mention the fact
> that you could just set a member variable equal to the
> DB object after your custom object is instantiated,
> but this also is regarded as poor OOP style.
>
> Here are examples of how to accomplish the first three
> options:
> [Example 1]
> class MyClass extends DB
> {
> function MyMethod()
> {
> this->Query($sql);
> }
> }
>
> [Example 2]
> class MyClass
> {
> var MyDB;
>
> function MyClass()
> {
> this->MyDB = new DB();
> }
>
> function MyMethod()
> {
> this->MyDB->Query($sql);
> }
> }
>
> [Example 3]
> class MyClass
> {
> var MyDB;
>
> function MyClass(refDB)
> {
> this->MyDB = refDB;
> }
>
> function MyMethod()
> {
> this->MyDB->Query($sql);
> }
> }
>
> MyObj = new MyClass(&$DB);
>
> Sorry for the long post guys, please let me know if I
> should avoid such long posts in the future.
>
> Dustin
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: list-unsubscribe at uphpu.org
> For additional commands, e-mail: list-help at uphpu.org
More information about the UPHPU
mailing list