<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">That’s easy to do by allowing an Animal to hold multiple modes. Yes, the code below uses a Protocol, but only as an OO interface.<div class=""><br class=""></div><div class=""><font face="Monaco" class="">let alligator = Animal()</font></div><div class=""><font face="Monaco" class="">alligator.mode.append(Land())</font></div><div class=""><font face="Monaco" class="">alligator.mode.append(Sea())</font></div><div class=""><font face="Monaco" class=""><br class=""></font></div><div class=""><font face="Monaco" class="">protocol Mode {</font></div><div class=""><font face="Monaco" class=""> func attack() -> Bool</font></div><div class=""><font face="Monaco" class=""> func move() -> Bool</font></div><div class=""><font face="Monaco" class="">}</font></div><div class=""><font face="Monaco" class=""><br class=""></font></div><div class=""><font face="Monaco" class="">class Animal {</font></div><div class=""><font face="Monaco" class=""> var modes: [Mode]</font></div><div class=""><font face="Monaco" class=""> func attack() -> Bool {</font></div><div class=""><font face="Monaco" class=""> for mode in modes {</font></div><div class=""><font face="Monaco" class=""> if mode.attack() {</font></div><div class=""><font face="Monaco" class=""> break</font></div><div class=""><font face="Monaco" class=""> }</font></div><div class=""><font face="Monaco" class=""> }</font></div><div class=""><font face="Monaco" class=""> }</font></div><div class=""><font face="Monaco" class="">}</font></div><div class=""><br class=""></div><div class=""><br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 15, 2016, at 1:43 PM, Jon Hoffman <<a href="mailto:hoffman.jon@gmail.com" class="">hoffman.jon@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Thank you for the feedback however you cannot design the code as you describe, if I understand your explanation correctly, because one of the requirements is the animals may be apart of multiple categories. As the example in the post shows the alligator belongs to both the Land and the Sea categories. In you description that would mean that the Alligator type would need to be a subclass of both the Land and Sea superclasses which is not permitted. Remember that one of the drawbacks with OOP is a subclass can only inherit from one superclass.<div class=""><br class=""></div><div class="">Jon</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Feb 15, 2016 at 1:17 PM, Daniel Tartaglia <span dir="ltr" class=""><<a href="mailto:danielt1263@gmail.com" target="_blank" class="">danielt1263@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">(Reposting because I forgot to change the subject line. Hope that this is the correct thing to do.)</div><div class=""><br class=""></div>I have to say John that I am not a fan of your OOP code. I would have written the OOP code very much like you wrote the POP version using the Strategy pattern.<br class=""><div class=""><div style="word-wrap:break-word" class=""><div class=""><br class=""></div><div class=""><div class=""><font face="Monaco" class="">[Animal]<*>--->[Mode]</font></div><div class=""><font face="Monaco" class=""> ^</font></div><div class=""><font face="Monaco" class=""> |</font></div><div class=""><font face="Monaco" class=""> +------+------+</font></div><div class=""><font face="Monaco" class=""> | | |</font></div><div class=""><font face="Monaco" class=""> [Land] [Sea] [Air]</font></div><div class=""> </div></div><div class=""><br class=""></div><div class="">(View the above with a mono-spaced font.)</div><div class=""><br class=""></div><div class="">In essence, I see no difference. There may be a difference, but I don’t think your example presents one.</div><div class=""><br class=""></div></div></div></div></blockquote></div></div></div></blockquote></div><br class=""></div></div></body></html>