• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
L'arte perduta di pensare ad oggetti
 

L'arte perduta di pensare ad oggetti

on

  • 2,983 views

La mia presentazione al Codemotion 2012

La mia presentazione al Codemotion 2012

Statistics

Views

Total Views
2,983
Views on SlideShare
1,797
Embed Views
1,186

Actions

Likes
4
Downloads
11
Comments
0

7 Embeds 1,186

http://matteo.vaccari.name 1066
http://presentz.org 89
http://local.host 12
http://lanyrd.com 10
http://dev.presentz.org 5
http://127.0.0.1 3
http://translate.googleusercontent.com 1
More...

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

    L'arte perduta di pensare ad oggetti L'arte perduta di pensare ad oggetti Presentation Transcript

    • L’arte perduta dipensare a oggetti Matteo Vaccari vaccari@pobox.com matteo.vaccari@xpeppers.com (cc) Alcuni diritti riservati
    • Che obiettivo ci diamo?
    • Costo del cambiamento Kent Beck, Extreme Programming Explained
    • Può essere così? Kent Beck, Extreme Programming Explained
    • OCP, DIP, SRP, LSP,...Decorator, Mediator,Bridge, Adapter, Composite, Visitor, Flyweight...
    • Not so many people can:• start with some simple, concrete user stories and build a minimal yet flexible object model, Dafydd Rees, Responsibility Driven Design References http://www.dafydd.net/archive/2010/
    • Minimo ma flessibile Dafydd Rees
    • Una storia Finalmente ho capito come collaborare!1982 Commodore Vic20 APPASSIONATO1991 Laurea in Scienze dellInformazione HOTSHOT1998 Dottorato in Informatica FORMALISTA2003 Extreme Programming! XPer2007 Team Orione in Sourcesense → XPeppers2009 Workshop su Design Emergente FC2011 Object Thinking Non tutti i progetti fatti con XP vanno bene. Alcuni hanno problemi di qualità del codice... Forse che ho trascurato il design?
    • Che cos’è un oggetto?
    • Che cos’è un oggetto? Proc1 Proc5Proc2 Data Proc3 Proc4 David West, Object Thinking
    • OOP è un paradigma nuovoOOP decompone il software in maniera diversa
    • Solve Problem Read Compute Write Input Answer Output IterateRead Validate Store Setup Clo Foo Bar Baz overhings Things Things Printer Prin things
    • Pryce e Freeman, Growing Object-Oriented Software
    • Pensiero a oggetti vs. Pensiero formale
    • Class, Responsibilities, Collaborators Vs The UML formal meta-model Kent Beck, Ward Cunningham http://c2.com/doc/oopsla89/paper.html
    • Vs
    • Cards + conversations Vs. documenti di specifica
    • Smalltalk Vs Eiffel
    • Un esempio:http access log report
    • Access Log ReportEsercizio - estrarre un report da un file di accessi di ApacheSi vuole scrivere un programma batch che legge in input un file di accessi di Apachee produce in output un report.Il nostro input è un file di questo tipo:192.168.20.192 - - [29/Jul/2011:14:19:48 +0200] "GET / HTTP/1.1" 200 11870192.168.20.192 - - [29/Jul/2011:14:19:49 +0200] "GET /tomcat.png HTTP/1.1" 304 -192.168.20.192 - - [29/Jul/2011:14:20:39 +0200] "POST /phoenix-0.0/phoenixServlet HTTP/1.1" 200 264192.168.20.192 - - [29/Jul/2011:14:21:23 +0200] "GET /phoenix-0.0/tranpipe-demo/demo.html HTTP/1.1"192.168.20.191 - - [29/Jul/2011:15:48:04 +0200] "POST /phoenix-0.0/phoenixServlet HTTP/1.1" 200 263192.168.100.184 - - [01/Aug/2011:13:20:49 +0200] "GET /manager/status?XML=true HTTP/1.1" 401 2486Il nostro obiettivo è estrarre un report di questa formadata risultati-2xx risultati-3xx risultati-4xx risultati-5xx29/Jul/2011 1223 23 456 1201/Aug/2011 1212 24 11 123
    • Usa la forza degli oggetti, Luke!
    • AccessLog Access Calendar Day Report
    • Usa la forza del TDD, Luke!
    • First test: a report with one row and one column
    • Second test: choose to develop rows? or to develop columns?
    • “Semplici strutture dati”
    • Mature programmers know that the idea that everything is an object isa myth. Sometimes you really do want simple data structures with procedures operating on them. Robert Martin, Clean Code
    • Robert Martin, Clean Coders episode VII
    • <form> <label for="firstName">First Name</label> <input id="firstName" name="firstName" value="${firstName}" /> <label for="lastName">Last Name</label> <input id="lastName" name="lastName" value="${lastName}" /> <label for="email">Email</label> <input id="email" name="email" value="${email}" /> <!-- and so on and so forth for 100 other fields --></form>
    • class RegistrationRequest { private String firstName; private String lastName; private String email; // and so on and so forth ... public void setFirstName(String firstName) { this.firstName = firstName; } public String getFirstName() { return firstName; } // and so on and so forth ... public ErrorList validate() { ErrorList errors = new ErrorList(); if (isEmpty(firstName)) { errors.add("First Name is required"); } if (isEmpty(lastName)) { errors.add("Last Name is required"); } // and so on and so forth .... return errors; } }
    • class RegistrationRequestController { public void handleRequest( HttpServletRequest request, HttpServletRequest response ) { RegistrationRequest rr = new RegistrationRequest(); rr.setFirstName(request.getParameter("firstName")); rr.setLastName(request.getParameter("lastName")); rr.setEmail(request.getParameter("email")); // etc etc ... if (rr.isEmpty()) { registrationDao.save(rr); response.redirectTo(THANKYOU_PAGE); } else { registrationView.setErrors(errors); response.getWriter().write(registrationView.toHtml()); } }}
    • class RegistrationDao { public void save(RegistrationRequest rr) { String sql = "insert into registration_requests" + " (firstName, lastName, email, ...) " + // etc. " values (?,?,?,....)"; // etc. PreparedStatement statement = connection.prepareStatement(sql); statement.setObject(1, rr.getFirstName()); statement.setObject(2, rr.getLastName()); // ... arrrgh! statement.execute(); }}
    • The basic principle of recursivedesign is to make the parts have thesame power as the whole. -- Alan Kay
    • public class User extends CompositeDataItem { private PrimaryKeyDataItem userId = new PrimaryKeyDataItem("UserId"); private StringDataItem username = new NonEditableStringDataItem("Username"); private StringDataItem firstName = new StringDataItem("FirstName"); private StringDataItem lastName = new StringDataItem("LastName"); private PasswordDataItem password = new PasswordDataItem("Password", "HashedPassword"); private StringDataItem email = new StringDataItem("Email"); private BooleanDataItem enabled = new BooleanDataItem("Enabled"); public User(Row row) { for (DataItem item : items.values()) { item.setFrom(row); } } public User(ParameterMap parameterMap) { for (DataItem item : items.values()) { item.setFrom(parameterMap); } }
    • public void displayDataOn(HtmlForm form) { for (DataItem item : items.values()) { item.displayDataOn(form); form.addRow(); }}public Row getDatabaseRow() { Row row = new Row(); for (DataItem item : items.values()) { item.putIn(row); } return row;}
    • public class UserView extends CrudView { private HtmlForm form; public void buildForm(CompositeDataItem user) { form = new HtmlForm(HttpMethod.POST); user.displayDataOn(form); this.add(form); }}
    • public class UserInsertController { // ... public void handleRequest(WebRequest request, WebResponse response) { if (request.isPost()) { User user = new User(request.parameterMap()); ErrorList errorList = user.validate(); if (errorList.isNotEmpty()) { view.setError(errorList.toHtmlElement()); return; } registry.insertUser(user); response.redirectTo(user.url()); } view.buildForm(new User(request.parameterMap())); }
    • Una storia...1982 Commodore Vic20 APPASSIONATO1991 Laurea in Scienze dellInformazione HOTSHOT1998 Dottorato in Informatica FORMALISTA2003 Extreme Programming! XPer2007 Team Orione in Sourcesense → XPeppers2009 Workshop su Design Emergente FC2011 Object Thinking2012 Success! L’ultimo progetto consegnato dal “mio” team XP: 1400 giornate su nove mesi, messo in produzione ...che prosegue... con pochissimi difetti e nei tempi previsti!
    • OOP è umanesimo
    • Per saperne di più:
    • Per saperne di più:http://www.cleancoders.com/codecast/clean-code-episode-7/show Architecture: the lost years http://www.youtube.com/watch?v=WpkDN78P884
    • Per saperne di più: Francesco Cirillo Kent Beck ha già scritto un libro sul design a oggetti -- è il libro sul TDD (Workshop Design Emergente 2009)
    • Want to know more? http://matteo.vaccari.name/blog/ vaccari@pobox.com twitter: @xpmatteoThis presentation can be downloaded from http://slideshare.net/xpmatteo
    • Grazie dell’attenzione! Extreme Programming:development & mentoring