Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007.

Similar presentations


Presentation on theme: "Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007."— Presentation transcript:

1 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Campagna Anti-IF: Java e i linguaggi dinamici, incrementare le potenzialità espressive di Java [Eliminare i FOR]

2 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Campagna Anti-IF

3 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Obiettivo Più potere a Java senza i FOR Paper su come eliminare i FOR Esperienza di design evolutivo Attraverso il refactoring Usando i principi di design Far vincere qualche maglietta :)

4 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Sviluppo Java Web: lento! News … > E poi detta tutta java a sviluppo web non è così tanto veloce in una > giornata non si riesce. su questo no :-) Direi che una prima iterazione con tutte le funzionalita' di base in una giornata con 2 coppie si riesce a fare. > Con Rails in mezza o 1/4 :) ma non entriamo in guerre di religione. Se non si riesce probabilmente le storie non sono state spezzate in modo iterativo-incrementale/verticale ;-) … … > E poi detta tutta java a sviluppo web non è così tanto veloce in una > giornata non si riesce. su questo no :-) Direi che una prima iterazione con tutte le funzionalita' di base in una giornata con 2 coppie si riesce a fare. > Con Rails in mezza o 1/4 :) ma non entriamo in guerre di religione. Se non si riesce probabilmente le storie non sono state spezzate in modo iterativo-incrementale/verticale ;-) …

5 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 // class Department public void printSlips() { Resource resource = null; for(int i=0; i < _resources.size();i++) { resource = (Resource)_resources.get(i); if(resource.lastContract().deadline().after(new Date())) { System.out.println(resource.name()); System.out.println(resource.salary()); } // class Department public void printSlips() { Resource resource = null; for(int i=0; i < _resources.size();i++) { resource = (Resource)_resources.get(i); if(resource.lastContract().deadline().after(new Date())) { System.out.println(resource.name()); System.out.println(resource.salary()); } Il problema public void printSlips() { for (Resource eachResource: _resources) { if(eachResource.lastContract().deadline().after(new Date()) ) { System.out.println(eachResource.name()); System.out.println(eachResource.salary()); } public void printSlips() { for (Resource eachResource: _resources) { if(eachResource.lastContract().deadline().after(new Date()) ) { System.out.println(eachResource.name()); System.out.println(eachResource.salary()); } Our job is to solve problems, not spoonfeed compilers (…) We need clarity so we can communicate using our code. We value conciseness and the ability to express a requirement in code accurately and efficiently. --Dave Thomas Our job is to solve problems, not spoonfeed compilers (…) We need clarity so we can communicate using our code. We value conciseness and the ability to express a requirement in code accurately and efficiently. --Dave Thomas (resources select: inForce) do: printSlip.

6 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 // class Department public void printSlips() { Resource resource = null; for(int i=0; i < _resources.size();i++) { resource = (Resource)_resources.get(i); if(resource.lastContract().deadline().after(new Date())) { System.out.println(resource.name()); System.out.println(resource.salary()); } // class Department public void printSlips() { Resource resource = null; for(int i=0; i < _resources.size();i++) { resource = (Resource)_resources.get(i); if(resource.lastContract().deadline().after(new Date())) { System.out.println(resource.name()); System.out.println(resource.salary()); } Parliamo di design

7 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 // class Department public void printSlips() { Resource resource = null; for(int i=0; i < _resources.size();i++) { resource = (Resource)_resources.get(i); if(resource.lastContract().deadline().after(new Date())) { System.out.println(resource.name()); System.out.println(resource.salary()); } // class Department public void printSlips() { Resource resource = null; for(int i=0; i < _resources.size();i++) { resource = (Resource)_resources.get(i); if(resource.lastContract().deadline().after(new Date())) { System.out.println(resource.name()); System.out.println(resource.salary()); } Parliamo di design public void printSlipForEach() { for (Resource eachResource: _resources) { if(eachResource.lastContract().deadline().after(new Date()) ) { System.out.println(eachResource.name()); System.out.println(eachResource.salary()); } public void printSlipForEach() { for (Resource eachResource: _resources) { if(eachResource.lastContract().deadline().after(new Date()) ) { System.out.println(eachResource.name()); System.out.println(eachResource.salary()); } Layout?Layout? Selezione?Selezione? Media?Media? Contenuti?Contenuti? Ciclo?+Navigazione?Ciclo?+Navigazione? Ciclo?Ciclo?

8 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Il Refactoring: Aumentare la capacità del codice di rivelare le intenzioni di design, a qualsiasi membro del team, alla prima occhiata Migliorare la struttura interna del sistema, consentendo alle necessarie astrazioni di emergere LightweightLightweight Our job is to solve problems, not spoonfeed compilers (…) We need clarity so we can communicate using our code. We value conciseness and the ability to express a requirement in code accurately and efficiently. --Dave Thomas Our job is to solve problems, not spoonfeed compilers (…) We need clarity so we can communicate using our code. We value conciseness and the ability to express a requirement in code accurately and efficiently. --Dave Thomas Abbassare la complessità

9 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 // class Department public void printSlips() { Resource resource = null; for(int i=0; i < _resources.size();i++) { resource = (Resource)_resources.get(i); if(resource.lastContract().deadline().after(new Date())) { System.out.println(resource.name()); System.out.println(resource.salary()); } // class Department public void printSlips() { Resource resource = null; for(int i=0; i < _resources.size();i++) { resource = (Resource)_resources.get(i); if(resource.lastContract().deadline().after(new Date())) { System.out.println(resource.name()); System.out.println(resource.salary()); } Step 1: Separare le logiche Selezione?Selezione? Stampa busta? // class Department public void printSlips() { Resource eachResource = null; List inforces = new ArrayList(); for(int i=0; i < _resources.size();i++) { eachResource = (Resource)_resources.get(i); if(eachResource.lastContract().deadline().after(new Date()) ) { inforces.add(eachResource); } Resource eachInForce = null; for(int i=0; i < inforces.size();i++) { eachInForce = (Resource)inforces.get(i); System.out.println(eachInForce.name()); System.out.println(eachInForce.salary()); } // class Department public void printSlips() { Resource eachResource = null; List inforces = new ArrayList(); for(int i=0; i < _resources.size();i++) { eachResource = (Resource)_resources.get(i); if(eachResource.lastContract().deadline().after(new Date()) ) { inforces.add(eachResource); } Resource eachInForce = null; for(int i=0; i < inforces.size();i++) { eachInForce = (Resource)inforces.get(i); System.out.println(eachInForce.name()); System.out.println(eachInForce.salary()); }

10 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Step 2: Semplificare il FOR // class Department public void printSlips() { … Resource eachInForce = null; for(int i=0; i < inforces.size();i++) { eachInForce = (Resource)inforces.get(i); System.out.println(eachInForce.name()); System.out.println(eachInForce.salary()); } // class Department public void printSlips() { … Resource eachInForce = null; for(int i=0; i < inforces.size();i++) { eachInForce = (Resource)inforces.get(i); System.out.println(eachInForce.name()); System.out.println(eachInForce.salary()); } // class Department public void printSlips() { … Resource eachInForce = null; for(int i=0; i < inforces.size();i++) { eachInForce = (Resource)inforces.get(i); System.out.println(eachInForce.name()); System.out.println(eachInForce.salary()); } // class Department public void printSlips() { … Resource eachInForce = null; for(int i=0; i < inforces.size();i++) { eachInForce = (Resource)inforces.get(i); System.out.println(eachInForce.name()); System.out.println(eachInForce.salary()); } Logica i-esima Ciclo + navigazione new Block() { public void evaluate(Resource each) { System.out.println(each.name()); System.out.println(each.salary()); }}.evaluate(eachInForce); new Block() { public void evaluate(Resource each) { System.out.println(each.name()); System.out.println(each.salary()); }}.evaluate(eachInForce);

11 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Step 2: Semplificare il FOR // class Department public void printSlips() { … Resource eachInForce = null; for(int i=0; i < inforces.size();i++) { eachInForce = (Resource)inforces.get(i); new Block() { public void evaluate(Resource each) { System.out.println(each.name()); System.out.println(each.salary()); }}.evaluate(eachInForce); } // class Department public void printSlips() { … Resource eachInForce = null; for(int i=0; i < inforces.size();i++) { eachInForce = (Resource)inforces.get(i); new Block() { public void evaluate(Resource each) { System.out.println(each.name()); System.out.println(each.salary()); }}.evaluate(eachInForce); } Logica i-esima Ciclo + navigazione

12 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Step 2: Semplificare il FOR // class Department public void printSlips() { … Resource eachInForce = null; for(int i=0; i < inforces.size();i++) { eachInForce = (Resource)inforces.get(i); new PrintSlip().evaluate(eachInForce); } // class Department public void printSlips() { … Resource eachInForce = null; for(int i=0; i < inforces.size();i++) { eachInForce = (Resource)inforces.get(i); new PrintSlip().evaluate(eachInForce); } Logica i-esima Ciclo + navigazione public class PrintSlip implements Block { public void evaluate(Resource aResource) { System.out.println(aResource.name()); System.out.println(aResource.salary()); } public class PrintSlip implements Block { public void evaluate(Resource aResource) { System.out.println(aResource.name()); System.out.println(aResource.salary()); }

13 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 public class PrintSlip implements Block { public void evaluate(Resource aResource) { System.out.println(aResource.name()); System.out.println(aResource.salary()); } public class PrintSlip implements Block { public void evaluate(Resource aResource) { System.out.println(aResource.name()); System.out.println(aResource.salary()); } Step 3: Eliminare il FOR // class Department public void printSlips() { … Resource eachInForce = null; for(int i=0; i < inforces.size();i++) { eachInForce = (Resource)inforces.get(i); new PrintSlip().evaluate(eachInForce); } // class Department public void printSlips() { … Resource eachInForce = null; for(int i=0; i < inforces.size();i++) { eachInForce = (Resource)inforces.get(i); new PrintSlip().evaluate(eachInForce); } Logica i-esima Ciclo + navigazione

14 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 public class PrintSlip implements Block { public void evaluate(Resource aResource) { System.out.println(aResource.name()); System.out.println(aResource.salary()); } public class PrintSlip implements Block { public void evaluate(Resource aResource) { System.out.println(aResource.name()); System.out.println(aResource.salary()); } Step 3: Eliminare il FOR // class Department public void printSlips() { … Iterator iterator = inforces.iterator(); while(iterator.hasNext()) { new PrintSlip().evaluate(iterator.next()); } // class Department public void printSlips() { … Iterator iterator = inforces.iterator(); while(iterator.hasNext()) { new PrintSlip().evaluate(iterator.next()); } Logica i-esima CicloCiclo

15 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 public class PrintSlip implements Block { public void evaluate(Resource aResource) { System.out.println(aResource.name()); System.out.println(aResource.salary()); } public class PrintSlip implements Block { public void evaluate(Resource aResource) { System.out.println(aResource.name()); System.out.println(aResource.salary()); } Step 3: Eliminare il FOR // class Department public void printSlips(…) { … Iterator iterator = inforces.iterator(); while(iterator.hasNext()) { aBlock.evaluate(iterator.next()); } // class Department public void printSlips(…) { … Iterator iterator = inforces.iterator(); while(iterator.hasNext()) { aBlock.evaluate(iterator.next()); } Logica i-esima CicloCiclo

16 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Step 3: Eliminare il FOR public class ResourceOrderedCollection { private Collection _items; public ResourceOrderedCollection(Collection items) { _items = items; } public void forEachDo(Block aBlock) { Iterator iterator = _items.iterator(); while(iterator.hasNext()) { aBlock.evaluate((Resource)iterator.next()); } public class ResourceOrderedCollection { private Collection _items; public ResourceOrderedCollection(Collection items) { _items = items; } public void forEachDo(Block aBlock) { Iterator iterator = _items.iterator(); while(iterator.hasNext()) { aBlock.evaluate((Resource)iterator.next()); } public void printSlips() { Resource eachResource = null; List inforces = new ArrayList(); for(int i=0; i < _resources.size();i++) { eachResource = (Resource)_resources.get(i); if(eachResource.lastContract().deadline().after(new Date()) ) { inforces.add(eachResource); } new ResourceOrderedCollection(inforces).forEachDo(new PrintSlip()); } public void printSlips() { Resource eachResource = null; List inforces = new ArrayList(); for(int i=0; i < _resources.size();i++) { eachResource = (Resource)_resources.get(i); if(eachResource.lastContract().deadline().after(new Date()) ) { inforces.add(eachResource); } new ResourceOrderedCollection(inforces).forEachDo(new PrintSlip()); } NavigazioneNavigazione CicloCiclo

17 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 public void printSlips() { Resource eachResource = null; List inforces = new ArrayList(); for(int i=0; i < _resources.size();i++) { eachResource = (Resource)_resources.get(i); if(eachResource.lastContract().deadline().after(new Date()) ) { inforces.add(eachResource); } new ResourceOrderedCollection(inforces).forEachDo(new PrintSlip()); } public void printSlips() { Resource eachResource = null; List inforces = new ArrayList(); for(int i=0; i < _resources.size();i++) { eachResource = (Resource)_resources.get(i); if(eachResource.lastContract().deadline().after(new Date()) ) { inforces.add(eachResource); } new ResourceOrderedCollection(inforces).forEachDo(new PrintSlip()); } Step 4: E la selezione public void printSlips() { Resource eachResource = null; List inforces = new ArrayList(); for(int i=0; i < _resources.size();i++) { eachResource = (Resource)_resources.get(i); if(eachResource.lastContract().deadline().after(new Date()) ) { inforces.add(eachResource); } new ResourceOrderedCollection(inforces).forEachDo(new PrintSlip()); } public void printSlips() { Resource eachResource = null; List inforces = new ArrayList(); for(int i=0; i < _resources.size();i++) { eachResource = (Resource)_resources.get(i); if(eachResource.lastContract().deadline().after(new Date()) ) { inforces.add(eachResource); } new ResourceOrderedCollection(inforces).forEachDo(new PrintSlip()); } public void printSlips() { Resource eachResource = null; List inforces = new ArrayList(); for(int i=0; i < _resources.size();i++) { eachResource = (Resource)_resources.get(i); if(new PredicateBlock() { public boolean is(Resource each) { return each.lastContract().deadline().after(new Date()); }}.is(eachResource) { inforces.add(eachResource); } new ResourceOrderedCollection(inforces).forEachDo(new PrintSlip()); } public void printSlips() { Resource eachResource = null; List inforces = new ArrayList(); for(int i=0; i < _resources.size();i++) { eachResource = (Resource)_resources.get(i); if(new PredicateBlock() { public boolean is(Resource each) { return each.lastContract().deadline().after(new Date()); }}.is(eachResource) { inforces.add(eachResource); } new ResourceOrderedCollection(inforces).forEachDo(new PrintSlip()); } Ciclo + navigazione SelezioneSelezione AddizioneAddizione Logica i-esima

18 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Step 4: E la selezione public void printSlips() { Resource eachResource = null; List inforces = new ArrayList(); for(int i=0; i < _resources.size();i++) { eachResource = (Resource)_resources.get(i); if(new InForcePredicate().is(eachResource)) { inforces.add(eachResource); } new ResourceOrderedCollection(inforces).forEachDo(new PrintSlip()); } public void printSlips() { Resource eachResource = null; List inforces = new ArrayList(); for(int i=0; i < _resources.size();i++) { eachResource = (Resource)_resources.get(i); if(new InForcePredicate().is(eachResource)) { inforces.add(eachResource); } new ResourceOrderedCollection(inforces).forEachDo(new PrintSlip()); } public class InForcePredicate implements PredicateBlock { public boolean is(Resource each) { return each.lastContract().deadline().after(new Date()); } public class InForcePredicate implements PredicateBlock { public boolean is(Resource each) { return each.lastContract().deadline().after(new Date()); } SelezioneSelezione Ciclo + navigazione AddizioneAddizione

19 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Step 4: E la selezione public void printSlips() { Collection inforces = new ResourceOrderedCollection(_resources).select(new InForce()); new ResourceOrderedCollection(inforces).forEachDo(new PrintSlip()); } public void printSlips() { Collection inforces = new ResourceOrderedCollection(_resources).select(new InForce()); new ResourceOrderedCollection(inforces).forEachDo(new PrintSlip()); } public Collection select(PredicateBlock aBlock) { Collection result = new ArrayList(); Iterator iterator = _items.iterator(); while(iterator.hasNext()) { Resource resource = (Resource)iterator.next(); if (aBlock.is(resource)) result.add(resource); } return result; } public Collection select(PredicateBlock aBlock) { Collection result = new ArrayList(); Iterator iterator = _items.iterator(); while(iterator.hasNext()) { Resource resource = (Resource)iterator.next(); if (aBlock.is(resource)) result.add(resource); } return result; } public class InForcePredicate implements PredicateBlock { public boolean is(Resource each) { return each.lastContract().deadline().after(new Date()); } public class InForcePredicate implements PredicateBlock { public boolean is(Resource each) { return each.lastContract().deadline().after(new Date()); } CicloCiclo AddizioneAddizione SelezioneSelezione NavigazioneNavigazione

20 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Step 5: Per leggere meglio public void printSlips() { Collection inforces = new ResourceOrderedCollection(_resources).select(new InForce()); new ResourceOrderedCollection(inforces).forEachDo(new PrintSlip()); } public void printSlips() { Collection inforces = new ResourceOrderedCollection(_resources).select(new InForce()); new ResourceOrderedCollection(inforces).forEachDo(new PrintSlip()); } public void printSlips() { (new ResourceOrderedCollection(_resources).select(new InForce()).forEachDo(new PrintSlip()); } public void printSlips() { (new ResourceOrderedCollection(_resources).select(new InForce()).forEachDo(new PrintSlip()); } public ResourceOrderedCollection select(PredicateBlock aBlock) { ResourceOrderedCollection result = new ResourceOrderedCollection(); Iterator iterator = _items.iterator(); while(iterator.hasNext()) { Resource resource = (Resource)iterator.next(); if (aBlock.is(resource)) result.add(resource); } return result; } public ResourceOrderedCollection select(PredicateBlock aBlock) { ResourceOrderedCollection result = new ResourceOrderedCollection(); Iterator iterator = _items.iterator(); while(iterator.hasNext()) { Resource resource = (Resource)iterator.next(); if (aBlock.is(resource)) result.add(resource); } return result; } public void printSlips() { Predicate isInForce = new InForce(); Block printSlip = new PrintSlip(); ResourceOrderedCollection resources = new ResourceOrderedCollection(_resources); resources.select(isInForce).forEachDo(printSlip); } public void printSlips() { Predicate isInForce = new InForce(); Block printSlip = new PrintSlip(); ResourceOrderedCollection resources = new ResourceOrderedCollection(_resources); resources.select(isInForce).forEachDo(printSlip); }

21 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Step 5: Per leggere meglio public void printSlips() { Predicate isInForce = new InForce(); Block printSlip = new PrintSlip(); ResourceOrderedCollection resources = new ResourceOrderedCollection(_resources); resources.select(isInForce).forEachDo(printSlip); } public void printSlips() { Predicate isInForce = new InForce(); Block printSlip = new PrintSlip(); ResourceOrderedCollection resources = new ResourceOrderedCollection(_resources); resources.select(isInForce).forEachDo(printSlip); } public void printSlipsUsing(Predicate aCriterium, Block anAction) { _resources.select(aCriterium).forEachDo(anAction); } public void printSlipsUsing(Predicate aCriterium, Block anAction) { _resources.select(aCriterium).forEachDo(anAction); } private ResourceOrderedCollection _resources; public void printSlips() { printSlipsUsing(new InForce(),new PrintSlip()); } public void printSlips() { printSlipsUsing(new InForce(),new PrintSlip()); } private void printSlipsUsing(Predicate aCriterium, Block anAction) { new ResourceOrderedCollection(_resources).select(aCriterium).forEachDo(anAction); } private void printSlipsUsing(Predicate aCriterium, Block anAction) { new ResourceOrderedCollection(_resources).select(aCriterium).forEachDo(anAction); }

22 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Step 6: Generalizzare new ResourceOrderedCollection(resources).select(isInForce).forEachDo(printSlip); public class ResourceOrderedCollection { … public void forEachDo(Block aBlock) { Iterator iterator = _items.iterator(); while(iterator.hasNext()) { aBlock.evaluate((Resource)iterator.next()); } public ResourceOrderedCollection select(Predicate aBlock) { ResourceOrderedCollection result = new ResourceOrderedCollection(); Iterator iterator = _items.iterator(); while(iterator.hasNext()) { Resource resource = (Resource)iterator.next(); if (aBlock.is(resource)) result.add(resource); } return result; } public class ResourceOrderedCollection { … public void forEachDo(Block aBlock) { Iterator iterator = _items.iterator(); while(iterator.hasNext()) { aBlock.evaluate((Resource)iterator.next()); } public ResourceOrderedCollection select(Predicate aBlock) { ResourceOrderedCollection result = new ResourceOrderedCollection(); Iterator iterator = _items.iterator(); while(iterator.hasNext()) { Resource resource = (Resource)iterator.next(); if (aBlock.is(resource)) result.add(resource); } return result; } public class PrintSlip implements Block { public void evaluate(Resource aResource) { System.out.println(aResource.name()); System.out.println(aResource.salary()); } public class PrintSlip implements Block { public void evaluate(Resource aResource) { System.out.println(aResource.name()); System.out.println(aResource.salary()); } public class InForcePredicate implements PredicateBlock { public boolean is(Resource each) { return each.lastContract().deadline().after(new Date()); } public class InForcePredicate implements PredicateBlock { public boolean is(Resource each) { return each.lastContract().deadline().after(new Date()); }

23 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Step 6: Generalizzare new ResourceOrderedCollection(resources).select(isInForce).forEachDo(printSlip); public class ResourceOrderedCollection { … public void forEachDo(Block aBlock) { Iterator iterator = _items.iterator(); while(iterator.hasNext()) { aBlock.evaluate((Resource)iterator.next()); } public ResourceOrderedCollection select(Predicate aBlock) { ResourceOrderedCollection result = new ResourceOrderedCollection(); Iterator iterator = _items.iterator(); while(iterator.hasNext()) { Resource resource = (Resource)iterator.next(); if (aBlock.is(resource)) result.add(resource); } return result; } public class ResourceOrderedCollection { … public void forEachDo(Block aBlock) { Iterator iterator = _items.iterator(); while(iterator.hasNext()) { aBlock.evaluate((Resource)iterator.next()); } public ResourceOrderedCollection select(Predicate aBlock) { ResourceOrderedCollection result = new ResourceOrderedCollection(); Iterator iterator = _items.iterator(); while(iterator.hasNext()) { Resource resource = (Resource)iterator.next(); if (aBlock.is(resource)) result.add(resource); } return result; } public class OrderedCollection { … public void forEachDo(Block aBlock) { Iterator iterator = _items.iterator(); while(iterator.hasNext()) { aBlock.evaluate(iterator.next()); } public OrderedCollection select(Predicate aBlock) { OrderedCollection result = new OrderedCollection(); Iterator iterator = _items.iterator(); while(iterator.hasNext()) { Object object = iterator.next(); if (aBlock.is(object)) result.add(object); } return result; } public class OrderedCollection { … public void forEachDo(Block aBlock) { Iterator iterator = _items.iterator(); while(iterator.hasNext()) { aBlock.evaluate(iterator.next()); } public OrderedCollection select(Predicate aBlock) { OrderedCollection result = new OrderedCollection(); Iterator iterator = _items.iterator(); while(iterator.hasNext()) { Object object = iterator.next(); if (aBlock.is(object)) result.add(object); } return result; } public class PrintSlip implements Block { public void evaluate(Resource aResource) { System.out.println(aResource.name()); System.out.println(aResource.salary()); } public class PrintSlip implements Block { public void evaluate(Resource aResource) { System.out.println(aResource.name()); System.out.println(aResource.salary()); } public class InForcePredicate implements PredicateBlock { public boolean is(Resource each) { return each.lastContract().deadline().after(new Date()); } public class InForcePredicate implements PredicateBlock { public boolean is(Resource each) { return each.lastContract().deadline().after(new Date()); } public class PrintSlip implements Block { public void evaluate(Object anObject) { System.out.println(((Resource)anObject).name()); System.out.println(((Resource)anObject).salary());} } public class PrintSlip implements Block { public void evaluate(Object anObject) { System.out.println(((Resource)anObject).name()); System.out.println(((Resource)anObject).salary());} } public class InForcePredicate implements Predicate { public boolean is(Object anObject) { return ((Resource)anObject).lastContract().deadline().after(new Date()); } public class InForcePredicate implements Predicate { public boolean is(Object anObject) { return ((Resource)anObject).lastContract().deadline().after(new Date()); }

24 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Dove siamo // class Department public void printSlips() { Resource resource = null; for(int i=0; i < _resources.size();i++) { resource = (Resource)_resources.get(i); if(resource.lastContract().deadline().after(new Date())) { System.out.println(resource.name()); System.out.println(resource.salary()); } // class Department public void printSlips() { Resource resource = null; for(int i=0; i < _resources.size();i++) { resource = (Resource)_resources.get(i); if(resource.lastContract().deadline().after(new Date())) { System.out.println(resource.name()); System.out.println(resource.salary()); } Layout?Layout? Contenuti?Contenuti? Navigazione?Navigazione? Selezione?Selezione? Media?Media? NavigazioneNavigazione SelezioneSelezione Contenuti+ Media+ Layout Contenuti+ _resources.select(isInForce).forEachDo(printSlip); _resources.select(onlyWomen).forEachDo(printReport);

25 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Review & ToDoList :Department Andrea:Employee Federica:Manager 10/01-10/11/2007:Contract 1/9/ /10/2008:Contract Federica:String Andrea:String // class Department public void printSlips() { Resource resource = null; for(int i=0; i < _resources.size();i++) { resource = (Resource)_resources.get(i); if(resource.lastContract().deadline().after(new Date())) { System.out.println(resource.name()); System.out.println(resource.salary()); } // class Department public void printSlips() { Resource resource = null; for(int i=0; i < _resources.size();i++) { resource = (Resource)_resources.get(i); if(resource.lastContract().deadline().after(new Date())) { System.out.println(resource.name()); System.out.println(resource.salary()); } Layout?Layout? Contenuti?Contenuti? Navigazione?Navigazione? Selezione?Selezione? Media?Media? System.out:PrintStream

26 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Review & ToDoList resources:OrderedCollection :Department Andrea:Employee Federica:Manager 10/01-10/11/2007:Contract 1/9/ /10/2008:Contract :InForce :PrintSlip Federica:String System.out:PrintStream inForce:OrderedCollection Andrea:String _resources.select(isInForce).forEachDo(printSlip); public OrderedCollection select(Predicate aBlock) { OrderedCollection result = new OrderedCollection(); Iterator iterator = _items.iterator(); while(iterator.hasNext()) { Object object = iterator.next(); if (aBlock.is(object)) result.add(object); } return result; } public OrderedCollection select(Predicate aBlock) { OrderedCollection result = new OrderedCollection(); Iterator iterator = _items.iterator(); while(iterator.hasNext()) { Object object = iterator.next(); if (aBlock.is(object)) result.add(object); } return result; } public boolean is(Object each) { return ((Resource)each).lastContract().deadline().after(new Date()); } public boolean is(Object each) { return ((Resource)each).lastContract().deadline().after(new Date()); }

27 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Review & ToDoList resources:OrderedCollection :Department Andrea:Employee Federica:Manager 10/01-10/11/2007:Contract 1/9/ /10/2008:Contract :InForce :PrintSlip Federica:String System.out:PrintStream inForce:OrderedCollection Andrea:String public void forEachDo(Block aBlock) { Iterator iterator = _items.iterator(); while(iterator.hasNext()) { aBlock.evaluate(iterator.next()); } public void forEachDo(Block aBlock) { Iterator iterator = _items.iterator(); while(iterator.hasNext()) { aBlock.evaluate(iterator.next()); } public OrderedCollection select(Predicate aBlock) { OrderedCollection result = new OrderedCollection(); Iterator iterator = _items.iterator(); while(iterator.hasNext()) { Object object = iterator.next(); if (aBlock.is(object)) result.add(object); } return result; } public OrderedCollection select(Predicate aBlock) { OrderedCollection result = new OrderedCollection(); Iterator iterator = _items.iterator(); while(iterator.hasNext()) { Object object = iterator.next(); if (aBlock.is(object)) result.add(object); } return result; } public class PrintSlip implements Block { public void evaluate(Object anObject) { System.out.println(((Resource)anObject).name()); System.out.println(((Resource)anObject).salary()); } public class PrintSlip implements Block { public void evaluate(Object anObject) { System.out.println(((Resource)anObject).name()); System.out.println(((Resource)anObject).salary()); }

28 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Riferimenti blocchi e chiusure Blocchi in Java Blocchi e chiusure in Ruby Chiusure nel linguaggio Java Esempi di librerie

29 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Segui la Campagna Anti-IF

30 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007 Risorse: Tecnica del Pomodoro: EasyTracking: Gruppo XPLabs Friends- Italia: Extreme Programming User Group – Italia: Domande


Download ppt "Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License Francesco Cirillo – MetodiAgili.it Javaday Roma - 01/12/2007."

Similar presentations


Ads by Google