What you have done isn't a Proxy per se. You have just created an object factory.

What may be wiser is to eliminate the "proxy" and pass breeds into the type Dog. Create a common class called Breed, and a second one extending Breed called DogBreed.

If you are worried about someday of an impossible breed being assigned to a wrong animal, pass the animal to the breed extensions (DogBreed,CatBreed) to validate that what you are about to assign is compatable. Or you can have the base breed provide a function to Dog for it to call to validate you aren't doing that type of silliness.

But don't get me wrong, object factories are really useful for uncanny patterns of construction. KatterBox does this, as every katterbox needs a configuration based on an input parameter. The factory method will sort everything out and pass back a katterbox object.

The proxy pattern, aka delegation pattern, is useful too. They are great for when you want to leave the flow of calls alone, but inserting a behaviour inbetween for some reason. In things like DB calls, a proxy pattern could help you find out how long a call took and how many times it was called.

Nice work none-the-less. I'm sure if you think in terms of 1000 breeds, and maybe expanding out your pattern to various species, you'll change your design. For a very small set of objects, your design is quite sound.

----
Then B.I. said, "Hov' remind yourself nobody built like you, you designed yourself"


In reply to Re: Polymorphism and Abstraction by exussum0
in thread Polymorphism and Abstraction by hypochrismutreefuzz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.