Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet175/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   171   172   173   174   175   176   177   178   ...   288
Bog'liq
GOF Design Patterns

Design Patterns: Elements of Reusable Object-Oriented Software 
259 
All widgets are subclasses of the Widget abstract class.Widget is a subclass of 
HelpHandler, since alluser interface elements can have help associated with them. 
(We couldhave used a mixin-based implementation just as well.) 
class Widget : public HelpHandler { 
protected: 
Widget(Widget* parent, Topic t = NO_HELP_TOPIC); 
private: 
Widget* _parent; 
}; 
Widget::Widget (Widget* w, Topic t) : HelpHandler(w, t) { 
_parent = w; 

In our example, a button is the first handler on the chain. TheButton class is 
a subclass of Widget.The Button constructor takes two parameters: a reference 
toits enclosing widget and the help topic. 
class Button : public Widget { 
public: 
Button(Widget* d, Topic t = NO_HELP_TOPIC); 
virtual void HandleHelp(); 
// Widget operations that Button overrides... 
}; 
Button's version of HandleHelp first tests to see ifthere is a help topic for 
buttons. If the developer hasn't definedone, then the request gets forwarded to 
the successor using theHandleHelp operation in HelpHandler. If there
is
a help 
topic, then the button displays it, and the searchends. 
Button::Button (Widget* h, Topic t) : Widget(h, t) { } 
void Button::HandleHelp () { 
if (HasHelp()) { 
// offer help on the button 
} else { 
HelpHandler::HandleHelp(); 


Dialog implements a similar scheme, except that itssuccessor is not a widget but 
any
help handler. In ourapplication this successor will be an instance of 
Application. 


Design Patterns: Elements of Reusable Object-Oriented Software 
260 
class Dialog : public Widget { 
public: 
Dialog(HelpHandler* h, Topic t = NO_HELP_TOPIC); 
virtual void HandleHelp(); 
// Widget operations that Dialog overrides... 
// ... 
}; 
Dialog::Dialog (HelpHandler* h, Topic t) : Widget(0) { 
SetHandler(h, t); 

void Dialog::HandleHelp () { 
if (HasHelp()) { 
// offer help on the dialog 
} else { 
HelpHandler::HandleHelp(); 


At the end of the chain is an instance of Application. Theapplication is not a 
widget, so Application is subclasseddirectly from HelpHandler.When a help request 
propagates to this level, theapplication can supply information on the application 
in general, orit can offer a list of different help topics: 
class Application : public HelpHandler { 
public: 
Application(Topic t) : HelpHandler(0, t) { } 
virtual void HandleHelp(); 
// application-specific operations... 
}; 
void Application::HandleHelp () { 
// show a list of help topics 

The following code creates and connects these objects. Here thedialog concerns 
printing, and so the objects have printing-relatedtopics assigned. 
const Topic PRINT_TOPIC = 1; 
const Topic PAPER_ORIENTATION_TOPIC = 2; 
const Topic APPLICATION_TOPIC = 3; 
Application* application = new Application(APPLICATION_TOPIC); 



Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   171   172   173   174   175   176   177   178   ...   288




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish