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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |