lecture6 - PatternsandtheVisitorPattern Somebodyhasalready...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 1 Patterns and the Visitor Pattern “Somebody has already  solved your problem” Page 331
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 2 What makes a great chess player? They are  not  memorizing  the board and playing back  a game, they are  recognizing arrangements of  pieces that call for a specific  strategy.
Background image of page 2
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 3 What is a Design Pattern? It is: A pattern for how  objects and methods can  be laid out to solve a  problem. Not: A class library Not: Standard  superclasses
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 4 How they happened Ever feel déjà vu when programming? Many people do. So, they started  looking at good programs and seeing  what patterns or structures were  occurring a lot. They started to write  them down and give them a name. Now you can avoid a big description  and just say “I used the observer  pattern”.
Background image of page 4
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 5 Do you know what these are? Inheritance Polymorphism Encapsulation Abstraction 3
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 6 The Big 4 of Object-oriented Programming Inheritance The ability to form new classes that extend the  capabilities of existing classes Polymorphism The ability of one type to appear to be and be used as  another type Encapsulation Separating an interface from an implementation,  hiding details that may change Abstraction Reducing or factoring out details so we can focus on  concepts – objects are abstractions
Background image of page 6
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 7 But, More Flexibility/Extendibility It should be easy to add capability. We should not have to always modify our core classes  to add a capability. Maintainability We like to avoid spreading code all over the project to  do a specific task.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 8 Remember This? Add a menu option called " Count the  male animals ". A bull is a male cow. A  boar is a male pig. Assume all  chickens are females How did you implement this?
Background image of page 8
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 9 How you likely implemented this class CAnimal { public:     CAnimal();     virtual ~CAnimal();     virtual void DisplayAnimal() {}     virtual bool IsMale() const {return false;} }; bool CPig::IsMale() const  {     return mType == Boar; } bool CCow::IsMale() const {     return mType == Bull; } int CFarm::NumberOfMaleAnimals() const {     int cnt = 0;     for(list<CAnimal *>::const_iterator i=mInventory.begin();              i != mInventory.end();  i++)
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/12/2010 for the course CSE CSE 335 taught by Professor Owen during the Fall '10 term at Michigan State University.

Page1 / 44

lecture6 - PatternsandtheVisitorPattern Somebodyhasalready...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online