SlideShare ist ein Scribd-Unternehmen logo
1 von 39
8	
  Lines	
  of	
  Code	
  
Greg	
  Young	
  
InfoQ.com: News & Community Site
• 750,000 unique visitors/month
• Published in 4 languages (English, Chinese, Japanese and Brazilian
Portuguese)
• Post content from our QCon conferences
• News 15-20 / week
• Articles 3-4 / week
• Presentations (videos) 12-15 / week
• Interviews 2-3 / week
• Books 1 / month
Watch the video with slide
synchronization on InfoQ.com!
http://www.infoq.com/presentations
/8-lines-code-refactoring
Presented at QCon London
www.qconlondon.com
Purpose of QCon
- to empower software development by facilitating the spread of
knowledge and innovation
Strategy
- practitioner-driven conference designed for YOU: influencers of
change and innovation in your teams
- speakers and topics driving the evolution and innovation
- connecting and catalyzing the influencers and innovators
Highlights
- attended by more than 12,000 delegates since 2007
- held in 9 cities worldwide
Simplicity	
  
I	
  am	
  stupid	
  to	
  work	
  otherwise.	
  
Fancy	
  code	
  befuddles	
  me.	
  
 public	
  class	
  DeactivateInventoryItem	
  
	
  {	
  
	
  	
  	
  	
  private	
  readonly	
  ItemRepository	
  repository;	
  
	
  
	
  	
  	
  	
  public	
  DeactivateInventoryItem(ItemRepository	
  repository)	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  this.repository	
  =	
  repository;	
  
	
  	
  	
  	
  }	
  
	
  
	
  	
  	
  	
  public	
  void	
  Deactivate(Guid	
  id,	
  string	
  reason)	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  var	
  item	
  =	
  repository.GetById(id);	
  
	
  	
  	
  	
  	
  	
  	
  	
  item.Deactivate(reason);	
  
	
  	
  	
  	
  	
  	
  	
  	
  repository.Save(item);	
  
	
  	
  	
  	
  }	
  
	
  }	
  
 [Transactional]	
  
	
  [RequiresPermission(“admin”)]	
  
	
  [Logged]	
  
	
  [EatsExceptions]	
  
	
  [DoesBadThingsWhenYouArentWatching]	
  
	
  public	
  class	
  DeactivateInventoryItem	
  
	
  {	
  
	
  	
  	
  	
  private	
  readonly	
  ItemRepository	
  repository;	
  
	
  
	
  	
  	
  	
  public	
  DeactivateInventoryItem(ItemRepository	
  repository)	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  this.repository	
  =	
  repository;	
  
	
  	
  	
  	
  }	
  
	
  
	
  	
  	
  	
  public	
  void	
  Deactivate(Guid	
  id,	
  string	
  reason)	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  var	
  item	
  =	
  repository.GetById(id);	
  
	
  	
  	
  	
  	
  	
  	
  	
  item.Deactivate(reason);	
  
	
  	
  	
  	
  }	
  
	
  }	
  
Simplicity?	
  
<bean	
  id="moreComplexObject"	
  class="example.ComplexObject">	
  
	
  <!-­‐-­‐	
  results	
  in	
  a	
  setAdminEmails(java.uNl.ProperNes)	
  call	
  -­‐-­‐>	
  
	
  <property	
  name="adminEmails">	
  
	
  	
  	
  <props>	
  
	
  	
  	
  	
  	
  <prop	
  key="administrator">administrator@example.org</prop>	
  
	
  	
  	
  	
  	
  <prop	
  key="support">support@example.org</prop>	
  
	
  	
  	
  	
  	
  <prop	
  key="development">development@example.org</prop>	
  
	
  	
  	
  </props>	
  
	
  </property>	
  
	
  <!-­‐-­‐	
  results	
  in	
  a	
  setSomeList(java.uNl.List)	
  call	
  -­‐-­‐>	
  
	
  <property	
  name="someList">	
  
	
  	
  	
  <list>	
  
	
  	
  	
  	
  	
  <value>a	
  list	
  element	
  followed	
  by	
  a	
  reference</value>	
  
	
  	
  	
  	
  	
  <ref	
  bean="myDataSource"	
  />	
  
	
  	
  	
  </list>	
  
	
  </property>	
  
	
  <!-­‐-­‐	
  results	
  in	
  a	
  setSomeMap(java.uNl.Map)	
  call	
  -­‐-­‐>	
  
	
  <property	
  name="someMap">	
  
	
  	
  	
  <map>	
  
	
  	
  	
  	
  	
  <entry	
  key="an	
  entry"	
  value="just	
  some	
  string"/>	
  
	
  	
  	
  	
  	
  <entry	
  key	
  ="a	
  ref"	
  value-­‐ref="myDataSource"/>	
  
	
  	
  	
  </map>	
  
 [Transactional]	
  
	
  [RequiresPermission(“admin”)]	
  
	
  [Logged]	
  
	
  [EatsExceptions]	
  
	
  [DoesBadThingsWhenYouArentWatching]	
  
	
  public	
  class	
  DeactivateInventoryItem	
  
	
  {	
  
	
  	
  	
  	
  private	
  readonly	
  ItemRepository	
  repository;	
  
	
  
	
  	
  	
  	
  public	
  DeactivateInventoryItem(ItemRepository	
  repository)	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  this.repository	
  =	
  repository;	
  
	
  	
  	
  	
  }	
  
	
  
	
  	
  	
  	
  public	
  void	
  Deactivate(Guid	
  id,	
  string	
  reason)	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  var	
  item	
  =	
  repository.GetById(id);	
  
	
  	
  	
  	
  	
  	
  	
  	
  item.Deactivate(reason);	
  
	
  	
  	
  	
  }	
  
	
  }	
  
 [Transactional]	
  
	
  [RequiresPermission(“admin”)]	
  
	
  [Logged]	
  
	
  [EatsExceptions]	
  
	
  [DoesBadThingsWhenYouArentWatching]	
  
	
  public	
  class	
  DeactivateInventoryItem	
  
	
  {	
  
	
  	
  	
  	
  private	
  readonly	
  ItemRepository	
  repository;	
  
	
  
	
  	
  	
  	
  public	
  DeactivateInventoryItem(ItemRepository	
  repository)	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  this.repository	
  =	
  repository;	
  
	
  	
  	
  	
  }	
  
	
  
	
  	
  	
  	
  public	
  virtual	
  void	
  Deactivate(Guid	
  id,	
  string	
  reason)	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  var	
  item	
  =	
  repository.GetById(id);	
  
	
  	
  	
  	
  	
  	
  	
  	
  item.Deactivate(reason);	
  
	
  	
  	
  	
  }	
  
	
  }	
  
 public	
  object	
  Foo()	
  
	
  {	
  
	
  	
  	
  	
  	
  return	
  this;	
  
	
  }	
  
If	
  you	
  find	
  you	
  need	
  an	
  extension	
  
to	
  your	
  ide	
  to	
  understand	
  what’s	
  
going	
  on.	
  Its	
  probably	
  not	
  simple.	
  
What’s	
  the	
  root	
  of	
  the	
  problem?	
  
 
	
  	
  	
  	
  public	
  void	
  Deactivate(Guid	
  id,	
  string	
  reason)	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  var	
  item	
  =	
  repository.GetById(id);	
  
	
  	
  	
  	
  	
  	
  	
  	
  item.Deactivate();	
  
	
  	
  	
  	
  }	
  
	
  	
  
	
  
	
  	
  	
  	
  public	
  void	
  Reactivate(Guid	
  id,	
  DateTime	
  effective,	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  string	
  reason)	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  var	
  item	
  =	
  repository.GetById(id);	
  
	
  	
  	
  	
  	
  	
  	
  	
  item.Deactivate();	
  
	
  	
  	
  	
  }	
  
	
  	
  
	
  
	
  	
  	
  	
  public	
  void	
  CheckIn(Guid	
  id,	
  int	
  count)	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  var	
  item	
  =	
  repository.GetById(id);	
  
	
  	
  	
  	
  	
  	
  	
  	
  item.Deactivate();	
  
	
  	
  	
  	
  }	
  
	
  	
  
No	
  common	
  interface!	
  
 
	
  	
  	
  	
  public	
  void	
  Log(PointCut	
  calledOn)	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  logger.Log(calledOn.Name	
  +	
  “:”	
  +	
  calledOn.Parameters);	
  	
  	
  	
  
	
  	
  	
  	
  }	
  
	
  	
  	
  
	
  
 
	
  	
  	
  	
  public	
  void	
  Handle(DeactivateCommand	
  c)	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  var	
  item	
  =	
  repository.GetById(c.id);	
  
	
  	
  	
  	
  	
  	
  	
  	
  item.Deactivate();	
  
	
  	
  	
  	
  }	
  
	
  	
  
	
  
	
  	
  	
  	
  public	
  void	
  Handle(ReactivateCommand	
  c)	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  var	
  item	
  =	
  repository.GetById(c.id);	
  
	
  	
  	
  	
  	
  	
  	
  	
  item.Reactivate();	
  
	
  	
  	
  	
  }	
  
	
  	
  
	
  
	
  	
  	
  	
  public	
  void	
  Handle(CheckInCommand	
  c)	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  var	
  item	
  =	
  repository.GetById(c.id);	
  
	
  	
  	
  	
  	
  	
  	
  	
  item.CheckIn(c.quantity);	
  
	
  	
  	
  	
  }	
  
	
  	
  
	
  
 
	
  interface	
  Handles<T>	
  where	
  T:Command	
  
	
  {	
  
	
  	
  	
  	
  	
  void	
  Handle(T	
  command);	
  	
  	
  	
  	
  	
  	
  	
  
	
  }	
  
	
  	
  
	
  
 class	
  LoggingHandler<T>	
  	
  :	
  Handles<T>	
  where	
  T:Command	
  
	
  {	
  
	
  	
  	
  	
  	
  private	
  readonly	
  Handles<T>	
  next;	
  
	
  
	
  	
  	
  	
  	
  public	
  LoggingHandler(Handles<T>	
  next)	
  
	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  this.next	
  =	
  next;	
  
	
  	
  	
  	
  	
  }	
  
	
  
	
  	
  	
  	
  	
  public	
  void	
  Handle(T	
  command)	
  
	
  	
  	
  	
  	
  {	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  myLoggingFramework.Log(command);	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  next.Handle(command);	
  
	
  	
  	
  	
  	
  }	
  
	
  }	
  
	
  
	
  	
  
	
  	
  var	
  handler	
  =	
  new	
  LoggingHandler<DeactivateCommand>(	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  new	
  DeactivateCommandHandler(...)	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  );	
  
	
  
 public	
  class	
  DeactivateInventoryItem	
  :Handles<DeactivateCommand>	
  
	
  {	
  
	
  	
  	
  	
  	
  private	
  readonly	
  ItemRepository	
  repository;	
  
	
  
	
  	
  	
  	
  	
  public	
  DeactivateInventoryItem(ItemRepository	
  repository)	
  
	
  	
  	
  	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  this.repository	
  =	
  repository;	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  public	
  void	
  Handle(DeactivateCommand	
  command)	
  
	
  	
  	
  	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  var	
  item	
  =	
  repository.GetById(command.id);	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  item.Deactivate(cmd.Reason);	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  }	
  
 public	
  class	
  DeactivateInventoryItem	
  :Handles<DeactivateCommand>	
  
	
  {	
  
	
  	
  	
  	
  	
  private	
  readonly	
  ItemRepository	
  repository;	
  
	
  
	
  	
  	
  	
  	
  public	
  DeactivateInventoryItem(ItemRepository	
  repository)	
  
	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  this.repository	
  =	
  repository;	
  
	
  	
  	
  	
  	
  }	
  
	
  
	
  	
  	
  	
  	
  public	
  void	
  Handle(DeactivateCommand	
  command)	
  
	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  var	
  item	
  =	
  repository.GetById(command.id);	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  item.Deactivate(cmd.Reason);	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  }	
  
	
  }	
  
 class	
  Handlers	
  
	
  {	
  
	
  	
  	
  public	
  static	
  void	
  Handle(ItemRepository	
  repository,	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  DeactivateCommand	
  c)	
  
	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  var	
  item	
  =	
  repository.GetById(c.id);	
  
	
  	
  	
  	
  	
  	
  	
  item.Deactivate();	
  
	
  	
  	
  }	
  
	
  
	
  	
  	
  public	
  static	
  void	
  Handle(ItemRepository	
  repository,	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ReactivateCommand	
  c)	
  
	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  var	
  item	
  =	
  repository.GetById(c.id);	
  
	
  	
  	
  	
  	
  	
  	
  item.Deactivate();	
  
	
  	
  	
  }	
  
	
  
	
  	
  	
  public	
  static	
  void	
  Handle(ItemRepository	
  repository,	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  CheckInCommand	
  c)	
  
	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  var	
  item	
  =	
  repository.GetById(c.id);	
  
	
  	
  	
  	
  	
  	
  	
  item.Deactivate();	
  
	
  	
  	
  }	
  
Back	
  to	
  the	
  same	
  problem!	
  
 public	
  static	
  int	
  Add(int	
  a,	
  int	
  b)	
  
	
  {	
  
	
  	
  	
  	
  	
  return	
  a	
  +	
  b;	
  
	
  }	
  
	
  
 public	
  static	
  int	
  Add(int	
  a,	
  int	
  b)	
  
	
  {	
  
	
  	
  	
  	
  	
  return	
  a	
  +	
  b;	
  
	
  }	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  var	
  add5	
  =	
  x	
  =>	
  Add(5,	
  x);	
  
	
  
 public	
  static	
  void	
  Deactivate(ItemRepository	
  repository,	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  DeactivateCommand	
  c)	
  
	
  {	
  
	
  	
  	
  	
  	
  var	
  item	
  =	
  repository.GetById(c.id);	
  
	
  	
  	
  	
  	
  item.Deactivate();	
  
	
  }	
  	
  
	
  
	
  
	
  	
  
	
  	
  	
  
	
  
 public	
  static	
  void	
  Deactivate(ItemRepository	
  repository,	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  DeactivateCommand	
  c)	
  
	
  {	
  
	
  	
  	
  	
  	
  var	
  item	
  =	
  repository.GetById(c.id);	
  
	
  	
  	
  	
  	
  item.Deactivate();	
  
	
  }	
  	
  
	
  
	
  
	
  	
  
	
  	
  	
  
	
  	
  	
  	
  	
  var	
  nodepends	
  =	
  x	
  =>	
  Deactivate(new	
  ItemRepository(),	
  x);	
  
	
  
 	
  
	
  
	
  
	
  
	
  
	
  
	
  void	
  BootStrap()	
  
	
  {	
  
	
  	
  	
  	
  handlers.Add(x	
  =>	
  Deactivate(new	
  ItemRepository(),	
  x));	
  
	
  	
  	
  	
  handlers.Add(x	
  =>	
  Reactivate(new	
  ItemRepository(),	
  x));	
  
	
  	
  	
  	
  handlers.Add(x	
  =>	
  CheckIn(new	
  ItemRepository(),	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  new	
  BarService(),	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  x));	
  
	
  }	
  
 	
  
	
  
	
  
	
  
	
  
	
  
	
  void	
  BootStrap()	
  
	
  {	
  
	
  	
  	
  	
  handlers.Add(x	
  =>	
  Deactivate(()	
  =>	
  new	
  ItemRepository(),	
  x));	
  
	
  	
  	
  	
  handlers.Add(x	
  =>	
  Reactivate(()	
  =>	
  new	
  ItemRepository(),	
  x));	
  
	
  	
  	
  	
  handlers.Add(x	
  =>	
  CheckIn(()	
  =>	
  new	
  ItemRepository(),	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  new	
  BarService(),	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  x));	
  
	
  }	
  
 	
  
	
  
	
  
	
  
	
  
	
  
	
  public	
  static	
  void	
  Log<T>(T	
  command,	
  Action<T>	
  next)	
  	
  
	
  	
  	
  where	
  T:Command	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  myLoggingFramework.Log(command);	
  
	
  	
  	
  	
  	
  	
  	
  	
  next(command);	
  
	
  	
  	
  	
  }	
  
 class	
  LoggingHandler<T>	
  	
  :	
  Handles<T>	
  where	
  T:Command	
  
	
  {	
  
	
  	
  	
  	
  	
  private	
  readonly	
  Handles<T>	
  next;	
  
	
  
	
  	
  	
  	
  	
  public	
  LoggingHandler(Handles<T>	
  next)	
  
	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  this.next	
  =	
  next;	
  
	
  	
  	
  	
  	
  }	
  
	
  
	
  	
  	
  	
  	
  public	
  void	
  Handle(T	
  command)	
  
	
  	
  	
  	
  	
  {	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  myLoggingFramework.Log(command);	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  next.Handle(command);	
  
	
  	
  	
  	
  	
  }	
  
	
  }	
  
	
  
	
  	
  
	
  	
  var	
  handler	
  =	
  new	
  LoggingHandler<DeactivateCommand>(	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  new	
  DeactivateCommandHandler(...)	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  );	
  
	
  
<bean	
  id="moreComplexObject"	
  class="example.ComplexObject">	
  
	
  <!-­‐-­‐	
  results	
  in	
  a	
  setAdminEmails(java.uNl.ProperNes)	
  call	
  -­‐-­‐>	
  
	
  <property	
  name="adminEmails">	
  
	
  	
  	
  <props>	
  
	
  	
  	
  	
  	
  <prop	
  key="administrator">administrator@example.org</prop>	
  
	
  	
  	
  	
  	
  <prop	
  key="support">support@example.org</prop>	
  
	
  	
  	
  	
  	
  <prop	
  key="development">development@example.org</prop>	
  
	
  	
  	
  </props>	
  
	
  </property>	
  
	
  <!-­‐-­‐	
  results	
  in	
  a	
  setSomeList(java.uNl.List)	
  call	
  -­‐-­‐>	
  
	
  <property	
  name="someList">	
  
	
  	
  	
  <list>	
  
	
  	
  	
  	
  	
  <value>a	
  list	
  element	
  followed	
  by	
  a	
  reference</value>	
  
	
  	
  	
  	
  	
  <ref	
  bean="myDataSource"	
  />	
  
	
  	
  	
  </list>	
  
	
  </property>	
  
	
  <!-­‐-­‐	
  results	
  in	
  a	
  setSomeMap(java.uNl.Map)	
  call	
  -­‐-­‐>	
  
	
  <property	
  name="someMap">	
  
	
  	
  	
  <map>	
  
	
  	
  	
  	
  	
  <entry	
  key="an	
  entry"	
  value="just	
  some	
  string"/>	
  
	
  	
  	
  	
  	
  <entry	
  key	
  ="a	
  ref"	
  value-­‐ref="myDataSource"/>	
  
	
  	
  	
  </map>	
  
 	
  
	
  
	
  
	
  
	
  
	
  
	
  public	
  static	
  void	
  Log<T>(T	
  command,	
  Action<T>	
  next)	
  	
  
	
  	
  	
  where	
  T:Command	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  myLoggingFramework.Log(command);	
  
	
  	
  	
  	
  	
  	
  	
  	
  next(command);	
  
	
  	
  	
  	
  }	
  
Understand	
  the	
  problem	
  a	
  tool	
  
or	
  idea	
  solves	
  well	
  
If	
  you	
  need	
  to	
  add	
  stuff	
  to	
  your	
  
IDE	
  you	
  are	
  probably	
  on	
  the	
  wrong	
  
path.	
  
You	
  own	
  all	
  code	
  in	
  your	
  project.	
  
	
  
	
  
	
  
	
  
Your	
  boss	
  doesn’t	
  care	
  if	
  the	
  bug	
  
happened	
  in	
  someone	
  else’s	
  library!	
  

Weitere ähnliche Inhalte

Mehr von C4Media

Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsC4Media
 
Kafka Needs No Keeper
Kafka Needs No KeeperKafka Needs No Keeper
Kafka Needs No KeeperC4Media
 
High Performing Teams Act Like Owners
High Performing Teams Act Like OwnersHigh Performing Teams Act Like Owners
High Performing Teams Act Like OwnersC4Media
 
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaDoes Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaC4Media
 
Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideC4Media
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDC4Media
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine LearningC4Media
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at SpeedC4Media
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsC4Media
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsC4Media
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerC4Media
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleC4Media
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeC4Media
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereC4Media
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing ForC4Media
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data EngineeringC4Media
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreC4Media
 
Navigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery TeamsNavigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery TeamsC4Media
 
High Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in AdtechHigh Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in AdtechC4Media
 
Rust's Journey to Async/await
Rust's Journey to Async/awaitRust's Journey to Async/await
Rust's Journey to Async/awaitC4Media
 

Mehr von C4Media (20)

Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java Applications
 
Kafka Needs No Keeper
Kafka Needs No KeeperKafka Needs No Keeper
Kafka Needs No Keeper
 
High Performing Teams Act Like Owners
High Performing Teams Act Like OwnersHigh Performing Teams Act Like Owners
High Performing Teams Act Like Owners
 
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaDoes Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
 
Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate Guide
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CD
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine Learning
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at Speed
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep Systems
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.js
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix Scale
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's Edge
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home Everywhere
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing For
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data Engineering
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
 
Navigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery TeamsNavigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery Teams
 
High Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in AdtechHigh Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in Adtech
 
Rust's Journey to Async/await
Rust's Journey to Async/awaitRust's Journey to Async/await
Rust's Journey to Async/await
 

Kürzlich hochgeladen

Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Kürzlich hochgeladen (20)

Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Parallel Keynote: 8 Lines of Code

  • 1. 8  Lines  of  Code   Greg  Young  
  • 2. InfoQ.com: News & Community Site • 750,000 unique visitors/month • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • News 15-20 / week • Articles 3-4 / week • Presentations (videos) 12-15 / week • Interviews 2-3 / week • Books 1 / month Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations /8-lines-code-refactoring
  • 3. Presented at QCon London www.qconlondon.com Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide
  • 5. I  am  stupid  to  work  otherwise.   Fancy  code  befuddles  me.  
  • 6.  public  class  DeactivateInventoryItem    {          private  readonly  ItemRepository  repository;            public  DeactivateInventoryItem(ItemRepository  repository)          {                  this.repository  =  repository;          }            public  void  Deactivate(Guid  id,  string  reason)          {                  var  item  =  repository.GetById(id);                  item.Deactivate(reason);                  repository.Save(item);          }    }  
  • 7.  [Transactional]    [RequiresPermission(“admin”)]    [Logged]    [EatsExceptions]    [DoesBadThingsWhenYouArentWatching]    public  class  DeactivateInventoryItem    {          private  readonly  ItemRepository  repository;            public  DeactivateInventoryItem(ItemRepository  repository)          {                  this.repository  =  repository;          }            public  void  Deactivate(Guid  id,  string  reason)          {                  var  item  =  repository.GetById(id);                  item.Deactivate(reason);          }    }  
  • 9. <bean  id="moreComplexObject"  class="example.ComplexObject">    <!-­‐-­‐  results  in  a  setAdminEmails(java.uNl.ProperNes)  call  -­‐-­‐>    <property  name="adminEmails">        <props>            <prop  key="administrator">administrator@example.org</prop>            <prop  key="support">support@example.org</prop>            <prop  key="development">development@example.org</prop>        </props>    </property>    <!-­‐-­‐  results  in  a  setSomeList(java.uNl.List)  call  -­‐-­‐>    <property  name="someList">        <list>            <value>a  list  element  followed  by  a  reference</value>            <ref  bean="myDataSource"  />        </list>    </property>    <!-­‐-­‐  results  in  a  setSomeMap(java.uNl.Map)  call  -­‐-­‐>    <property  name="someMap">        <map>            <entry  key="an  entry"  value="just  some  string"/>            <entry  key  ="a  ref"  value-­‐ref="myDataSource"/>        </map>  
  • 10.  [Transactional]    [RequiresPermission(“admin”)]    [Logged]    [EatsExceptions]    [DoesBadThingsWhenYouArentWatching]    public  class  DeactivateInventoryItem    {          private  readonly  ItemRepository  repository;            public  DeactivateInventoryItem(ItemRepository  repository)          {                  this.repository  =  repository;          }            public  void  Deactivate(Guid  id,  string  reason)          {                  var  item  =  repository.GetById(id);                  item.Deactivate(reason);          }    }  
  • 11.  [Transactional]    [RequiresPermission(“admin”)]    [Logged]    [EatsExceptions]    [DoesBadThingsWhenYouArentWatching]    public  class  DeactivateInventoryItem    {          private  readonly  ItemRepository  repository;            public  DeactivateInventoryItem(ItemRepository  repository)          {                  this.repository  =  repository;          }            public  virtual  void  Deactivate(Guid  id,  string  reason)          {                  var  item  =  repository.GetById(id);                  item.Deactivate(reason);          }    }  
  • 12.  public  object  Foo()    {            return  this;    }  
  • 13.
  • 14. If  you  find  you  need  an  extension   to  your  ide  to  understand  what’s   going  on.  Its  probably  not  simple.  
  • 15. What’s  the  root  of  the  problem?  
  • 16.          public  void  Deactivate(Guid  id,  string  reason)          {                  var  item  =  repository.GetById(id);                  item.Deactivate();          }                public  void  Reactivate(Guid  id,  DateTime  effective,                                                          string  reason)          {                  var  item  =  repository.GetById(id);                  item.Deactivate();          }                public  void  CheckIn(Guid  id,  int  count)          {                  var  item  =  repository.GetById(id);                  item.Deactivate();          }      
  • 18.          public  void  Log(PointCut  calledOn)          {                  logger.Log(calledOn.Name  +  “:”  +  calledOn.Parameters);                }          
  • 19.          public  void  Handle(DeactivateCommand  c)          {                  var  item  =  repository.GetById(c.id);                  item.Deactivate();          }                public  void  Handle(ReactivateCommand  c)          {                  var  item  =  repository.GetById(c.id);                  item.Reactivate();          }                public  void  Handle(CheckInCommand  c)          {                  var  item  =  repository.GetById(c.id);                  item.CheckIn(c.quantity);          }        
  • 20.    interface  Handles<T>  where  T:Command    {            void  Handle(T  command);                  }        
  • 21.  class  LoggingHandler<T>    :  Handles<T>  where  T:Command    {            private  readonly  Handles<T>  next;              public  LoggingHandler(Handles<T>  next)            {                    this.next  =  next;            }              public  void  Handle(T  command)            {                      myLoggingFramework.Log(command);                    next.Handle(command);            }    }            var  handler  =  new  LoggingHandler<DeactivateCommand>(                                              new  DeactivateCommandHandler(...)                                      );    
  • 22.
  • 23.  public  class  DeactivateInventoryItem  :Handles<DeactivateCommand>    {            private  readonly  ItemRepository  repository;              public  DeactivateInventoryItem(ItemRepository  repository)                  {                          this.repository  =  repository;                  }                    public  void  Handle(DeactivateCommand  command)                  {                          var  item  =  repository.GetById(command.id);                          item.Deactivate(cmd.Reason);                          }          }  
  • 24.  public  class  DeactivateInventoryItem  :Handles<DeactivateCommand>    {            private  readonly  ItemRepository  repository;              public  DeactivateInventoryItem(ItemRepository  repository)            {                          this.repository  =  repository;            }              public  void  Handle(DeactivateCommand  command)            {                          var  item  =  repository.GetById(command.id);                          item.Deactivate(cmd.Reason);                    }    }  
  • 25.  class  Handlers    {        public  static  void  Handle(ItemRepository  repository,                                                            DeactivateCommand  c)        {                var  item  =  repository.GetById(c.id);                item.Deactivate();        }          public  static  void  Handle(ItemRepository  repository,                                                              ReactivateCommand  c)        {                var  item  =  repository.GetById(c.id);                item.Deactivate();        }          public  static  void  Handle(ItemRepository  repository,                                                              CheckInCommand  c)        {                var  item  =  repository.GetById(c.id);                item.Deactivate();        }  
  • 26. Back  to  the  same  problem!  
  • 27.  public  static  int  Add(int  a,  int  b)    {            return  a  +  b;    }    
  • 28.  public  static  int  Add(int  a,  int  b)    {            return  a  +  b;    }                                                var  add5  =  x  =>  Add(5,  x);    
  • 29.  public  static  void  Deactivate(ItemRepository  repository,                                                        DeactivateCommand  c)    {            var  item  =  repository.GetById(c.id);            item.Deactivate();    }                    
  • 30.  public  static  void  Deactivate(ItemRepository  repository,                                                        DeactivateCommand  c)    {            var  item  =  repository.GetById(c.id);            item.Deactivate();    }                            var  nodepends  =  x  =>  Deactivate(new  ItemRepository(),  x);    
  • 31.                void  BootStrap()    {          handlers.Add(x  =>  Deactivate(new  ItemRepository(),  x));          handlers.Add(x  =>  Reactivate(new  ItemRepository(),  x));          handlers.Add(x  =>  CheckIn(new  ItemRepository(),                                                                new  BarService(),                                                                x));    }  
  • 32.                void  BootStrap()    {          handlers.Add(x  =>  Deactivate(()  =>  new  ItemRepository(),  x));          handlers.Add(x  =>  Reactivate(()  =>  new  ItemRepository(),  x));          handlers.Add(x  =>  CheckIn(()  =>  new  ItemRepository(),                                                                new  BarService(),                                                                x));    }  
  • 33.                public  static  void  Log<T>(T  command,  Action<T>  next)          where  T:Command          {                  myLoggingFramework.Log(command);                  next(command);          }  
  • 34.  class  LoggingHandler<T>    :  Handles<T>  where  T:Command    {            private  readonly  Handles<T>  next;              public  LoggingHandler(Handles<T>  next)            {                    this.next  =  next;            }              public  void  Handle(T  command)            {                      myLoggingFramework.Log(command);                    next.Handle(command);            }    }            var  handler  =  new  LoggingHandler<DeactivateCommand>(                                              new  DeactivateCommandHandler(...)                                      );    
  • 35. <bean  id="moreComplexObject"  class="example.ComplexObject">    <!-­‐-­‐  results  in  a  setAdminEmails(java.uNl.ProperNes)  call  -­‐-­‐>    <property  name="adminEmails">        <props>            <prop  key="administrator">administrator@example.org</prop>            <prop  key="support">support@example.org</prop>            <prop  key="development">development@example.org</prop>        </props>    </property>    <!-­‐-­‐  results  in  a  setSomeList(java.uNl.List)  call  -­‐-­‐>    <property  name="someList">        <list>            <value>a  list  element  followed  by  a  reference</value>            <ref  bean="myDataSource"  />        </list>    </property>    <!-­‐-­‐  results  in  a  setSomeMap(java.uNl.Map)  call  -­‐-­‐>    <property  name="someMap">        <map>            <entry  key="an  entry"  value="just  some  string"/>            <entry  key  ="a  ref"  value-­‐ref="myDataSource"/>        </map>  
  • 36.                public  static  void  Log<T>(T  command,  Action<T>  next)          where  T:Command          {                  myLoggingFramework.Log(command);                  next(command);          }  
  • 37. Understand  the  problem  a  tool   or  idea  solves  well  
  • 38. If  you  need  to  add  stuff  to  your   IDE  you  are  probably  on  the  wrong   path.  
  • 39. You  own  all  code  in  your  project.           Your  boss  doesn’t  care  if  the  bug   happened  in  someone  else’s  library!