Yes, if you have "book is-a page" you may run into some weirdness.That is why 
the "has-a" relationship is useful.
A book "has" pages. Because of the underlying data structure in my case, to 
continue the example, the book "has"a pointer to the first page.
My question arose because it seems that Perl's built in OO system allows you to 
do "has-a" but only asa slight twist on "is-a". Or may be not. Has there been 
an answer to that yet? If so, I didn't see it.
Check out the wikipedia page on has-a http://en.wikipedia.org/wiki/Has-a
I was thinking along the lines of the example there of a car that "has-a" 
chassis when making my LinkedList that "has-a" head node.
I'm not making an bold claims that this is the best way to do it, again, this 
was just my experimenting with some code late at night.

> Date: Sun, 2 Nov 2014 09:14:35 -0600
> Subject: Re: [Boston.pm] object composition (has-a) with built-in OO system
> From: [email protected]
> To: [email protected]
> CC: [email protected]; [email protected]
> 
> My experience has been that having a page instance be mangled
> in some way to behave like a book is almost always going to be
> a regrettable coding decision.
> 
> What I sometimes do would be to have the page contain a pointer
> to the book in which it is bound, so that the page can call
> book level methods.
> 
> If a page needed to display "page 1 of <total>", it would need
> to call the book method to find out the total number
> of pages in the book. It starts getting weird for me if the
> page class has or inherits book level methods.
> 
> ymmv
> Greg
> 
> 
> On Sun, November 2, 2014 12:03 am, Adam Russell wrote:
> > I would rather have a "book" have "pages"than just have "pages". Perhaps
> 
> >>> The approach I took was to define a package LinkedListNode and then a
> >>>  package LinkedList. My idea is that my LinkedList package is a
> >>> wrapper around the head node which would also define some useful
> >>> methods such as print_list(), remove_node(), and so forth.
> 
> 
> 
                                          

_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to