lecture13 - InterfacesandAdapters Itsoftenusefultohavea

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

View Full Document Right Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 1 Interfaces and Adapters Things don’t always come to  you in a form that fits right into  your design.  It’s often useful to have a  simple way to define how we  interface with something GoF Book: Page 139
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 But first… class WXDLLIMPEXP_CORE wxBitmap: public wxBitmapBase { public:     wxBitmap() { }     wxBitmap( int width, int height, int depth = -1 );     wxBitmap( const char bits[], int width, int height, int depth = 1 );     wxBitmap( const char* const* bits );     //…
Background image of page 2
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 3 Two problems you’ll run into a lot… Someone needs to use  something you wrote in their  design. You need to use something  someone else wrote in your  design. Who’s responsible for  making things work  together?
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 Two problems you’ll run into a lot… Someone needs to use  something you wrote in their  design. You need to use something  someone else wrote in your  design. Murphy’s law of  code reuse: It’s  gonna be your  problem!
Background image of page 4
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 5 You wrote this wonderful information tree  browser You can add items to the  tree, select them, and  expand levels of the tree What might the interface  look like for this?
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 Your solution To add something at the top level:   CTreeBrowser::Item item = tree.AddItem(NULL, “Top level item”,  topicon); To add a child of that item: tree.AddItem(item, “Second level item”, secondlevelicon); Simple, concise, works  well in your application.
Background image of page 6
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 7 Your boss wants it  for his project Conflicting requirements: They don’t want to use (or see) your interface at  all. They have their own interface they want to use. You need to continue using the code in your  programs. What are you going to do?
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 Two possible interfaces Yours What our boss wants
Background image of page 8
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 9 One Option: An Interface Interface class  is a class with only pure virtual  functions. We can inherit from our  interface, create our object, and  pass the interface to our bosses  program.
Background image of page 9

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 10 An Interface Class example class ITreeInterface { public:      void Draw(wxDC *dc) = 0;      = 0;      void Indent() = 0;
Background image of page 10
Image of page 11
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 / 35

lecture13 - InterfacesandAdapters Itsoftenusefultohavea

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

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