| 
	
 | 
 Posted by Jerry Stuckle on 09/07/05 21:27 
Markus Ernst wrote: 
>  
> Yes, this is a very useful guideline one sometimes tends to forget. Anyway  
> in this case the generalized abstract object is useful for handling the  
> relations between different things - i.e. a text element can be assigned to  
> a page, or to an author (biography), or to a book (abstract). A page can be  
> assigned to a rubric, or to an author (extended biography, works list...),  
> or to a book (review, excerpt...). Therefore I decided to use one  
> centralized ID and relations handling.  
>  
>  
 
Markus, 
 
But herein lies the problem.  Inheritance is not applicable here.  A  
text element is not a "type of" a page.  Rather, a page "contains" one  
or more text elements. 
 
A biography is a "type of" a book, so it would be applicable to derive  
biography from book.  The book also "has an" author, but the author is  
not a "type of" text element (or vice versa). 
 
Applying inheritance correctly can be quite complex - and I've seen it  
misused quite a bit. 
 
I use inheritance a fair amount.  For instance - one I'm working on now  
is for a non-profit.  I have a hierarchy: 
 
   Person -> Member -> Board Member 
 
Person includes non-members who have attended meetings and otherwise  
shown an interest in the organization.  Members are Persons with a  
Member ID number and an expiration date.  Board Member has the  
additional attribute of Position. 
 
Unfortunately, MySQL isn't an OO DB, so I need to fudge a little.  I  
could, for instance, put a Position column in the Persons table.  But  
that would end wasting space for those who are non-members. 
 
So, I assign every person an internal ID (auto increment column).  I  
have a Members table with the ID, membership number which is linked to  
the Person table.  And a BoardMember table contains the ID and position. 
 
The beauty of this is that all the work is hidden.  If, for instance, I  
want to send an email to everyone, I use a PersonList object.  For  
Members, a MemberList object, and Board Members I create a  
BoardMemberList object.  *All* the rest of the code to send the emails  
is exactly the same.  It's just a matter of which object I create.  In  
fact, the creation of the object is similar to: 
 
   switch($POST['mailto']) { 
     case 'All' : 
       $list=new PersonList(); 
       break; 
     case 'Members': 
       $list = new MemberList(); 
       break; 
     case 'Board': 
       $list = new BoardMemberList(); 
       break; 
     default: 
       $emsg = 'No list selected'; 
       break; 
   } 
   (rest of processing) 
 
This is a perfect *applicable* use for inheritance. 
 
 
--  
================== 
Remove the "x" from my email address 
Jerry Stuckle 
JDS Computer Training Corp. 
jstucklex@attglobal.net 
==================
 
  
Navigation:
[Reply to this message] 
 |