Difference between revisions of "OOP Reassigned"
(New page: Category:OOP Duck Study ==Problems with inheritance== The super class Duck has a swim method. Duck.swim() Any class that subclasses the duck class will inherit the swim() method. ...) |
|||
Line 1: | Line 1: | ||
− | [[Category: | + | [[Category:Object Oriented Programming]] |
Duck Study | Duck Study |
Revision as of 21:08, 4 August 2008
Duck Study
Problems with inheritance
The super class Duck has a swim method.
Duck.swim()
Any class that subclasses the duck class will inherit the swim() method. So far so good all ducks swim
The super class also has a fly() method sa all classes that inherit from duck will get the fly() method.
All ducks don't fly...
Controls is an example of good inhertance
http://iam.colum.edu/oop/classsource/class11/controls.aspx
see
Hierarchy
Object ---> Control---> WebControl---> BaseDataBoundControl ---> DataBoundControl --->ListControl ---> DropDownList
Strategy Pattern
http://www.dofactory.com/Patterns/PatternStrategy.aspx
Strategy Pattern
- Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
Ducks From Book
http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class11/Duck
http://www.dofactory.com/Patterns/PatternStrategy.aspx
Pretty good example of the strategey method in action.
Homework
Create Characters class and weapons class that uses the strategy pattern