{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture21 - MediatorPatternand ImprovedModularity...

Info icon This preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 1 Mediator Pattern and  Improved Modularity Reading: GoF page  273 FruitCo application available on class web site.
Image of page 1

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

View Full Document Right Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 2 FruitCo Drag fruit to juice,  basket, or trash. Click on fruit in  basket or trash to  return to picker. Overfilling is  rejected by  returning fruit to  picker. Menu options: Restock a fruit. AutoSort a picker. 3
Image of page 2
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 3 First the Easy Stuff A fruit knows its type (apple  or orange), grade (good,  med, bad), and a bitmap to  draw. The factory creates a fruit.  The derived classes just load  the correct images and set  the type.
Image of page 3

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

View Full Document Right Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 4 Factory example code CFruit * CFruitFactory::Create(FruitGrades  grade) {     CFruit *fruit =  new CFruit;     fruit->mImage = mImages[grade];     fruit->mBitmap = fruit->mImage;     fruit->mType = mType;     fruit->mGrade = grade;     fruit->mPosition = wxPoint(0, 0);      return fruit; } CAppleFactory::CAppleFactory() {     mType =  Apple;     LoadImage( Good, L"image/apple- spartan.png");     LoadImage( Med, L"image/apple.png");     LoadImage( Bad, L"image/apple-worm.png"); }
Image of page 4
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 5 FruitCo major  classes What are the associations? I have omitted Frame  and the base classes  wxWindow,  wxFrame, and  wxTextCtrl
Image of page 5

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

View Full Document Right Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 6 Some are obvious So I’ll ignore those for now…
Image of page 6
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 7 These are the  classes I really  care about 4
Image of page 7

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

View Full Document Right Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 8 Associations needed here (a) (b) (c) (d) (e) (f) What if I added:  FruitBottle can  reject bad fruit directly to the trash? 5
Image of page 8
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 9 Problems With This  Approach Too many things  depend on each other. Where do you put that  AutoSort algorithm? Increased connectivity =  increased complexity. Components are not  reusable for other  purposes. Hard to debug. Welcome to the  Object-Oriented  equivalent of  spaghetti code !
Image of page 9

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

View Full Document Right Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 10 Excessive Connections Is there a better choice than this? Distributed Control is often the best  choice, but can lead to too many  connections!
Image of page 10
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 11 A Mediator Suppose we put one person (object) in charge?   Everyone talks to that person, not to each other!
Image of page 11

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

View Full Document Right Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 12 A Mediator Suppose we put one person (object) in charge?   Everyone talks to that person, not to each other!
Image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '10
  • OWEN
  • Dr. Charles B. Owen, Charles B. Owen, B. Owen Object­Oriented, Owen Object­Oriented Programming, Dr. Charles B.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern