lecture21 - MediatorPatternand ImprovedModularity...

Info iconThis 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.
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 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
Background 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.
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 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"); }
Background 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
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 Some are obvious So I’ll ignore those for now…
Background image of page 6
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 7 These are the  classes I really  care about 4
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 Associations needed here (a) (b) (c) (d) (e) (f) What if I added:  FruitBottle can  reject bad fruit directly to the trash? 5
Background 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 !
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 Excessive Connections Is there a better choice than this? Distributed Control is often the best  choice, but can lead to too many  connections!
Background 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!
Background image of page 11

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

View Full DocumentRight Arrow Icon
Object-Oriented Programming 12 A Mediator Suppose we put one person (object) in charge?   Everyone talks to that person, not to each other! Mediator
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 34

lecture21 - MediatorPatternand ImprovedModularity...

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

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