x404.co.uk http://www.x404.co.uk/forum/ |
|
Whats this OO principle called? http://www.x404.co.uk/forum/viewtopic.php?f=4&t=14785 |
Page 1 of 1 |
Author: | Fogmeister [ Tue Sep 20, 2011 7:54 am ] |
Post subject: | Whats this OO principle called? |
I'm trying to find some info about writing a class structure in Obj-C but I can't think of the name of the prinicple? Basically I want a single Class called something like BasicStrategy but it will never be initialised into an Object (almost an Abstract Class?). It will have certain methods like... sanityCheck, setState, execute, etc... These will all do something except for the execute methods. Then I want to create several other classes that inherit from the BasicStrategy but then override the execute method so that it does something different. That way I can have a method inside BasicStrategy that does something like.... self.setState(); self.sanityCheck(); self.execute(); and then in (for instance) ComplexStrategy I can have the execute method containing the code for the complex strategy and it will then run that instead of whats in the BasicStrategy bit. I hope that makes sense. I knwo it has a name but I can't remember what it is to look it up. Thanks all. |
Author: | Fogmeister [ Tue Sep 20, 2011 8:36 am ] |
Post subject: | Re: Whats this OO principle called? |
TBH I think I'm just overthinking it. I think I just need to create a class and then subclass it. |
Author: | forquare1 [ Tue Sep 20, 2011 10:25 am ] |
Post subject: | Re: Whats this OO principle called? |
I think the term is polymorphism? ComplexStrategy would subclass BasicStrategy and override certain methods. Methods it didn't override would be called from BasicStrategy. Both classes could be made static so they can't be instantiated, or they could be Abstract. To have a ComplexStrategy instance you would sublass it (adding functionality). If you then called self.sanityCheck(), it would call the one from ComplexStrategy if it existed, if it doesn't exist in ComplexStrategy then it'll be called from BasicStrategy. Even then if you called something like self.isEqual it'll keep going up to NSObject, unless you've overridden it further down the line. I've a feeling there is another way, I'll check later in my book at home. |
Author: | Fogmeister [ Tue Sep 20, 2011 10:38 am ] | |||||||||
Post subject: | Re: Whats this OO principle called? | |||||||||
Cool, thanks! Yes, that's the result I want. What I want to do is put all the subclass objects of BasicStrategy into an array so that I don't care which one it is I know I can run certain methods in them and they will all work. Thanks! |
Author: | forquare1 [ Tue Sep 20, 2011 3:05 pm ] |
Post subject: | Re: Whats this OO principle called? |
Cool ![]() I think polymorphism is my favourite OO word ![]() ![]() |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |