Professional Documents
Culture Documents
Understanding PAC: Part III: Creating Your Application Architecture
Understanding PAC: Part III: Creating Your Application Architecture
Understanding PAC
At its most abstract, a PAC architecture consists of six kinds of classes: three at
the agent scale and three within each agent. Figure 14-1 shows this overall view.
Presentation
Abstraction
Control
Top-level agent
Intermediate-level agents
Figure 14-1:
The overall hierarchy of agents and PAC within
agents.
Bottom-level agents
At the agent scale, the three classes are top-level, bottom-level, and interme diate-level.
Figure 14-2 shows Class-Responsibility-Collaboration (CRC; refer to Chapter 2) cards
for these three agent classes.
The agents in a PAC hierarchy behave like layers in the Layers pattern (see
Chapter 9), in that they communicate only with agents in adjacent layers. If information
needs to flow from an agent of one level to another agent of the same level, it
must flow upward through an intermediate-level agent before returning to
its destination.
_Chapter 14: Layering Interactive Agents with Presentation-
Abstraction-Control
Class
Top-level Agent
Collaborators
• Intermediate level Agent
Responsibilities
• Provide the core functionality of the system
• Control the PAC hierarchy
Collaborators
• Top-level Agent
• Intermediate level Agent
Class
Intermediate-level Agent Responsibilities
• Coordinate lower
level agents
• Compose lower level agents to appear as a single abstraction to higher levels
Class
Bottom-level Agent
Collaborators
• Intermediate level Agent
Responsibilities
• Provide specific views of the software or service, including interaction with users
Figure 14-2:
Agent CRC cards.
Inside all the agents of a PAC architecture are three classes: presentation,
abstraction, and control. Figure 14-3 shows CRC cards for these internal
classes.
212
Part III: Creating Your Application Architecture
Class
Control
Responsibilities
• Provide access to services provided by
this agent
• Coordinate the PAC
hierarchy
• Maintain overall user interaction
Collaborators
• Control classes
in higher-level agents
• Control classes in lower-level agents
• Presentation
class in this agent
• Abstraction class in this agent
Class
Abstraction
Collaborators
• Control class in
this agent
• Presentation
class in this agent
Responsibilities
• Store internal data
used by this agent
Class
Presentation
Collaborators
• Control class in
this agent
• Abstraction class in this agent
Responsibilities
• Provide view of
abstraction to user
• Provide and control user interactions
Figure 14-3: Internal PAC
CRC cards.
Each of these classes inside an agent has the same responsibility relative
to the others. Depending on a class's location in the overall agent
hierarchy, however, the functionality of one or more of these internal
classes is mini mized or emphasized (see Figure 14-4). In the top-level
agent, the abstraction is emphasized because it stores the model data. In
the bottom-level agents, the presentation class is emphasized because it
provides the lowest-level dis play functionality. The intermediate-level agents
can fulfill several roles; as a result, the responsibilities of all three internal
classes may be more balanced.
REAL-WO
TI
T.
AT
INT
Presentation
(Abstraction
Top level
Control
Presentation
Mid level
Abstraction
Control
Figure 14-4:
Relative importance
of PAC classes in
different layers of agents.
Presentation
Bottom level
Abstraction
Control
214
Part III: Creating Your Application Architecture
study. The scientists have been using individual programs to access differ ent data sets
and data displays; now they'd like to transition this collection of programs to a unified
system. When you get this assignment, your goal is to reuse as much as possible of the
existing programs. You and the scientists expect that it will be easier and faster to create
new views of the data if all the existing views and data are combined into a single
program.
Currently, all the individual data programs use their own private data sets.
The scientists have two goals for the new application:
They want to view all their data in one program with a simplified, unified user interface (UI).
They want to combine all their data into one large data set. Currently, each of the
different programs stores its own data, and some overlap has led to data-integrity issues
in the past. The scientists think that if all the data is together and in the same place, they may
see new relation ships between the data sets that have been invisible to them in the past.
You also have a goal: You want the new system to be easier to maintain. Keeping all the
little programs consistent and synchronized is hard.
In addition to reusing the existing programs, you need to add some other objects to the
unified application, including error handling and a new data entry method. Your class
diagram looks like Figure 14-5, in which the old dis play programs are labeled
Program1, Program2, and Program3.
ViewCoordinator
Program1
Figure 14-5:
Different data dis played as
objects in the solution.
Programa |—
Program2
ErrorHandler
ErrorHandler
Data Manager
Program3
Program |
_Chapter 14: Layering Interactive Agents with Presentation-
Abstraction-Control
215
The data from all the different data sets is being combined into one data
repository. You pick a popular open-source database because it seems appropriate and
you want to find out more about it. Regardless of the type of database or file you store
the data in, you create a repository object to access the data and to provide it to the
views.
Because you have this new centralized data repository, you also need to create a
new way to enter the data and to access it directly. You discuss this issue with the
scientists and decide that data entry should be done through a simple spreadsheetlike
interface.
Each of the formerly independent programs needs some modifications that allow it to
access data from the shared repository instead of from its inter nal data store.
These modifications aren't hard, because, for the most part, the individual
programs were written with maintainability in mind, and they isolated the
mechanics of their local data stores from the display functions. By changing
some application programming interfaces (APIs) and writing some Adapter
software, you're able to redirect data access to the centralized repository. (The
Adapter pattern is available in Design Patterns: Elements of Reusable Object-
Oriented Software, by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides
[Addison-Wesley Professional].)
The model component in the MVC architecture pushes changes out to the views.
In the new program, you want the formerly separate pro grams to act more
autonomously and to retrieve data from the reposi tory when they need it. The views
and controllers in MVC are closely related. Many times, these components are
implemented as subviews. When you combine existing systems into a new unified
system, each of the views in the new system was an independent program before,
so it stands alone and doesn't have interfaces to other programs, like the views in a
typical MVC system. Conversion of the separate programs to objects within an MVC
architecture would be hard, and you wouldn't be able to reuse as much of the
existing programs as you'd hoped to.
The following section provides a more general comparison of the MVC and
PAC patterns.
In PAC, the architecture is created with a hierarchy of agents, each contain ing all
three parts of the name: a presentation part, an abstraction part, and a control part.
The most important difference between these two patterns that should lead you to
choose one or the other is that PAC is built around the notion of inde pendent
components cooperating to perform the application, whereas MVC is more about
the flexibility of the human-computer interaction within a single overall component.
Each of the agents in your new program once was a separate, independent
program. As a result, it had its own data abstraction component, in which it structured
the data for which it was responsible; its own view component, which it used to
present the display to the Ul; and its own control part for receiving input from the user.
Figure 146 shows several display components with their subcomponents.
You have to add a high-level agent to control and coordinate all the separate
views that once were separate programs. This agent will provide the main UI that
lets the scientists pick the display they want to see.