Title: Software Development Using Proper Separation of Concerns: Talk only to your friends who share your concerns (Law of Demeter for Concerns)
1Software Development UsingProper Separation of
ConcernsTalk only to your friends who share
your concerns(Law of Demeter for Concerns)
2General
- Many interpretations for talk and friends.
- LOD Only talk to your friends
- LoDC Only talk to your friends who share your
concerns - LoDC implies LoD
- LoD a module should not know about too many
other modules.
3LoD OO
- Send messages only to preferred supplier objects.
- Preferred suppliers ??
4LODC
- Crossing boundaries.
- Specify separately what is foreign
- ClassGraph, Strategy, Visitor
- LoD organize inside a set of concerns
- LoDC separate outside concerns concern-based
growth phases modularize each growth phase
5Summing LoDC
- Find all Salary-objects Traversal concern
WhereToGo concern only deals with traversal - Visitor separately expresses WhenAndWhatToDo.
Describes where traversal is extended - Start c 0
- Salary cvalue
6Weaving
- cg.traverse(o, whereToGo, whatAndWhereToDo)
- Weaves four concerns
- Structure concern (cg)
- Instantiation concern (o)
- Traversal concern (whereToGo)
- Collaboration concern (whatAndWhereToDo)
7How do we find all Salary objects
- Follow LoD, not good enough
- Follow DRY
- Abstract from class graph
- From Company to Salary
- And not company.divisions.departments.
- workGroups.employees.getSalary()
8Relational Formulation
from x1 to x2 (from Company to Salary)
From object o of class x1, to get to x2, follow
edges in the set POSS(x1,x2)e x1
lt.e.gt.(lt.C.gt).lt x2
Can easily compute these sets for every x1, x2
via transitive-closure algorithms. POSS
abbreviation for following these edges it is
still possible to reach a x2-object for some
x1-object rooted at o.
9Adaptation Dilemma
- When a parameterized abstraction P(Q) is given
with a broad definition of the domain of the
allowed actual parameters, we need to retest and
possibly change the abstraction P when we modify
the actual parameter, i.e., we move from P(Q1)
to P(Q2).
10Consequence of Adaptation Dilemma
- When class graph changes, need to test all
strategies
11Producing Traversal code
- For some class graph and strategy combinations we
might produce a large number of traversal methods
if we are not careful (exponential in worst
case). - DJ (DemeterJ, DJ, DAJ) avoid this problem. Have
built-in efficient code generation.
12PaperBoy Example
- // customer.wallet.totalMoney
- // customer.apartment.kitchen.
- // kitchenCabinet.totalMoney
- // customer.apartment.bedroom.
- // mattress.totalMoney
- we widen the interface of the Customer class and
add a method - int customer.getPayment(..)
13Implications of LoD
- A general problem of following the LoD is that it
leads to wide class interfaces because there are
so many ways of traversing through a complex
object structure for different purposes. - Use abstraction to organize the wide interfaces
using the strategy language
14Other LoDC Applications
- Growth plans for class graphs
- Constructing data structures
15Other Applications of LoD
- Object creation
- Constructor call call on a class object
- Minimize number of such calls follows the LoD
(Principle of Minimal Knowledge) - A.parse(object description)