1 based on slides by gitit amihud. 2 the person class string firstname string lastname date...

36
1 Based on slides by Gitit Amihud

Post on 21-Dec-2015

230 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

1

Based on slides by Gitit Amihud

Page 2: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

2

The Person class

String firstNameString lastNameDate birthDateAddress home

setFirstName(String)String getFirstName()

setLastName(String)String getLasttName()

.

.

.

We want to add method getPresent(Thing). but we want to enable calling it only on the Person’s birthday.

we want to control the use of this method, depends on the state of the object

Page 3: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

3

The solution:

Page 4: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

4

Characteristics The Principle of message filtering the filter structure Filter elements Filters types The Interface Pseudo variables Examples

Topics:

Page 5: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

5

The Composition Filter model

The composition-filters object model extends the kernel object model.

The extension is at the interface level and includes input and output filters.

The Input filters deal with the messages that are received by the object, whereas output filters deal with the messages that are sent by the object.

Page 6: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

6

methods

InstanceVariables

The extension of the object model

Page 7: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

7

Characteristics of the Composition Filter model

Modular extension - filter can be attached to a class without modifying the definition of that class.

Orthogonal extension – each filter extension to a class is independent from other filter extension. it allows easy composition of multiple filters.

Declarative – A filter specification describes what it means but not how it is implemented.

Page 8: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

8

The Principle of message filtering

Page 9: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

9

The Filter structure

Each filter consists of an ordered set of filter elements.

A filter element consists of three parts:

Condition => {matching part} {substitution part}

Filter name : filter type =

{

Filter elements

{

Page 10: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

10

Filter elementCondition => {matching part} {substitution part}

o Condition - specifies a necessary condition to be fulfilled in order to continue the evaluation of a filter element:

if the condition evaluates to false, usually the filter will reject the message and continue according to the rejection behavior

if the condition evaluates to true the filter proceeds (sometimes it means sending error…).

the default condition is True.

Page 11: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

11

Filter element (cont)

Condition => {matching part} {substitution part}

o the enable operator => – causes the acceptance of every message that matches the matching part.the exclusion operator ~> - causes the acceptance of any message except for the massages that matches the matching part. the default operator is the enable operator

o A matching part - the evaluated message is matched against a pattern consisting of a message selector and a target specification (Target.Selector).the target and the selector can be replaced by wild cardsif there are several patterns, the message is applied to each of them, from left to right, until a match has occurred.

Page 12: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

12

Filter element (cont)

Condition => {matching part} {substitution part}

o A substitution part - specifies replacement values for the target and selector of the message.

If the substitution part is a wild card, the target and selector remain unchanged.

for example:

IsBirthday => *.getPresent *.*

Page 13: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

13

Filter types

Error filter Dispatch filter Substitution filter Send filter Wait filter Meta filter (later)

Page 14: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

14

Filter types (cont)

Error filterUsed for: restriction of class interface. This filter can be

used to implement pre conditions and view partitioning. Used in: Input/Output filter set.Accept handler: The accepted message proceeds to the next filter.Reject handler: The rejected message is regarded as illegal and the

program raises an exception stating where the exception occurred.

parameters: none.When the condition holds, accept only messages in the list when condition is not true, proceed, otherwise accept only matchingfor example:

select: Error = { IsBirthday =>[*.getPresent] *.*} “On birthday, accept only getPresent”

Page 15: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

15

Filter types (cont)

Dispatch filterUsed for: initiation of a message execution. The dispatch filter

introduces ‘inheritance’ by delegation. Used in: input filter set.Accept handler: The accepted message is delegated to the target

object, or executed if target object is inner. Reject handler: The rejected message continues to the next filter.Parameters: none.

for example: disp: Dispatch = {True => inner.*, someclass.* };

Page 16: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

16

Filter types (cont)

substitution filterUsed for: substitution of the target, selector or target and selector

of the message.

Used in: Input/Output filter set.

Accept handler: The accepted message is substituted by the target and selector specified in the parameter (substitution)

part.

Reject handler: The rejected message continues to the next filter.

Parameters: the new target and/or selector.

Page 17: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

17

Filter types (cont)

Send filterUsed for: initiation of a message delegation.

Used in: Output filter set.

Accept handler: The accepted message is passed to another object outside the sending object.

Reject handler: The rejected message continues to the next filter.

Parameters: none.

Page 18: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

18

Filter types (cont)

Wait filterUsed for: concurrency control and synchronization.

Used in: Input/Output filter set.

Accept handler: The accepted message continues to the next filter.

Reject handler: The rejected message is blocked until one or more conditions are satisfied. The message is then re-evaluated by the wait filter.

Parameters: none.

Page 19: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

19

The interface

Class Example interface

Internals

Externals

Conditions

Methods

Input filters

Output filters

End;

Page 20: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

20

The interface (cont)Internals

Fully encapsulated objects, used to compose the behavior of the cf object.they are created when their encapsulating object is created.

Externalsobjects that exist outside the composition filter object, such as global objects.since they lay outside the object in which they are declared, they have to be passed to the cf object when it is created.

Conditionstypically represent an object’s state, used in a filter to test whether a message should be accepted or rejected.condition are methods without parameters, return boolean and should be free of side effects.

Page 21: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

21

The interface (cont)

Methodsthe name of the methods that are available to other objects (visible on the interface).

Input filtersfilters for inspecting and manipulating incoming messages.

Output filtersfilters for inspecting and manipulating outgoing messages.

Page 22: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

22

Composition Filter model

Page 23: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

23

The Person class

class Person interface/* no internals *//* no externals */conditions

isBirthday;isLocal;

methodsgetFullName(Boolean) returns StringgetPresent(Thing) returns Nil

inputfiltersselect: Error = { True => [*. getFullName]*.*, IsBirthday

=>[*.getPresent]*.*},

disp: Dispatch = {inner.* };/* no outputfilters */

end;

Page 24: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

24

Filter specification of class USViewMail

class USViewMail interfaceinternals

mail: Email;/* no externals */conditions

userView;systemView;

methods… … …inputfilters

multipleViews: Error = { userView => {putOriginator, putReceiver, putContent, getContent, send, reply},

systemView => {approve, putRoute, deliver}, True => {getOriginator, getReceiver,

isApproved, getRoute, isDelivered}

} ;invoke: Dispatch = { True=> inner.*, mail.* };

/* no outputfilters */end;

Page 25: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

25

Pseudo variables

Sender Server Self Inner Message

Page 26: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

26

Sender

the object that was responsible for sending the current executed message.

Server

the original receiver of the message that caused the current execution.

Self

the object that executes the current method.

Pseudo variables (cont)

Page 27: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

27

Inner

the kernel, implementation part of the current object.

Message

the message that caused the current execution.

Pseudo variables (cont)

Page 28: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

28

Page 29: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

29

Pseudo variables (cont)

1-sender2-server

3-self4-inner

5-message

Page 30: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

30

class Secretary interface internals

work : Employee; private : Spouse;

conditions WorkHours; OffTime ;

methods schedule(Appointment) returns Boolean;

Inputfilters dynInh : Dispatch = {WorkHours=>inner.*, OffTime=>private.*,

WorkHours=>work.*}; end

Dynamic inheritance Designate a mechanism that allows for enabling and disabling an inheritance

relation with a superclass at runtime

Page 31: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

31

Multiple viewsclass Clerk interface

internalsempl : Employee;

externalsadministrator : Secretary;

conditionsSentByManager begin return sender.isSubTypeOf(Manager); end;SentBySecretary begin return sender=administrator; end;

methodsgetWorkingHours returns WorkingHourssetWorkingHours(WorkingHours) returns Nil

inputfiltersselect : Error = { SentByManager=>putTask,

{SentByManager, SentBySecretary}=>getWorkingHours,True~>{putTask, getWorkingHours} };

delegate : Dispatch = { inner.*, empl.*, administrator.schedule };end

Page 32: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

32

Filter types: Meta filter

Meta filterUsed for: reflection on object interactions.

Used in: Input/Output filter set.

Accept handler: The accepted message is reified (converted to an instance of class Message and then passed as an argument ) and delegated to a meta object.

Reject handler: The rejected message continues to the next filter.

Parameters: the target meta object and the selector of the function to be called.

Page 33: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

33

class LoggedClerk interfaceinternals

clerk : Clerk; // inherit from clerkexternals

bigBrother : LogACT; // this declares an external ACT objectinputfilters

reifyIn : Meta = { [*.*]bigBrother.logMessage }; // reify and send message to the ACTinherit : Dispatch = { clerk.* };

outputfiltersreifyOut : Meta = { [*.*]bigBrother.logMessage }; // reify

and send message to the ACTend

Filter types: Meta filter (cont)

Page 34: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

34

class LogACT interface

comment "this class logs all the received meta-messages, and fires them again" ;

methods

logMessage(Message) returns Nil;

Inputfilters

disp : Dispatch = {inner.* };

end;

Filter types: Meta filter (cont)

Page 35: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

35

Filter types: Meta filter (cont)

class LogACT implementationinstvars

log : OrderedCollection;methods

logMessage(mess : Message) returns Nilbegin

log.addLast(mess);mess.fire;

end;end; // class LogACT implementation

Page 36: 1 Based on slides by Gitit Amihud. 2 The Person class String firstName String lastName Date birthDate Address home setFirstName(String) String getFirstName()

36

Lodewijk Bergmans, The composition Filters object model

Lodewijk Bergmans & Mehmet Aksit .Composing multiple concerns using Composition Filters

Mehmet Aksit & Bedir Tekinerdogan. Solving the modeling problems of object-oriented languages by composing multiple aspects using Composition Filters.