Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/14ExI0I.
Greg Young discusses eight lines of very common code finding in them massive numbers of dependencies and difficulties, looking for ways to get rid of them. Filmed at qconlondon.com.
Greg Young is an independent consultant and entrepreneur. He is always involved with many concurrent projects, currently these include building out a distributed event store and mighty moose (a continuous test runner). For periods of years Greg has been known to stop living anywhere and just travel. Twitter: @gregyoung
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
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);
}
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();
}
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);