Presentation is loading. Please wait.

Presentation is loading. Please wait.

© AgiliX Agile Development Consulting The forgotten abstractions Cesario Ramos.

Similar presentations


Presentation on theme: "© AgiliX Agile Development Consulting The forgotten abstractions Cesario Ramos."— Presentation transcript:

1 © AgiliX Agile Development Consulting The forgotten abstractions Cesario Ramos

2 © AgiliX Agile Development Consulting The forgotten abstractions How to use them in Java

3 © AgiliX Agile Development Consulting Roles are about objects and how they interact to achieve some purpose. For thirty years I have tried to get them into the into the main stream, but haven't succeeded. I believe the reason is that our programming languages are class oriented rather than object oriented. Trygve Reenskaug

4 © AgiliX Agile Development Consulting

5 A set of properties and behavior an object can assume in a particular context. Roles can be played by objects of different classes. An object can play different roles. The class of an object is not affected!

6 © AgiliX Agile Development Consulting Collaboration Set of roles working together to realize some functionality (User Story / Use Case). Race Racecars -> laps to go, driver... Race itself -> weather, race lap, participants,...

7 © AgiliX Agile Development Consulting What the object IS vs What the object DOES

8 © AgiliX Agile Development Consulting What’s in it for me?

9 © AgiliX Agile Development Consulting Open Closed Principle A module should be open for extension and closed for modification

10 © AgiliX Agile Development Consulting Separation Of Concerns Low Coupling Minimal dependencies Minimal side effects High Cohesion Single responsibility One reason to change

11 © AgiliX Agile Development Consulting The forgotten abstractions How to use them in Java

12 © AgiliX Agile Development Consulting ObjectTeams Stephan Herrmann Extends Java. Uses instrumentation Provides mature Eclipse plugin

13 © AgiliX Agile Development Consulting

14 public abstract class Subject { protected Set observers = … public void notify() { for(Observer aObserver: observers) { aObserver.update(this); } public void attachObserver(Observer anObserver) {…} … } public interface Observer { public void update(Subject theSubject); }

15 © AgiliX Agile Development Consulting All implementing classes result in objects instantiated are Subject and/or Observer Using Subjects or Observers in more contexts can give some problems Now we must use the objects in a different context... Poor Open Closeness Poor Separation of Concerns

16 © AgiliX Agile Development Consulting public abstract team class SubjectObserver { … protected abstract class Subject { private LinkedList observers = … public void attachObserver (Observer o) {…}... public void notify() { for (Observer observer : observers) observer.update(this); } protected abstract class Observer { abstract void update(Subject s); }

17 © AgiliX Agile Development Consulting public team class ObservingGraphical extends SubjectObserver { protected class Subject playedBy TV { notify <- after setPrice; } protected class ScreenObserver extends Observer playedBy Screen { update -> redraw; } … }

18 © AgiliX Agile Development Consulting final ObservingGraphical observingGrph = new ObservingGraphical(); TV tv = new TV(); Screen screen = new Screen(); within(observingGrph) { observingGrph.attachSubjectObserver(tv, screen); tv.setPrice(1000); }

19 © AgiliX Agile Development Consulting Reusing collaborations

20 © AgiliX Agile Development Consulting Printer Service User has a limit on number of pages. SuperUser can print unlimited. Offer as a component for user by multiple clients.

21 © AgiliX Agile Development Consulting public team class PrinterService { private int totalPrintedPages = 0; private void print(Job job, Login login) { … } private void setTotalPrintedPages(int totalPrintedPages) { this.totalPrintedPages = totalPrintedPages;} … public abstract class User { private static final int MAX_PAGES_USER = 10; int counter = 0; public int print(Job job) { if (counter + job.getNumberPages() >= MAX_PAGES_USER) return 0; counter += job.getNumberPages(); PrinterService.this.print(job, getLogin() ); return counter; } public int getPrintedPages() { return counter; }...

22 © AgiliX Agile Development Consulting... public abstract class SuperUser { public int print(Job job) { PrinterService.this.print(job, getLogin()); return getTotalPrintedPages(); } public int getTotalpages(){ return getTotalPrintedPages(); } protected abstract Login getLogin(); }

23 © AgiliX Agile Development Consulting public team class PrinterForPersons extends PrinterService { public class User playedBy Developer { Login getLogin() -> Login getLogin(); } public class SuperUser playedBy Manager { Login getLogin() -> Login getLogin(); } public SuperUser asSuperUser(Manager as SuperUser superUser) { return superUser; } public User asUser(Developer as User user) { return user; }

24 © AgiliX Agile Development Consulting final PrinterForPersons printerForPersons = new PrinterForPersons(); // get domain objects Developer person1 = … Manager person2 = … printerForPersons.activate(); // externalized roles using lifting User user = printerForPersons.asUser(person1); SuperUser superUser = printerForPersons.asSuperUser(person2); // rol specific use case superUser.print(new Job(25)); user.print(new Job(5)); superUser.getPrintedPages()); user.getPrintedPages()); printerForPersons.getTotalPrintedPages(); printerForPersons.deactivate();

25 © AgiliX Agile Development Consulting ObjectTeams brings Roles extension to Java Easy to separate what the system IS from what the system DOES.


Download ppt "© AgiliX Agile Development Consulting The forgotten abstractions Cesario Ramos."

Similar presentations


Ads by Google