lecture11 - DesignPatterns page293...

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 A Case Study and the Observer Pattern Design Patterns  page 293
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 patterns do we have so far? Visitor Pattern Allows a visitor object to be  passed to every item in a  collection. The item can then  call functions on the visitor  object with a concrete class. Iterator Pattern Allows a client to safely visit  every node in a collection.
Background image of page 2
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 3 Patterns so far Composite Pattern Allows us to build structures  from parts. We have  collections of objects that can,  in turn, have collections of  objects.
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 Important UML Notations Nested Class Used for Iterators Aggregation “Part of” relationships Composition “Owned by” relationships
Background image of page 4
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 5 The Drawing Application I’m going to use this  application as a case  study for: Iterator Pattern Composite Pattern Visitor Pattern Observer Pattern  (new)
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 UML for just  the data Notice: No  Draw in  Drawable… How can we  draw?
Background image of page 6
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 7 A Visitor for Drawables void CVisitorDrawable::VisitGroup(CGroup  *group) {     VisitDefault(group); } void CVisitorDrawable::VisitPicture(CPicture  *picture) {     VisitDefault(picture); } class CGroup; class CPicture; class CDrawable; class CVisitorDrawable { public:      virtual ~CVisitorDrawable();      virtual void VisitDefault(CDrawable *)  {}      virtual void VisitGroup(CGroup  *group);      virtual void VisitPicture(CPicture  *picture); protected:      CVisitorDrawable(); };
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 A Visitor for Drawing #include "CVisitorDrawable.h" class CVisitorDraw: public  CVisitorDrawable { public:      CVisitorDraw(wxDC *dc);      virtual ~CVisitorDraw();      virtual void VisitPicture(CPicture  *picture); private:     wxDC *mDC;      // Pointer to device  context }; void CVisitorDraw::VisitPicture(CPicture  *picture) {     picture->Draw(mDC); }
Background image of page 8
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 9 Discussion… Would I normally choose to use a visitor to draw?  Not  really. This was more an exercise to demonstrate the use  of visitors in a particular example. Some of the other things I used visitors for were much 
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.

Page1 / 49

lecture11 - DesignPatterns page293...

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