0% found this document useful (0 votes)
36 views7 pages

Abstract Factory Gof Object Creational

This document discusses how the Abstract Factory and Command patterns are used in an expression tree processing application. The Abstract Factory contains Factory Methods that create different Command objects, which dictate how users can interact with the application. This allows new operations to be added by defining new factory methods and command classes, improving extensibility.

Uploaded by

Hello
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views7 pages

Abstract Factory Gof Object Creational

This document discusses how the Abstract Factory and Command patterns are used in an expression tree processing application. The Abstract Factory contains Factory Methods that create different Command objects, which dictate how users can interact with the application. This allows new operations to be added by defining new factory methods and command classes, improving extensibility.

Uploaded by

Hello
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

GoF Patterns Expression Tree Case Study Douglas C.

Schmidt

Abstract Factory GoF Object Creational


Intent
• Create families of related objects without specifying subclass names
Applicability
• When clients cannot anticipate groups of classes to instantiate
Structure
e.g., ET_Command
_Impl
e.g., ET_Command
_Factory_Impl

e.g., Eval_Command, Print_


Command, Macro_Command, etc.

e.g., Concrete_ET_
Command_Factory_Impl
1
GoF Patterns Expression Tree Case Study Douglas C. Schmidt

Abstract Factory GoF Object Creational


Abstract Factory example in C++
• Create families of related objects without specifying subclass names
class Concrete_ET_Command_Factory_Impl
: public ET_Command_Factory_Impl {
public:
Concrete_ET_Command_Factory_Impl() {
command_map_["format"] = &make_format_command;
command_map_["expr"] = &make_expr_command;
command_map_["eval"] = &make_eval_command;
... std::map associating command names to pointer-
to-member-function command factories

2
GoF Patterns Expression Tree Case Study Douglas C. Schmidt

Abstract Factory GoF Object Creational


Abstract Factory example in C++
• Create families of related objects without specifying subclass names
class Concrete_ET_Command_Factory_Impl
: public ET_Command_Factory_Impl {
public:
Concrete_ET_Command_Factory_Impl() {
command_map_["format"] = &make_format_command;
command_map_["expr"] = &make_expr_command;
command_map_["eval"] = &make_eval_command;
... The primary factory method that creates the
designated command based on user input
virtual ET_Command make_command(const std::string &input) {
auto iter = command_map_.find(command_name(input));
if (iter != command_map_.end()) {
auto ptmf = iter->second;
return (this->*ptmf)(command_parameter(input));
}
... Dispatch command
3 factory method via returned via map
GoF Patterns Expression Tree Case Study Douglas C. Schmidt

Abstract Factory GoF Object Creational


Consequences
+ Flexibility: Removes type (i.e., subclass)
dependencies from clients
+ Abstraction & semantic checking:
Encapsulates product’s composition
– Complexity: Tedious to extend factory
interface to create new products

4
GoF Patterns Expression Tree Case Study Douglas C. Schmidt

Abstract Factory GoF Object Creational


Consequences
+ Flexibility: Removes type (i.e., subclass)
dependencies from clients
+ Abstraction & semantic checking:
Encapsulates product’s composition
– Complexity: Tedious to extend factory
interface to create new products
Implementation
• Parameterization as a way of controlling
interface size
• Configuration with prototypes to determine
who creates the factories
• Abstract factories are essentially groups of
factory methods

5
GoF Patterns Expression Tree Case Study Douglas C. Schmidt

Abstract Factory GoF Object Creational


Consequences Known Uses
+ Flexibility: Removes type (i.e., subclass) • InterViews Kits
dependencies from clients • ET++ WindowSystem
+ Abstraction & semantic checking: • AWT Toolkit
Encapsulates product’s composition
• The ACE ORB (TAO)
– Complexity: Tedious to extend factory
interface to create new products
Implementation
• Parameterization as a way of controlling
interface size
• Configuration with prototypes to determine
who creates the factories
• Abstract factories are essentially groups of
factory methods

6
GoF Patterns Expression Tree Case Study Douglas C. Schmidt

Summary of Command & Factory Patterns


Abstract Factory contains Factory Methods that create Command objects,
which then dictate how users interact with an expression tree processing app

Abstract Factory &


ET_Event_Handler ET_Command_Factory ET_Command_Factory_Impl Factory Method

<< create >> Concrete_ET_Command_Factory_Impl ET_Context

* ET_Command ET_Command_Impl
Command

1
Macro_Command Print_Command Set_Command Quit_Command Null_Command

Format_Command Expr_Command Eval_Command

These patterns enable extensibility of


7 operations via new factory methods

You might also like