--- "Stig S. Bakken" <[EMAIL PROTECTED]> wrote:
> On Sat, 2002-04-06 at 23:40, brad lafountain wrote:
> > 
> > --- "Stig S. Bakken" <[EMAIL PROTECTED]> wrote:
> > > MI is compile-time, aggregate is runtime.  That's a big enough reason
> > > for me.
> > 
> >  I know the difference but how does this benifit you?
> > 
> > > 
> > > > Class definition is defined at design time not run time!
> > > 
> > > Aggregate is not really about class definition.  The shortcut in the
> > > current implementation modifies the class definition, but in its basic
> > > form, aggregation is about forwarding calls, not about changing class
> > > definitions.  Thus my suggestion to change aggregate as in my first
> > > reply to Kristian.
> > 
> >  Ok... Can you give me a good example that aggergate would be used over MI.
> > That makes sence and isn't garbage code!
> 
> Okay, a good example could be a database abstraction layer supporting
> ODBC with special handling of each database behind ODBC.
> 
> For example, if you use ODBC to talk with MySQL, Oracle or Solid, you
> have three ways of dealing with sequences (mysql only has auto_increment
> fields, Oracle has real sequences, but for Solid 2.x you need to define
> and use a procedure to get sequence values).  If you use iODBC to do all
> this, you won't know which one you're talking to until after connecting.
> 
> Example set of classes using aggregate to customize at runtime:
> 
> DB_Connection          generic connection object
> DB_Connection_odbc     layer interfacing to PHP's odbc functions
> DB_Connection_oracle   ditto for Oracle
> DB_Connection_mysql    ditto for MySQL
> DB_SQL_oracle          SQL portability layer for Oracle
> DB_SQL_mysql           ditto for MySQL
> 
> If the user requests a connection to an Oracle database, the connect
> function returns an instance of DB_Connection that has aggregated
> DB_Connection_oracle and DB_SQL_oracle.
> 
> But if the user requests a connection to Oracle through ODBC, the
> connect function returns an instance of DB_Connection that has
> aggregated DB_Connection_odbc.  After connecting to the database,
> DB_Connection_odbc detects that it is used against Oracle and aggregates
> DB_SQL_oracle.

 Are you saying the connect function aggergates the specfic connectio class and
the specfic sql class? or the Connection class connect method aggerates the sql
class?


 You don't even need aggergate or MI for this.

 What would be wrong with having the *_SQL_* objects be a member of the
*_Connection* classes? It makes sence that a connection you can't have a
connection without having a SQL implementation. Then you could make a generic
one for most cases. Then you could ither have a get_sql() mehtod. This would
make more sence.

class DB_Connection_Factory
{
 function get_connection($type)
 {
   switch($type)
   {
   case 'oracle':
     return new DB_Connection_oracle($type);
   break;
   case 'odbc':
     return new DB_Connection_odbc($type);
   break;
   ...
   }
 }
}

class DB_Connection
{
 var $sql;
 function DB_Connection($type)
 {
   switch($type)
   {
   case 'oracle':
    $this->sql = new DB_SQL_oracle();
   break;
   case 'mysql':
    $this->sql = new DB_SQL_mysql();
   break;
   default:
    $this->sql = new DB_SQL();
   break;
   }
 }
 function connect($server, $u, $p)
 { 
 }
 function set_sql($sql)
 {
   $this->sql = $sql;
 }

}
class DB_Connection_odbc extends DB_Connection
class DB_Connection_oracle extends DB_Connection
class DB_Connection_mysql extends DB_Connection
class DB_SQL
class DB_SQL_oracle extends DB_SQL
class DB_SQL_mysql extends DB_SQL

$connection = DB_Connection_Factory::get_connection(oracle);
$connection->connect(server, l, p);
$sql = $connection->get_sql_handler();
$ret = $sql->query($query);
 or
$connection = new DB_Connection();
$ret = $conection->sql->query($query);

They way that you describe first will be slower than the above code and they
way it hides the sql class from the connection class theres now way to mix and
match sql classes with connection class. 

$connect->set_sql(new DB_SQL_mysql());
this works way nicer cause theres no way to "unaggergate" classes methods.

IMHO as far as pure OO design goes this way is way bettter than the way that
you described.

__BRAD__


__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to