JDT
Upcoming SlideShare
Loading in...5
×
 

JDT

on

  • 168 views

 

Statistics

Views

Total Views
168
Views on SlideShare
168
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

JDT JDT Presentation Transcript

  • eclip se. or g/ obje ctt eams Redefining Modularity, Re-use in Variants and all that with Object Teams Stephan Herrmann, GK Software AG JavaOne October 3, 2012 JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 #1
  • eclip se. or g/ obje ctt eams Java OT/J JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 #2
  • eclip se. or g/ obje ctt eams A Little History of Spaghetti In the beginning the world consisted of statements: read, store, arithmetics, jump jumps where found to be dangerous because: Through undisciplined jumps each statement could relate to any other statement This is not modular Tim Avatar Bartel JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 #3
  • eclip se. or g/ obje ctt eams A Little History of Spaghetti Solution combine statements to sub-routines / procedures But: what about data? data sharing through global variables each procedure may relate to any global variable Data Spaghetti This is not modular Tim Avatar Bartel JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 #4
  • eclip se. or g/ obje ctt eams A Little History of Spaghetti Solution combine procedures and variables to classes But: what about size? systems made from 1000s of classes each class may relate to any other class Class Spaghetti This is not modular Tim Avatar Bartel JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 #5
  • eclip se. or g/ obje ctt eams Attempts for Addressing Scale Creating modules everything you write should be a module Statement 1 LOC Procedure module of 20 statements 20 LOC Class module of 20 procedures (“methods”) 400 LOC Package module of 20 classes 8000 LOC Bundle module of 20 packages 160000 LOC Beans, Components, Super Packages, Modules, Jars ... JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 #6
  • eclip se. or g/ obje ctt eams Attempts for Addressing Scale Creating modules everything you write should be a module Statement 1 LOC Procedure module of 20 statements 20 LOC Class 1 new concept for each level of scale? module of 20 procedures (“methods”) 400 LOC Package Not an economic solution! module of 20 classes 8000 LOC Bundle module of 20 packages 160000 LOC Beans, Components, Super Packages, Modules, Jars ... JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 #7
  • eclip se. or g/ obje ctt eams System made from Classes City Person Address Vendor Order Item Transaction JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 #8
  • eclip se. or g/ obje ctt eams System made from Nested Classes Ordering City Windowing Widget Srollbar Person Address Vendor Form Window Order Item Transaction Field Button Listener Persisting JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 #9
  • eclip se. or g/ obje ctt eams System made from Nested Classes ApplicationA Ordering Windowing ApplicationB Traveling Windowing Persisting Persisting ApplicationC Cool! but... classes with 100s of inner classes are not manageable JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 10
  • eclip se. or g/ obje ctt eams Classes & Packages Package hierarchical organization: folders & files Class define boundary: signature ↔ implementation support nesting Choose one ! ? JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 11
  • eclip se. or g/ obje ctt eams Classes & Packages Package hierarchical organization: folders & files Class define boundary: signature ↔ implementation support nesting Solution: team = class & package physical view logical view = JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 12
  • eclip se. or g/ obje ctt eams Classes & Packages Package hierarchical organization: folders & files Class define boundary: signature ↔ implementation support nesting #1 Solution: team = class & package Teams unify class and package make nesting feasible modules at any level of scale JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 13
  • eclip se. or g/ obje ctt eams Composition: Dream vs. Reality System construction, ideally: build lots of small building blocks compose small blocks to larger blocks top-level block is your system Remaining challenges complexity makes hierarchical breakdown extremely difficult software re-use is more demanding than lego playing Essence of re-use Problem handle near miss! transform “near miss” into “perfect match” JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 14
  • eclip se. or g/ obje ctt eams Unanticipated Adaptation Transform “near miss” into “perfect match” need a tool for adapting an existing module (anticipated adaptation: parameters) unanticipated adaptation? O-O tool for adaptation: inheritance acquire all from parent adapt those parts that dont fit Inheritance is “broken” for inner classes in Java! inherited methods can be overridden inherited classes cannot be overridden! JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 15
  • eclip se. or g/ obje ctt eams Example: Board Games BoardGame Player Token Move Rule impossible to mix impossible to mix elements from elements from Chess different games different games Player Token Move Rule mature, mature, established concept established concept Team inheritance, members are virtual classes consistent refinement of all members JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 16
  • eclip se. or g/ obje ctt eams Example: Board Games Chess Player Token Move Rule single choice: single choice: new BlitzChess() version of Rule version of Rule BlitzChess version of validate() version of validate() Player Token Move Rule #2 selectively override selectively override validate() at any nesting level at any nesting level Team inheritance, members are virtual classes consistent refinement of all members deep overriding flexible & modular JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 17
  • eclip se. or g/ obje ctt eams Essence of Re-Use Commonalities (abstract) super-classes (abstract) team classes decompose Variations sub-classes sub-teams Assemble selected variations to a system how do I select among variants? when do I select? compose is the composition itself re-usable? JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 18
  • eclip se. or g/ obje ctt eams Capturing Variance with Inheritance Polymorphism flexible, selection is postponed type of a variable describes a range of behaviors module is re-usablenew Instantiation instantiation selects one class / variant / behavior new: hard-coded selection each instance is locked to one behavior selection is final This power creates conflicts re-use is limited to one step selection cannot be revised there can only be one winner JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 19
  • eclip se. or g/ obje ctt eams Capturing Variance with Inheritance Polymorphism flexible, selection is postponed considered new type of a variable describes always of behaviors a range use factories? harmful?re-usable module is DI?new Instantiation instantiation selects one class / variant / behavior new: hard-codedconflicts are a result These conflicts are a result These selection eachfrom limitationsone behavior from limitations of inheritance. instance is locked to of inheritance. selection is final This power creates conflicts re-use is limited to one step selection cannot be revised there can only be one winner JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 20
  • eclip se. or g/ obje ctt eams Limitations of Inheritance Inheritance is great, but ... A text book example: Person A man/woman is a person, OK name An employee is a person, OK? Male/female Employees? Born as an employee? Dying when loosing the job? Man Woman Several jobs, yet only one salary? Whats wrong with inheritance? Employee salary Missing “become”, “quit”  Cant duplicate fields  Can we do better? Yes: Employee is a Role played by a Person JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 21
  • eclip se. or g/ obje ctt eams Role playing playedBy relationship «playedBy» Employee Person salary name Role Base Advantages: Dynamism: «played roles can come and go :Student By» matr=0815 joe: Man (same base object) y» ayedB name=”joe” Multiplicities: «pl » :Employee By one base can play several roles ed salary=100 l ay (different/same role types) «p Roles in OOPLs have been :Employee Roles in OOPLs have been salary=2000 studied for approx. 20 years studied for approx. 20 years JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 22
  • eclip se. or g/ obje ctt eams Binding Roles to Bases ● playedBy acquire behaviors connect role to base from base ● callout forward to base Employee «playedBy»  Person getName() getOfficePhone() callout getName -> getName getName() getPhone() getName() JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 23
  • eclip se. or g/ obje ctt eams Binding Roles to Bases ● playedBy connect role to base callout adapt behaviors ● forward to base adapt behaviors that dont fit that dont fit ● callin intercept base method «playedBy»  Employee Person getName() getOfficePhone() callout getName() getName -> getName getOfficePhone <- getPhone getPhone() callin getPhone() JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 24
  • eclip se. or g/ obje ctt eams Binding Roles to Bases ● playedBy connect role to base ● callout forward to base ● callin intercept base method «playedBy»  Employee Person getName() getOfficePhone() callout getName() getName -> getName getOfficePhone <- getPhone getPhone() callin Conceptually this is one object JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 25
  • eclip se. or g/ obje ctt eams Composition Redefined Class-based inheritance is rigid re-use requires flexibility #3 flexibility is achieved by complex design patterns those are work-arounds Composing instances one instance can accumulate multiple behaviors Composing at runtime an instance may change its behavior during its life time «playedBy» Employee Person salary name Role Base JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 26
  • eclip se. or g/ obje ctt eams Roles vs. Modules Avoid role spaghetti Roles & base each live in their own context / module Bases may be encapsulated inside a module not all bases will be visible to our roles BasePkg   «playedBy» Role1 C1 Role2  «play edBy» roleMeth1() roleMeth2() callout C2 roleMeth1 -> method1 method1() roleMeth2 <- method2 callin method2() Role2 & C2 are “one object” JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 27
  • eclip se. or g/ obje ctt eams Roles vs. Modules #4 Decapsulation: defined exceptions to encapsulation Legalizing decapsulation: visible, controllable (approve/deny per case) less total coupling BasePkg   «playedBy» Role1 C1 Role2  «play edBy» roleMeth1() roleMeth2() callout C2 roleMeth1 -> method1 method1() roleMeth2 <- method2 callin method2() Role2 & C2 are “one object” JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 28
  • eclip se. or g/ obje ctt eams Modules for Roles MyTeam Off On BasePkg teamField: someType teamMethod(T2): Type2   «playedBy» Role1 C1 Role2  «play edBy» roleMeth1() roleMeth2() callout C2 #5 roleMeth1 -> method1 method1() roleMeth2 <- method2 callin method2() Roles are members of a team Behavior implemented as interaction among roles Team activation controls all contained roles no callin trigger into an inactive team on-demand role instances per team instance JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 29
  • eclip se. or g/ obje ctt eams Check Your Order Your shopping cart contains five items: Team classes / packages unifying classes & packages makes nesting feasible Team inheritance virtual classes: consistent specialization, deep overriding Role playing dynamically specialize / compose instances at runtime «playedBy» Decapsulation admit exceptions from boundary enforcement Teams are modules for roles consistent (de)activation – callin and role instantiation JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 30
  • eclip se. or g/ obje ctt eams Connector Pattern Bonus Base: Flight booking Complete application Subscriber Add-on: Collectiong bonus points Self-contained, re-usable module BonusItem Connector Refine Bonus using team inheritance Let its roles hook into the base FlightBonus FlightBooking FlightBooking Passenger Subscriber «playedBy» Flight BonusItem Segment «playedBy» JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 31
  • eclip se. or g/ obje ctt eams Check Your Order Your shopping cart contains five items: Team classes / packages unifying classes & packages makes nesting feasible Team inheritance virtual classes: consistent specialization, deep overriding Role playing dynamically specialize / compose instances at runtime «playedBy» Decapsulation admit exceptions from boundary enforcement Teams are modules for roles consistent (de)activation – callin and role instantiation To check out these items please visit http://eclipse.org/objectteams JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 32
  • eclip se. or g/ obje ctt eams Install into a recent Eclipse package JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 33
  • eclip se. or g/ obje ctt eams Java OT/J OTDT JDT JDT «playedBy» «playedBy» JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 34
  • eclip se. or g/ obje ctt eams Credits Resources used in this presentation http://upload.wikimedia.org/wikipedia/commons/9/93/Spaghetti.jpg by Tim Avatar Bartel JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 35
  • eclip se. or g/ obje ctt eams Bonus Material JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 36
  • eclip se. or g/ obje ctt eams Adaptation using Object Teams Eat the cake and have it, too adaptation is a separate module (team and role classes) tightly integrated with existing code minimal coupling JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 37
  • eclip se. or g/ obje ctt eams Observer-Mediator-Actuator Mediator Mediator mediatorStorageField : DataStructure write read ObserverRole ActuatorRole write read additionalReference MediatorRole1 MediatorRole2 intercept decorate decorate intercept (non-modifying) (modifying) adaptation base application C1 C2 C3 C4 JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 38
  • eclip se. or g/ obje ctt eams Nesting – Stacking – Layering Team plays the role Role Team plays the role Role Nesting Team plays the role Base Team plays the role Base Stacking Role plays the role Base Role plays the role Base Layering JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 39
  • eclip se. or g/ obje ctt eams Components: OT/Equinox MANIFEST.MF ... Bundle A Bundle A Require-Bundle: B ... plugin.xml CA1 CA2 <extension point="org.objectteams.otequinox.aspectBindings"> <aspectBinding> <basePlugin id=”B”/> «require» CA2 <team class=”Team1” activation=”ALL_THREADS”/> </aspectBinding> IB2 extension Bundle B Bundle B point Bundle C Bundle C CC1 CB2 Team1 Team1 «aspectBinding» import base CB1; import base CB1; import base CB3; export CB1 import base CB3; R1 «playedBy» rm←bm internal R2 CB4 «playedBy» CB3 JavaOne 2012 | © 2012 by Stephan Herrmann; made available under the EPL v1.0 # 40