dci - data, context and interaction @ jug genova april 2011

Post on 29-Nov-2014

1.819 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

My personal take on the Data, Context and Interaction best practice.

TRANSCRIPT

DCIData, Context and

InteractionFabrizio Giudici, Senior Java Architect

Tidalwave s.a.s - fabrizio.giudici@tidalwave.it

1Wednesday, April 20, 2011

DCI

About the speaker

2

2Wednesday, April 20, 2011

DCI

About the speaker

• Senior Software Architect, Mentor, Technical Writer

• Fourteen years of Java experience (JSE, JEE, JME, etc...)

• Sun partner since 1998, Oracle consultant since 2010

• Author of a number of open source projects

• Speaker at JavaOne, Devoxx, Jazoon, JAX and other events

• Member of the NetBeans Dream Team

• Co-leader of JUG Milano

• Java.Net blogger at http://www.java.net/blogs/fabriziogiudici

2

2Wednesday, April 20, 2011

DCI

Agenda

3

3Wednesday, April 20, 2011

DCI

Agenda

• Two real world examples

3

3Wednesday, April 20, 2011

DCI

Agenda

• Two real world examples

• DCI - Basic concepts

3

3Wednesday, April 20, 2011

DCI

Agenda

• Two real world examples

• DCI - Basic concepts

• DCI - How to implement?

3

3Wednesday, April 20, 2011

DCI

Agenda

• Two real world examples

• DCI - Basic concepts

• DCI - How to implement?

• Some simple examples

3

3Wednesday, April 20, 2011

DCI

Agenda

• Two real world examples

• DCI - Basic concepts

• DCI - How to implement?

• Some simple examples

• Abstracting and sweetening

3

3Wednesday, April 20, 2011

Two real world examples

4Wednesday, April 20, 2011

DCI

Shameless Plug

5

5Wednesday, April 20, 2011

DCI

Shameless Plug

• Exercises of Design - my design book...

5

5Wednesday, April 20, 2011

DCI

Shameless Plug

• Exercises of Design - my design book...

• Just started!

5

5Wednesday, April 20, 2011

DCI

Shameless Plug

• Exercises of Design - my design book...

• Just started!

• http://exercisesofdesign.java.net

5

5Wednesday, April 20, 2011

DCI

The Observation API

• A core component of blueBill Mobile

• An application about recording bird observations

• Designed with a high degree of abstraction

6

6Wednesday, April 20, 2011

DCI

The Observation API

• A core component of blueBill Mobile

• An application about recording bird observations

• Designed with a high degree of abstraction

6

6Wednesday, April 20, 2011

DCI

The Observation API

• A core component of blueBill Mobile

• An application about recording bird observations

• Designed with a high degree of abstraction

6

6Wednesday, April 20, 2011

DCI 7

7Wednesday, April 20, 2011

DCI

The Taxonomy API

• Models the taxonomy of a philogenetic tree

• The standard way of biology for representing living beings species

8

8Wednesday, April 20, 2011

DCI 9

9Wednesday, April 20, 2011

DCI - Basic Concepts

10Wednesday, April 20, 2011

DCI

Data, Context and Interaction

11

11Wednesday, April 20, 2011

DCI

Data, Context and Interaction

• OOD best practice invented by Trygve Reenskaug

11

11Wednesday, April 20, 2011

DCI

Data, Context and Interaction

• OOD best practice invented by Trygve Reenskaug

• The formalizer of MVC

11

11Wednesday, April 20, 2011

DCI

Data, Context and Interaction

• OOD best practice invented by Trygve Reenskaug

• The formalizer of MVC

• Seen as an evolution of MVC

11

11Wednesday, April 20, 2011

DCI

Data, Context and Interaction

• OOD best practice invented by Trygve Reenskaug

• The formalizer of MVC

• Seen as an evolution of MVC

• But it doesn’t replace it

11

11Wednesday, April 20, 2011

DCI

Data, Context and Interaction

• OOD best practice invented by Trygve Reenskaug

• The formalizer of MVC

• Seen as an evolution of MVC

• But it doesn’t replace it

• It rather broadens the analysis scope

11

11Wednesday, April 20, 2011

DCI

Data, Context and Interaction

• OOD best practice invented by Trygve Reenskaug

• The formalizer of MVC

• Seen as an evolution of MVC

• But it doesn’t replace it

• It rather broadens the analysis scope

• http://www.artima.com/articles/dci_vision.html

11

11Wednesday, April 20, 2011

DCI

DCI - aims

12

12Wednesday, April 20, 2011

DCI

DCI - aims

• Improve readability of a OO system

12

12Wednesday, April 20, 2011

DCI

DCI - aims

• Improve readability of a OO system

• Give system behaviour first-class status

12

12Wednesday, April 20, 2011

DCI

DCI - aims

• Improve readability of a OO system

• Give system behaviour first-class status

• Recover readability of system properties on the whole

12

12Wednesday, April 20, 2011

DCI

DCI - aims

• Improve readability of a OO system

• Give system behaviour first-class status

• Recover readability of system properties on the whole

• Separate responsibilities for behaviour and domain

12

12Wednesday, April 20, 2011

DCI

DCI - aims

• Improve readability of a OO system

• Give system behaviour first-class status

• Recover readability of system properties on the whole

• Separate responsibilities for behaviour and domain

• Behaviour: what the system does

12

12Wednesday, April 20, 2011

DCI

DCI - aims

• Improve readability of a OO system

• Give system behaviour first-class status

• Recover readability of system properties on the whole

• Separate responsibilities for behaviour and domain

• Behaviour: what the system does

• Domain: what the system is

12

12Wednesday, April 20, 2011

DCI

DCI - aims

• Improve readability of a OO system

• Give system behaviour first-class status

• Recover readability of system properties on the whole

• Separate responsibilities for behaviour and domain

• Behaviour: what the system does

• Domain: what the system is

• Be close to people’s mental model

12

12Wednesday, April 20, 2011

DCI

DCI - Data

13

13Wednesday, April 20, 2011

DCI

DCI - Data

• What the system is

13

13Wednesday, April 20, 2011

DCI

DCI - Data

• What the system is

• Relatively static with relations

13

13Wednesday, April 20, 2011

DCI

DCI - Data

• What the system is

• Relatively static with relations

• Domain structure implemented with “conventional” classes

13

13Wednesday, April 20, 2011

DCI

DCI - Data

• What the system is

• Relatively static with relations

• Domain structure implemented with “conventional” classes

• Typically it includes persistence

13

13Wednesday, April 20, 2011

DCI

DCI - Data

• What the system is

• Relatively static with relations

• Domain structure implemented with “conventional” classes

• Typically it includes persistence

• Comes from the mental model of system stakeholders

13

13Wednesday, April 20, 2011

DCI

DCI - Data

• What the system is

• Relatively static with relations

• Domain structure implemented with “conventional” classes

• Typically it includes persistence

• Comes from the mental model of system stakeholders

• Close to the “model” in MVC

13

13Wednesday, April 20, 2011

DCI

DCI - Data

• What the system is

• Relatively static with relations

• Domain structure implemented with “conventional” classes

• Typically it includes persistence

• Comes from the mental model of system stakeholders

• Close to the “model” in MVC

• Example: BankAccount with increase(), decrease(); no deposit()

13

13Wednesday, April 20, 2011

DCI

DCI - Context (and Roles)

14

14Wednesday, April 20, 2011

DCI

DCI - Context (and Roles)

• Associated to a use case, user story, scenario, or algorithm

14

14Wednesday, April 20, 2011

DCI

DCI - Context (and Roles)

• Associated to a use case, user story, scenario, or algorithm

• Identifies objects participating in a scenario

14

14Wednesday, April 20, 2011

DCI

DCI - Context (and Roles)

• Associated to a use case, user story, scenario, or algorithm

• Identifies objects participating in a scenario

• Assign to each object one or more stateless roles

14

14Wednesday, April 20, 2011

DCI

DCI - Context (and Roles)

• Associated to a use case, user story, scenario, or algorithm

• Identifies objects participating in a scenario

• Assign to each object one or more stateless roles

• Objects can have multiple roles at the same time

14

14Wednesday, April 20, 2011

DCI

DCI - Context (and Roles)

• Associated to a use case, user story, scenario, or algorithm

• Identifies objects participating in a scenario

• Assign to each object one or more stateless roles

• Objects can have multiple roles at the same time

• Decompose the use case (etc...) into roles, not objects

14

14Wednesday, April 20, 2011

DCI

DCI - Context (and Roles)

• Associated to a use case, user story, scenario, or algorithm

• Identifies objects participating in a scenario

• Assign to each object one or more stateless roles

• Objects can have multiple roles at the same time

• Decompose the use case (etc...) into roles, not objects

• Contrast this with polymorphism and classic OO decomposition

14

14Wednesday, April 20, 2011

DCI

DCI - Context (and Roles)

• Associated to a use case, user story, scenario, or algorithm

• Identifies objects participating in a scenario

• Assign to each object one or more stateless roles

• Objects can have multiple roles at the same time

• Decompose the use case (etc...) into roles, not objects

• Contrast this with polymorphism and classic OO decomposition

• Example: MoneyTransfer with SrcAccount and DestAccount

14

14Wednesday, April 20, 2011

DCI

Quick terminology note

15

15Wednesday, April 20, 2011

DCI

Quick terminology note

• Methodless role: abstract role

15

15Wednesday, April 20, 2011

DCI

Quick terminology note

• Methodless role: abstract role

• Interface, abstract class

15

15Wednesday, April 20, 2011

DCI

Quick terminology note

• Methodless role: abstract role

• Interface, abstract class

• Methodful role: concrete role

15

15Wednesday, April 20, 2011

DCI

Quick terminology note

• Methodless role: abstract role

• Interface, abstract class

• Methodful role: concrete role

• Regular class

15

15Wednesday, April 20, 2011

DCI

DCI - Interaction

16

16Wednesday, April 20, 2011

DCI

DCI - Interaction

• What the system does

16

16Wednesday, April 20, 2011

DCI

DCI - Interaction

• What the system does

• Occurs among roles, which act as adapters to objects

16

16Wednesday, April 20, 2011

DCI

DCI - Interaction

• What the system does

• Occurs among roles, which act as adapters to objects

• Roles are bound in different ways for each context

16

16Wednesday, April 20, 2011

DCI

DCI - Interaction

• What the system does

• Occurs among roles, which act as adapters to objects

• Roles are bound in different ways for each context

• Roles should be generic

16

16Wednesday, April 20, 2011

DCI

DCI - Interaction

• What the system does

• Occurs among roles, which act as adapters to objects

• Roles are bound in different ways for each context

• Roles should be generic

• Roles life cycle is likely to be bound to a given interaction

16

16Wednesday, April 20, 2011

DCI

DCI - Interaction

• What the system does

• Occurs among roles, which act as adapters to objects

• Roles are bound in different ways for each context

• Roles should be generic

• Roles life cycle is likely to be bound to a given interaction

• Interaction should be explicit given role nature, rather than emergent as in (agile) OOD

16

16Wednesday, April 20, 2011

DCI

DCI - Execution Model

17

17Wednesday, April 20, 2011

DCI

DCI - Execution Model

• The Context finds object participants

17

17Wednesday, April 20, 2011

DCI

DCI - Execution Model

• The Context finds object participants

• Then, it assigns (injects?) roles to them

17

17Wednesday, April 20, 2011

DCI

DCI - Execution Model

• The Context finds object participants

• Then, it assigns (injects?) roles to them

• Roles find each other by type (methodless)

17

17Wednesday, April 20, 2011

DCI

DCI - Execution Model

• The Context finds object participants

• Then, it assigns (injects?) roles to them

• Roles find each other by type (methodless)

• What about static languages and designs?

17

17Wednesday, April 20, 2011

DCI

DCI - Execution Model

• The Context finds object participants

• Then, it assigns (injects?) roles to them

• Roles find each other by type (methodless)

• What about static languages and designs?

• Then, it invokes a method on the first role

17

17Wednesday, April 20, 2011

DCI

DCI - Execution Model

• The Context finds object participants

• Then, it assigns (injects?) roles to them

• Roles find each other by type (methodless)

• What about static languages and designs?

• Then, it invokes a method on the first role

• Interaction goes on among other roles

17

17Wednesday, April 20, 2011

DCI - How to implement?

18Wednesday, April 20, 2011

DCI

Some design issues

19

19Wednesday, April 20, 2011

DCI

Some design issues

• Static vs dynamic

19

19Wednesday, April 20, 2011

DCI

Some design issues

• Static vs dynamic

• Traits, Mix-ins

19

19Wednesday, April 20, 2011

DCI

Some design issues

• Static vs dynamic

• Traits, Mix-ins

• AOP, annotations (e.g. Qi4J)

19

19Wednesday, April 20, 2011

DCI

Some design issues

• Static vs dynamic

• Traits, Mix-ins

• AOP, annotations (e.g. Qi4J)

• Problems: schizophrenia

19

19Wednesday, April 20, 2011

DCI

Some design issues

• Static vs dynamic

• Traits, Mix-ins

• AOP, annotations (e.g. Qi4J)

• Problems: schizophrenia

• Which is the identity of an object that becomes a cluster of roles

19

19Wednesday, April 20, 2011

DCI

Some design issues

• Static vs dynamic

• Traits, Mix-ins

• AOP, annotations (e.g. Qi4J)

• Problems: schizophrenia

• Which is the identity of an object that becomes a cluster of roles

• Partly solved by the clear separation object (stateful) / role (stateless)

19

19Wednesday, April 20, 2011

DCI

Some design issues

• Static vs dynamic

• Traits, Mix-ins

• AOP, annotations (e.g. Qi4J)

• Problems: schizophrenia

• Which is the identity of an object that becomes a cluster of roles

• Partly solved by the clear separation object (stateful) / role (stateless)

• What about equals() / hashcode()?

19

19Wednesday, April 20, 2011

DCI

Some design issues

• Static vs dynamic

• Traits, Mix-ins

• AOP, annotations (e.g. Qi4J)

• Problems: schizophrenia

• Which is the identity of an object that becomes a cluster of roles

• Partly solved by the clear separation object (stateful) / role (stateless)

• What about equals() / hashcode()?

• Problem: anemic objects

19

19Wednesday, April 20, 2011

DCI

Some design issues

• Static vs dynamic

• Traits, Mix-ins

• AOP, annotations (e.g. Qi4J)

• Problems: schizophrenia

• Which is the identity of an object that becomes a cluster of roles

• Partly solved by the clear separation object (stateful) / role (stateless)

• What about equals() / hashcode()?

• Problem: anemic objects

• Really a problem in this perspective?19

19Wednesday, April 20, 2011

DCI

Designing with DCI

20

20Wednesday, April 20, 2011

DCI

Designing with DCI

• First, acknowledge that DCI is a best practice

20

20Wednesday, April 20, 2011

DCI

Designing with DCI

• First, acknowledge that DCI is a best practice

• Some languages can fit better than others

20

20Wednesday, April 20, 2011

DCI

Designing with DCI

• First, acknowledge that DCI is a best practice

• Some languages can fit better than others

• Frameworks might help... but they force a new nature

20

20Wednesday, April 20, 2011

DCI

Designing with DCI

• First, acknowledge that DCI is a best practice

• Some languages can fit better than others

• Frameworks might help... but they force a new nature

• My point: DCI must be addressed in design

20

20Wednesday, April 20, 2011

Some UI-oriented examples

21Wednesday, April 20, 2011

DCI

NodesExample 1

• Static role implementation

• Introduce some generic, (G)UI oriented roles

• NetBeans Platform’s Lookup based implementation

22

22Wednesday, April 20, 2011

DCI

NodesExample 2

• Dynamically replacing roles with decorators

23

23Wednesday, April 20, 2011

DCI

NodesExample 4

• Adding contextual Actions and ToolTips

24

24Wednesday, April 20, 2011

DCI

NodesExample 5

• Removing UI dependencied

25

25Wednesday, April 20, 2011

DCI

NodesExample 6

• Injecting roles from the Context

26

26Wednesday, April 20, 2011

DCI

NodesExample 7

• Injecting Roles in function of the Context

27

27Wednesday, April 20, 2011

Abstracting and sweetening

28Wednesday, April 20, 2011

DCI

Abstracting and sweetening

• Would be nice to be technology independent

• Would be nice to have some syntactic sugar

29

29Wednesday, April 20, 2011

DCI

as()

30

30Wednesday, April 20, 2011

DCI

as()

• From Role role = object.getLookup().lookup(Role.class) ...

30

30Wednesday, April 20, 2011

DCI

as()

• From Role role = object.getLookup().lookup(Role.class) ...

• ... to Role role = object.as(Role);

30

30Wednesday, April 20, 2011

DCI

as()

• From Role role = object.getLookup().lookup(Role.class) ...

• ... to Role role = object.as(Role);

• As a wrapper around Lookup

30

30Wednesday, April 20, 2011

DCI

as()

• From Role role = object.getLookup().lookup(Role.class) ...

• ... to Role role = object.as(Role);

• As a wrapper around Lookup

• With annotations and Lombok

30

30Wednesday, April 20, 2011

DCI

as()

• From Role role = object.getLookup().lookup(Role.class) ...

• ... to Role role = object.as(Role);

• As a wrapper around Lookup

• With annotations and Lombok

30

@AsCapablepublic class MyObject { @Role private Role1 r1 = new Role1();

@Role // lazy private Provider<Role> r2 = ...; }

30Wednesday, April 20, 2011

DCI

Q & A

• Question Time

31

31Wednesday, April 20, 2011

top related