49
ph Johnson - University of Illinois Reflection and the Adaptive Object Model Architecture Ralph Johnson University of Illinois at Urbana- Champaign [email protected] 217-244-0093 http://st-www.cs.uiuc.edu/users/ johnson

Reflection and the Adaptive Object Model Architecture

  • Upload
    shelly

  • View
    29

  • Download
    0

Embed Size (px)

DESCRIPTION

Reflection and the Adaptive Object Model Architecture. Ralph Johnson University of Illinois at Urbana-Champaign [email protected] 217-244-0093 http://st-www.cs.uiuc.edu/users/johnson. Reflection. Is hard Is important - PowerPoint PPT Presentation

Citation preview

Page 1: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 1

Reflection and the Adaptive Object Model

ArchitectureRalph Johnson

University of Illinois at Urbana-Champaign

[email protected]

217-244-0093

http://st-www.cs.uiuc.edu/users/johnson

Page 2: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 2

Reflection

Is hard Is important

The ability of a program to reason about and change its own implementation.

Page 3: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 3

Reflection

Base level (the application)

Meta level (the virtual machine)

Paycheck

Printer Report

Module

Employee

Class Method

Page 4: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 4

Patterns and Architecture

Problem with Pattern-Oriented Software Architecture is that the “architectural patterns” are really pattern languages, not patterns.

Page 5: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 5

Kinds of Architectures

Client-serverPurpose: access shared data, distribute

computation

Result: bottlenecks usually database or network, not CPU

Page 6: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 6

Kinds of Architectures

Layered systemPurpose:

reuse lower layers

limit effects of change

make system easier to understand

Result:can be inefficient

fix bottlenecks by “punching hole” thru layers

Page 7: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 7

Adaptive Object Model

Pattern of business software Used to model information Valuable where information structure is

complex and changes rapidly Can be inefficient and hard to

understand

Page 8: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 8

Adaptive Object Model

Made up of design patterns» Composite, Strategy, Interpreter» Type Object» Properties

Examples:» Rating insurance policies» Rating telephone calls» Maintaining database

Page 9: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 9

Type Object

Problem: Have to subclass, and subclasses require code. Want to customize system without programming.

Solution: » For each kind of object, make two classes,

an Instance and a Type.» Try not to make a subclass - make a new

object of the Type.

Page 10: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 10

Examples

Airline scheduling system» airplane and airplane type

Medical information system» observation and observation type

Manufacturing» item and item type

Page 11: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 11

Type Object

“type” describes what a group of objects have in common

often “type” creates “instances” often used with Strategy, Interpreter, and

Property

Instance Typenamevalues

namestrategiesproperties

type

Page 12: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 12

Insurance Policies

Instead of using multiple inheritance to model policies, model a policy as a tree of components. House

address, value,size, style

Houseaddress, value,size, style

Liabilitylimit, deductable

Liabilitylimit, deductable

Carvalue, mileage, age, drivers

Carvalue, mileage, age, drivers

Policyowner, address

Policyowner, address

Firelimit, deductable

Firelimit, deductable

Liabilitylimit, deductable

Liabilitylimit, deductable

Collisionlimit, deductable

Collisionlimit, deductable

Page 13: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 13

Component Class Hierarchy

One solution is to make a class for each kind of component.

PolicyComponent

Car House HouseFire HouseLiability

CarFire CarLiability

Policy

Page 14: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 14

Component Characteristics

Insurance policies have only a few operations» Edit - create new policy or change old one» Rate - compute amount to charge for policy» Print - convert into paper

Different components have different attributes

Page 15: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 15

Eliminating Subclasses

Policy made up of Components and ComponentTypes.

Each ComponentType defines a set of Strategies (to represent operations)

Component has a set of Properties (to represent attributes).

One Component class and one ComponentType class.

Page 16: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 16

Property

Problem: object has arbitrary or huge number of attributes

Solution: represent attributes with a dictionary

Subject Propertynamevalue

properties

Page 17: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 17

Composite Type Object with Properties and

Strategies

Component ComponentTypename

Propertyvalue

PropertyTypenametype

Strategytype

type

properties

children

Page 18: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 18

Composite Type Object with Properties and

Strategies

ComponentComponent

StrategyStrategy

Propertyvalue = ‘1 Main Street,Big City’

Propertyvalue = ‘1 Main Street,Big City’

PropertyTypename =‘address’

PropertyTypename =‘address’

ComponentTypename =‘House’

ComponentTypename =‘House’

PropertyTypename =‘owner’

PropertyTypename =‘owner’

Propertyvalue =‘John Doe’

Propertyvalue =‘John Doe’

Auto

ComponentTypename =‘Policy’

ComponentTypename =‘Policy’

ComponentComponent

Page 19: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 19

Problem: Strategy leads to a big class hierarchy, one class for each kind of policy.

Solution: Make Composite Strategies.

=> Interpreter pattern

Page 20: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 20

Interpreter Pattern

Problem: Need a small language

Solution:» Make class hierarchy that models the

grammar» Each class defines a value() function with

the context as the argument» Program is a tree of objects

Page 21: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 21

Small Language for Insurance

Attributes - value() function for an Attribute Type will return value of an attribute with that type in the context.

Arithmetic expressions (+,-,*,/) Table lookup Assignment to attribute

Page 22: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 22

Component ComponentTypename

Propertyvalue

PropertyTypenametype

Ruletype

childrenproperties

Table

Expression

type

children

Type Object

Composite

Strategy

Interpreter

Property

Composite Type Object

Page 23: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 23

Products

A product is a type of policy. Framework makes it easy to create new

kind of product. Framework makes composite types. Instance vs. type Operational vs. knowlege

Page 24: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 24

Editing a Policy

One editor can edit any policy. Policy is a sequence of components. Policy editor is a sequence of component

editors. Component editor has a field for each

attribute in the component.» Number field» date field

Page 25: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 25

Creating New Component

ComponentTypename =‘Liability’

ComponentTypename =‘Liability’

ComponentComponent

ComponentComponent

ComponentTypename =‘Policy’

ComponentTypename =‘Policy’

ComponentComponent

ComponentComponent ComponentTypename =‘House’

ComponentTypename =‘House’

ComponentTypename =‘Auto’

ComponentTypename =‘Auto’

ComponentTypename =‘Liability’

ComponentTypename =‘Liability’

Page 26: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 26

Creating New Component

When editing component of type T, you can create a component of any type that is a child of T.

Types act like a grammar, while components are an abstract syntax tree

Page 27: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 27

Advantages of AOM

Automate user interface Automate database interface Enable users to extend system Automate other aspects of system

» History» Workflow

Page 28: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 28

Insurance Framework Summary

Policy is a tree of components Component type is a composite object System has tools for editing policies,

and tools for editing component types Domain specific object model is in the

database, not the CASE tool.

Page 29: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 29

Adaptive Object Model

Many systems store object model in a database and interpret it» results in user extensible systems» flexible, easy to maintain» kernel is small, abstract, complex» performance is an issue

Page 30: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 30

AOM and Reflection

Similarities» Base level and meta level» Developers have to know both levels

Differences» Base level doesn’t necessarily invoke meta

level» No “reflective tower”

Page 31: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 31

Telecommunications Billing

Database » customers» charges» network events (call, directory assistance,

voice-mail)» billing plans» bills

Page 32: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 32

Telecommunications Billing

Rating - converting network events into charges to customer

Billing - computing discounts, finance charges, etc - printing bills

Page 33: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 33

Rating

Many kind of network events Billing policy determines how to rate

network events Billing policies continually changing Network event has a set of properties

Page 34: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 34

Rating

AccountAccount Billing PolicyBilling Policy

BusinessEventname = ‘information’

BusinessEventname = ‘information’

BusinessEventname = ‘phone call’

BusinessEventname = ‘phone call’

Chargevalue = ‘roaming * .25’

Chargevalue = ‘roaming * .25’

Chargevalue = ‘air time * .05’

Chargevalue = ‘air time * .05’

Propertyname = ‘caller’value = ‘217-345-1111’

Propertyname = ‘caller’value = ‘217-345-1111’

Network Eventname = ‘phone call’

Network Eventname = ‘phone call’

Propertyname = ‘air time’value = ‘25’

Propertyname = ‘air time’value = ‘25’

Page 35: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 35

Rating Algorithm

Given a Network Event, find the Account, then the Billing Policy.

Find the Business Event with the same name as the Network Event.

Compute the total of the Charges for the Business Event by evaluating them in the context of the Business Event.

Page 36: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 36

NetworkEvent

Typename

Propertynamevalue NetworkEventType

BusinessEvent BusinessEventType

Charge

+ * PropertyRef

EntityProperties

type

Interpreter

Type Object

Page 37: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 37

Similarities Between Systems

Automate GUIs Automate database access Provide full history on all objects Provide GUIs for editing types and rules. Planned for customers to edit types, but

they don’t.

Page 38: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 38

Differences Between Systems

Phone billing system makes lots of subclasses of Entity and Type

Phone billing system has more complex algorithms

Insurance system has more powerful rules

Page 39: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 39

Global Data

Database for factory locations, product types, accounting codes, conversion rates, etc.

Originally 10 tables, now 100. Keeps complete history of data Global Data Division in charge of

schemas and data editing programs, their users are in charge of the data.

Page 40: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 40

D ata EditingD ata access

Page 41: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 41

History

Effective date - data at which record is valid

Obsolete date - date at which record is invalid

Record is never deleted, its obsolete date is just set to yesterday.

Referential integrity

Page 42: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 42

Global Data Editor

WindowDescription

Tablename

Attributenametype

Widgetvalue

RecordValidator

Window

Properties

Type Object

Record

Fieldnamevalue

Type Object

FieldValidator

WidgetDescription

Type Object

Type Object

Strategy

Page 43: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 43

Result

Instead of 200 COBOL programs, there are two Java programs (client and server)

We use XML for metadata (window specs and table specs)

Generate documentation from XML Programs make type objects from XML New validation rules are in Java

Page 44: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 44

Adaptive Object Models

It is common to see combinations of Type Object, Composite, Property, Strategy, and Interpreter.

Object model stored in the database. Editors / database interface driven by

object model. Enables system to be customized easily.

Page 45: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 45

Disadvantages of AOM

Abstract - can be hard to learn An interpreter - can be slow A language - are you ready to write a

debugger, a test harness, a configuration control system, documentation aids, etc?

Page 46: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 46

The Poetry of the Language

“It is possible to put patterns together in such a way that many many patterns overlap in the same physical space: the building is very dense; it has many meanings captured in a small space; and through this density, it becomes profound.”

Christopher Alexander

“A Pattern Language”

Page 47: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 47

Summary

Interesting applications use many patterns

Many interesting patterns are not in Design Patterns

Particular combinations of patterns are architectures, and interesting in their own right.

Page 48: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 48

Summary

Document architectures Patterns are a good model for

documentation» architecture is a pattern?» architecture is a set of patterns?» architecture is an application of a set of

patterns?

Page 49: Reflection and the Adaptive Object Model Architecture

Ralph Johnson - University of Illinois 49

For more information on adaptive object models and other architectures for business software, see

http://st-www.cs.uiuc.edu/users/johnson

/bus-obj.html