Software Architecture Bertrand Meyer & Till Bay
ETH Zurich, February-May 2008
Lecture 10: Flyweight, Composite, Iterator Program overview Date - - PowerPoint PPT Presentation
Software Architecture Bertrand Meyer & Till Bay ETH Zurich, February-May 2008 Lecture 10: Flyweight, Composite, Iterator Program overview Date Topic Who? last week Introduction; A Basic Architecture Example Till 26. Feb. Modularity
ETH Zurich, February-May 2008
Date Topic Who? last week Introduction; A Basic Architecture Example
Till
Modularity and reusability; Abstract Data Types
Till
Project description and Delta Debugging
Jason, Andy
Patterns 1: observer + event library, componentization
Till
Design by Contract
No course :-)
Patterns 2: visitor, strategy, state, chain of responsibility
Till
Patterns 3: factory, builder, singleton
Till
Patterns 4: bridge, composite, decorator, facade
Michela
Today
Patterns 5: Wrap up
Till
Language constructs for mod. and info. hiding
Bertrand
Date Topic Who?
Exception handling
Martin
Concurrent programming
Jason
Project presentation
Everybody
Exam
Everybody
Date Topic
Abstract Data Types
Design by Contract
Exception Handling Rest Project
comerge AG
during object creation.
repository of objects.
comerge inc.
class FLYWEIGHT_FACTORY feature -- Factory make_new_flyweight (a: SOME_ARG): FLYWEIGHT is
do if flyweight_pool.has_index (a) then Result := flyweight_pool.item (a) else create Result.make (a) flyweight_pool.extend (Result, a) end end flyweight_pool: HASH_TABLE [FLYWEIGHT,SOME_ARG] is once ... end end
5
comerge AG
semantics
equality (is_equal, ~)
comerge AG
where you would have used flyweight for Java or .NET
following:
comerge AG
comerge AG
recursive data structure
comerge inc.
10
comerge inc.
11
LEAF * NODE NON_LEAF sub_node: NODE
comerge inc.
deferred class EXPRESSION end
12
comerge inc.
class INTEGER_EXPRESSION inherit EXPRESSION feature -- Access value: INTEGER
end
13
comerge inc.
class ADDITION_EXPRESSION inherit EXPRESSION feature -- Access left: EXPRESSION
right: EXPRESSION
invariant left_not_void: left /= Void right_not_void: right /= Void end
14
comerge inc.
class MULTIPLICATION_EXPRESSION inherit EXPRESSION feature -- Access left: EXPRESSION
right: EXPRESSION
invariant left_not_void: left /= Void right_not_void: right /= Void end
15
comerge inc.
16
(recursively) built from parts.
nodes.
using visitors (next pattern).
comerge inc.
aggregate object sequentially without exposing its underlying representation.”
17
comerge inc.
deferred class LINEAR [G] feature -- Access item: G is
require not_off: not off deferred end feature -- Cursor movement forth is
require not_off: not off deferred end feature -- Status
end
18
NOT like Java: hasNext() next()
comerge inc.
19
comerge AG
LINKED_LIST [G] LINKABLE [G] LINKABLE [G] LINKABLE [G] right cursor_position first right class LINKED_LIST [G] inherit LINEAR [G]
comerge AG
LINKED_LIST [G] LINKABLE [G] LINKABLE [G] LINKABLE [G] right cursor_position first right LINKED_LIST_ CURSOR [G]
comerge AG
LINKED_LIST [G] LINKABLE [G] LINKABLE [G] LINKABLE [G] right cursor_position first right LINKED_LIST_ CURSOR [G] iterators
comerge inc.
feature -- Iterators do_all (c: PROCEDURE [ANY, TUPLE [G]])
for_all (q: FUNCTION [ANY, TUPLE [G], BOOLEAN]): BOOLEAN
there_exists (q: FUNCTION [ANY, TUPLE [G], BOOLEAN]): BOOLEAN
23
comerge AG
+ easy to track and contract
+ independent operations, less side-effects
+ No dead nodes, well-defined behavior
+ powerful, very expressive, safe