SlideShare a Scribd company logo
PRESENTED BY
Daniel Fisher
CONTACT US
daniel.fisher@devcoach.com
dc
EFFECTIVE, LOOSLY COUPLED
Writing better code with C#
LENNYBACON.COM
Daniel Fisher | CTO & Software Architect
CCD mit MCP, MCTS, MCPD…
daniel.fisher@devcoach.com
Mit-Gründer und Geschäftsführer von devcoach.com
www.devcoach.com
Mit-Gründer und Vorstand der
gemeinnützigen www.just community.de e.V.
Veranstalter des größten Entwickler & IT-Pro
Community Events in Deutschland: www.nrwconf.de
Mit-Gründer und Leiter der
INETA Usergroup Düsseldorf
www.NetUG-NiederRhein.de
Mitglied im Microsoft
Community Leader & Insider Program (CLIP)
Connected Systems Advisory Board
Expertengruppe für WCF, WF & BizTalk
DEVCOACH.COM
• Leistungen
– Architektur-Beratung
• Strukturierter und effizienter zu einer wartbaren Anwendung.
– Prozessoptimierung
• BPM
• FDD, TDD, MSF Agile & SCRUM
– Software-Entwicklung
• Team-out-of-the-box (Near-shoring)
• Objektmodelle und Datenzugriff
• Kommunikations-Infrastrukturen
• Identitäts- und Berechtigungsmodelle
• Web 2.0 und Rich Internet Applikation
– Coaching & Training
• Technologien schneller verstehen und richtig einsetzen.
• Technologien
– Microsoft Windows & .NET Framework
• ASP.NET, WCF, WF, WPF, Silverlight & Geneva
• Kunden
– Versicherung, Finanzindustrie, Mittelstand, Handel, Kommunikation,
Softwarehersteller u.v.a.
• Bundesamt für Sicherheit in der Informationstechnologie, Microsoft,
Dresdner Bank…
Project
Experience
Technology
Know-how
devcoach®
AGENDA
• Loose Koppelung
• Konzepte
• Code
LOOSE KOPPELUNG
WHAT IS BAD DESIGN?
"That's not the way I would have done it..."
Well, that is not a valid measure for the
quality of the design!
This statement is purely based on personal
preferences.
WHAT IS BAD DESIGN?
• Rigid:
– it's hard to change a part of the system without affection
too many other parts of the system
• Fragile:
– when making a change, unexpected parts of the system
break
• Immobile:
– it is hard to reuse it in another application because it cannot
be disentangled from the current application.
THE "OBJECT-STYLE"
PetSearch
PetSearchResultList
PetSearchResult
QUESTION?
• Are you telling me that every screen the app
has, there is a different object?
• No, but …
– Define your objects like they are "viewed" in the
application.
KONZEPTE
DESIGN GOALS
• There are several design goals
– Reusability
– Maintainability
– Performance
– Scalability
– …
• Make decisions on the goals of you application!
WHY MAINTAINABILITY?
• The most expensive and time-consuming work of software
development is the work of finding bugs and fixing them.
– In the U.S. the number of bugs … averages five per function point.
– The cost of finding and repairing these defects averages about 35
percent of the total development cost of building the application.
– The schedule time required is about 30 percent of project development
schedules.
• Defect repair costs and schedules are often larger than
coding costs and schedules.
Capers Jones, Estimating Software Costs
http://www.amazon.com/Estimating-Software-Costs-Capers-Jones/dp/0071483004/
COMPOSITION OVER INHERITANCE
Person
Employee
Person Employee
COMPOSITION OVER INHERITANCE
Person
Employee
Person Contract
Company
FRAGILE BASE CLASS
• A fundamental architectural problem problem
of OOP
• Base classes (superclasses) are considered
"fragile"
– Modifications to a base class may cause derived
classes to malfunction.
– The programmer cannot determine whether a base
class change is safe simply by examining in isolation
the methods of the base class.
• Solutions: "sealed" and "non-virtual"
http://en.wikipedia.org/wiki/Fragile_base_class
COMPOSITION ADVANTAGES
• More flexibility
• Much more resilient to change
– When used properly :-)
• Where inheritance represents the relationship
with the most coupling between two classes,
composition allows us to freely decouple two
(or more) classes.
INHERITANCE SAMPLE
public class SqlRoleProvider
{
…
}
public class CachedSqlRoleProvider
: SqlRoleProvider
{
public override string[] GetAllRoles()
{
//TODO: Get from Cache and return
var roles = base.GetAllRoles()
//TODO: Fill Cache
return roles;
}
}
SOLID DESING…
• Single Responsibility Principle
• Open Closed Principle
• Liskov Substitution Principle
• Interface Segregation Principle
• Dependency Inversion Principle
SINGLE RESPONSIBILITY PRINCIPLE
• A class should have one, and only one, reason to
change.
• "Separation of concerns"
OPEN CLOSE PRINCIPLE
• You should be able to extend a classes behavior,
without modifying it.
– Keep public interfaces reduced to the neccessary…
• All member fields private.
• No Global Variables -- Ever.
LISKOV SUBSTITUTION PRINCIPLE
• Derived classes must be substitutable for their
base classes.
IMAGINE FOLLOWING
public class Rectangle
{
public void SetWidth(double w) { itsWidth=w; }
public void SetHeight(double h) { itsHeight=w; }
public double GetHeight() { return itsHeight; }
public double GetWidth() { return itsWidth; }
private double itsWidth;
private double itsHeight;
};
NOW THIS …
public class Square
: Rectangle
{
new void SetWidth(double w)
{
base.SetWidth(w);
base.SetHeight(w);
}
new void SetHeight(double h)
{
base.SetHeight(h);
base.SetWidth(h);
}
}
WHAT WILL HAPPEN HERE?
public void f(Rectangle r)
{
r.SetWidth(32);
}
AND HERE?
void f<TObj>(TObj r)
where T: Rectangle
{
r.SetWidth(32);
}
ENABLE EXTENSION…
public class Rectangle
{
public void virtual SetWidth(double w) { itsWidth=w; }
public void virtual SetHeight(double h) { itsHeight=w;}
public double GetHeight() { return itsHeight; }
public double GetWidth() { return itsWidth; }
private double itsWidth;
private double itsHeight;
};
INTERFACE SEGREGATION PRINCIPLE
• Make fine grained interfaces that are client
specific.
IMAGINE FOLLOWING
public interface IRectangle
{
void SetWidth(double w);
void SetHeight(double h);
double GetHeight();
double GetWidth();
};
VS. THAT
public interface IRectangle
{
double GetHeight();
double GetWidth();
};
public interface IEditableRectangle
{
void SetWidth(double w);
void SetHeight(double h);
};
DEPENDENCY INVERSION PRINCIPLE
• Depend on abstractions, not on concretions.
IMAGINE FOLLOWING
public class Lamp
{
public void TurnOff();
public void TurnOn();
};
public class Button
{
private Lamp _lamp;
public Button(Lamp lamp) { _lamp = lamp; }
public void Detect()
{
if (GetPhysicalState()) _lamp.TurnOn(); return;
_lamp.TurnOff();
}
public bool GetPhysicalState(){ return Clicked;}
};
VS. THAT
public class ButtonClient
{
public void TurnOff();
public void TurnOn();
}
public class Lamp : ButtonClient
{
//The button client allows us to re-use the button...
}
public class Button
{
private ButtonClient _client;
public Button(ButtonClient client) { _client = client; }
public void Detect()
{
if (GetPhysicalState()) _client.TurnOn(); return;
_client.TurnOff();
}
public bool GetPhysicalState();
};
INVERSION OF CONTROL
• Constructor Injection
• Method Injection
• Property Injection
• Configuration Injection
– Dependency Object Container
MICROSOFT AND IOC...
public interface IServiceProvider
{
object GetService(Type serviceType);
}
public interface IServiceLocator
: IServiceProvider
{
GetAllInstances<TService>();
IEnumerable<object> GetAllInstances(Type serviceType);
TService GetInstance<TService>();
TService GetInstance<TService>(string key);
object GetInstance(Type serviceType);
object GetInstance(Type serviceType, string key);
}
SIMPLE DESIGN
“Simplicity is more complicated than you think.
But it’s well worth it.”
• Satisfy requirements
– No Less
– No more
• Shape units
DIVIDE AND CONQUER
„recursively breaking down a problem into two
or more sub-problems of the same (or related)
type, until these become simple enough to be
solved directly. “
„ The solutions to the sub-problems are then
combined to give a solution to the original
problem. “
CREATE ASSEMBLIES WISELY
• More assemblies = more physical stuff
– Build, configuration, Deployment, File IO…
• Who will pay that?
• But necessary for:
– Product Separation?
– Different Liceses models?
SIMPLE DESIGN CRITERIA
• The code …
– Fulfills the requirements.
• YAGNI
– Has the smallest number of classes.
• FxCop Rule: At least 3 members per class.
– Has the smallest number of methods
• Keep your methods maintainable.
– At maximum 50 lines
– At least 80 chars
– …
SOLID References
• http://www.objectmentor.com/resources/articles
/srp.pdf
• http://www.objectmentor.com/resources/articles
/ocp.pdf
• http://www.objectmentor.com/resources/articles
/lsp.pdf
• http://www.objectmentor.com/resources/articles
/isp.pdf
• http://www.objectmentor.com/resources/articles
/dip.pdf

More Related Content

Viewers also liked

.NET Developer Days 2015, PL: Defensive programming, resilience patterns & an...
.NET Developer Days 2015, PL: Defensive programming, resilience patterns & an....NET Developer Days 2015, PL: Defensive programming, resilience patterns & an...
.NET Developer Days 2015, PL: Defensive programming, resilience patterns & an...
Daniel Fisher
 
2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und build2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und build
Daniel Fisher
 
2010 - Basta!: REST mit ASP.NET MVC
2010 - Basta!: REST mit ASP.NET MVC2010 - Basta!: REST mit ASP.NET MVC
2010 - Basta!: REST mit ASP.NET MVC
Daniel Fisher
 
2011 - Dotnet Information Day: NUGET
2011 - Dotnet Information Day: NUGET2011 - Dotnet Information Day: NUGET
2011 - Dotnet Information Day: NUGET
Daniel Fisher
 
2008 - TechDays PT: Modeling and Composition for Software today and tomorrow
2008 - TechDays PT: Modeling and Composition for Software today and tomorrow2008 - TechDays PT: Modeling and Composition for Software today and tomorrow
2008 - TechDays PT: Modeling and Composition for Software today and tomorrow
Daniel Fisher
 
2011 - DNC: REST Wars
2011 - DNC: REST Wars2011 - DNC: REST Wars
2011 - DNC: REST Wars
Daniel Fisher
 
2007 - Basta!: Nach soa kommt soc
2007 - Basta!: Nach soa kommt soc2007 - Basta!: Nach soa kommt soc
2007 - Basta!: Nach soa kommt soc
Daniel Fisher
 
2015 TechSummit Web & Cloud - Gem, NPM, Bower, Nuget, Paket - Päckchen hier, ...
2015 TechSummit Web & Cloud - Gem, NPM, Bower, Nuget, Paket - Päckchen hier, ...2015 TechSummit Web & Cloud - Gem, NPM, Bower, Nuget, Paket - Päckchen hier, ...
2015 TechSummit Web & Cloud - Gem, NPM, Bower, Nuget, Paket - Päckchen hier, ...
Daniel Fisher
 
2008 - TechDays PT: Building Software + Services with Volta
2008 - TechDays PT: Building Software + Services with Volta2008 - TechDays PT: Building Software + Services with Volta
2008 - TechDays PT: Building Software + Services with Volta
Daniel Fisher
 
2006 - Basta!: Advanced server controls
2006 - Basta!: Advanced server controls2006 - Basta!: Advanced server controls
2006 - Basta!: Advanced server controls
Daniel Fisher
 
2009 - DNC: Silverlight ohne UI - Nur als Cache
2009 - DNC: Silverlight ohne UI - Nur als Cache2009 - DNC: Silverlight ohne UI - Nur als Cache
2009 - DNC: Silverlight ohne UI - Nur als Cache
Daniel Fisher
 
2005 - NRW Conf: Design, Entwicklung und Tests
2005 - NRW Conf: Design, Entwicklung und Tests2005 - NRW Conf: Design, Entwicklung und Tests
2005 - NRW Conf: Design, Entwicklung und Tests
Daniel Fisher
 
2008 - Basta!: DAL DIY
2008 - Basta!: DAL DIY2008 - Basta!: DAL DIY
2008 - Basta!: DAL DIY
Daniel Fisher
 
Saturation vs satisfaction in it industry
Saturation vs satisfaction in it industrySaturation vs satisfaction in it industry
Saturation vs satisfaction in it industry
Chirabrata Majumder
 
2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...
2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...
2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...
Daniel Fisher
 
2014 - DotNetCologne: Build, Builder, Am Buildesten
2014 - DotNetCologne: Build, Builder, Am Buildesten2014 - DotNetCologne: Build, Builder, Am Buildesten
2014 - DotNetCologne: Build, Builder, Am Buildesten
Daniel Fisher
 
2005 - .NET Chaostage: 1st class data driven applications with ASP.NET 2.0
2005 - .NET Chaostage: 1st class data driven applications with ASP.NET 2.02005 - .NET Chaostage: 1st class data driven applications with ASP.NET 2.0
2005 - .NET Chaostage: 1st class data driven applications with ASP.NET 2.0Daniel Fisher
 
2014 - DotNet UG Rhen Ruhr: Komponentenorientierung
2014 - DotNet UG Rhen Ruhr: Komponentenorientierung2014 - DotNet UG Rhen Ruhr: Komponentenorientierung
2014 - DotNet UG Rhen Ruhr: Komponentenorientierung
Daniel Fisher
 
2013 - ICE Lingen: AngularJS introduction
2013 - ICE Lingen: AngularJS introduction2013 - ICE Lingen: AngularJS introduction
2013 - ICE Lingen: AngularJS introduction
Daniel Fisher
 

Viewers also liked (20)

.NET Developer Days 2015, PL: Defensive programming, resilience patterns & an...
.NET Developer Days 2015, PL: Defensive programming, resilience patterns & an....NET Developer Days 2015, PL: Defensive programming, resilience patterns & an...
.NET Developer Days 2015, PL: Defensive programming, resilience patterns & an...
 
2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und build2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und build
 
2010 - Basta!: REST mit ASP.NET MVC
2010 - Basta!: REST mit ASP.NET MVC2010 - Basta!: REST mit ASP.NET MVC
2010 - Basta!: REST mit ASP.NET MVC
 
2011 - Dotnet Information Day: NUGET
2011 - Dotnet Information Day: NUGET2011 - Dotnet Information Day: NUGET
2011 - Dotnet Information Day: NUGET
 
2008 - TechDays PT: Modeling and Composition for Software today and tomorrow
2008 - TechDays PT: Modeling and Composition for Software today and tomorrow2008 - TechDays PT: Modeling and Composition for Software today and tomorrow
2008 - TechDays PT: Modeling and Composition for Software today and tomorrow
 
2011 - DNC: REST Wars
2011 - DNC: REST Wars2011 - DNC: REST Wars
2011 - DNC: REST Wars
 
2007 - Basta!: Nach soa kommt soc
2007 - Basta!: Nach soa kommt soc2007 - Basta!: Nach soa kommt soc
2007 - Basta!: Nach soa kommt soc
 
2015 TechSummit Web & Cloud - Gem, NPM, Bower, Nuget, Paket - Päckchen hier, ...
2015 TechSummit Web & Cloud - Gem, NPM, Bower, Nuget, Paket - Päckchen hier, ...2015 TechSummit Web & Cloud - Gem, NPM, Bower, Nuget, Paket - Päckchen hier, ...
2015 TechSummit Web & Cloud - Gem, NPM, Bower, Nuget, Paket - Päckchen hier, ...
 
2008 - TechDays PT: Building Software + Services with Volta
2008 - TechDays PT: Building Software + Services with Volta2008 - TechDays PT: Building Software + Services with Volta
2008 - TechDays PT: Building Software + Services with Volta
 
2006 - Basta!: Advanced server controls
2006 - Basta!: Advanced server controls2006 - Basta!: Advanced server controls
2006 - Basta!: Advanced server controls
 
2009 - DNC: Silverlight ohne UI - Nur als Cache
2009 - DNC: Silverlight ohne UI - Nur als Cache2009 - DNC: Silverlight ohne UI - Nur als Cache
2009 - DNC: Silverlight ohne UI - Nur als Cache
 
2005 - NRW Conf: Design, Entwicklung und Tests
2005 - NRW Conf: Design, Entwicklung und Tests2005 - NRW Conf: Design, Entwicklung und Tests
2005 - NRW Conf: Design, Entwicklung und Tests
 
2008 - Basta!: DAL DIY
2008 - Basta!: DAL DIY2008 - Basta!: DAL DIY
2008 - Basta!: DAL DIY
 
Saturation vs satisfaction in it industry
Saturation vs satisfaction in it industrySaturation vs satisfaction in it industry
Saturation vs satisfaction in it industry
 
2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...
2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...
2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...
 
Pļavu bibliotēka
Pļavu bibliotēkaPļavu bibliotēka
Pļavu bibliotēka
 
2014 - DotNetCologne: Build, Builder, Am Buildesten
2014 - DotNetCologne: Build, Builder, Am Buildesten2014 - DotNetCologne: Build, Builder, Am Buildesten
2014 - DotNetCologne: Build, Builder, Am Buildesten
 
2005 - .NET Chaostage: 1st class data driven applications with ASP.NET 2.0
2005 - .NET Chaostage: 1st class data driven applications with ASP.NET 2.02005 - .NET Chaostage: 1st class data driven applications with ASP.NET 2.0
2005 - .NET Chaostage: 1st class data driven applications with ASP.NET 2.0
 
2014 - DotNet UG Rhen Ruhr: Komponentenorientierung
2014 - DotNet UG Rhen Ruhr: Komponentenorientierung2014 - DotNet UG Rhen Ruhr: Komponentenorientierung
2014 - DotNet UG Rhen Ruhr: Komponentenorientierung
 
2013 - ICE Lingen: AngularJS introduction
2013 - ICE Lingen: AngularJS introduction2013 - ICE Lingen: AngularJS introduction
2013 - ICE Lingen: AngularJS introduction
 

Similar to 2009 Dotnet Information Day: More effective c#

OO Design and Design Patterns in C++
OO Design and Design Patterns in C++ OO Design and Design Patterns in C++
OO Design and Design Patterns in C++
Ganesh Samarthyam
 
Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Clean Code - Design Patterns and Best Practices at Silicon Valley Code CampClean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Theo Jungeblut
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
Iván Fernández Perea
 
L03 Software Design
L03 Software DesignL03 Software Design
L03 Software Design
Ólafur Andri Ragnarsson
 
PHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better CodePHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better Code
SWIFTotter Solutions
 
Developing SOLID Code
Developing SOLID CodeDeveloping SOLID Code
Developing SOLID Code
Mark Niebergall
 
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
Theo Jungeblut
 
Microservices Chaos Testing at Jet
Microservices Chaos Testing at JetMicroservices Chaos Testing at Jet
Microservices Chaos Testing at Jet
C4Media
 
Design for Testability
Design for TestabilityDesign for Testability
Design for Testability
Stanislav Tiurikov
 
SOLID & IoC Principles
SOLID & IoC PrinciplesSOLID & IoC Principles
SOLID & IoC Principles
Pavlo Hodysh
 
Reviewing OOP Design patterns
Reviewing OOP Design patternsReviewing OOP Design patterns
Reviewing OOP Design patterns
Olivier Bacs
 
Solid principle
Solid principleSolid principle
Solid principle
muhammadali0014
 
Lecture 2 software components ssssssss.pptx
Lecture 2 software components ssssssss.pptxLecture 2 software components ssssssss.pptx
Lecture 2 software components ssssssss.pptx
AhmedAlAfandi5
 
Object-oriented design principles
Object-oriented design principlesObject-oriented design principles
Object-oriented design principles
Xiaoyan Chen
 
Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...
Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...
Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...
DicodingEvent
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in Java
Ionut Bilica
 
SOLID
SOLIDSOLID
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
deonpmeyer
 

Similar to 2009 Dotnet Information Day: More effective c# (20)

OO Design and Design Patterns in C++
OO Design and Design Patterns in C++ OO Design and Design Patterns in C++
OO Design and Design Patterns in C++
 
Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Clean Code - Design Patterns and Best Practices at Silicon Valley Code CampClean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
L03 Software Design
L03 Software DesignL03 Software Design
L03 Software Design
 
PHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better CodePHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better Code
 
Developing SOLID Code
Developing SOLID CodeDeveloping SOLID Code
Developing SOLID Code
 
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
 
Microservices Chaos Testing at Jet
Microservices Chaos Testing at JetMicroservices Chaos Testing at Jet
Microservices Chaos Testing at Jet
 
Design Principles
Design PrinciplesDesign Principles
Design Principles
 
Design for Testability
Design for TestabilityDesign for Testability
Design for Testability
 
SOLID & IoC Principles
SOLID & IoC PrinciplesSOLID & IoC Principles
SOLID & IoC Principles
 
Reviewing OOP Design patterns
Reviewing OOP Design patternsReviewing OOP Design patterns
Reviewing OOP Design patterns
 
Solid principle
Solid principleSolid principle
Solid principle
 
Lecture 2 software components ssssssss.pptx
Lecture 2 software components ssssssss.pptxLecture 2 software components ssssssss.pptx
Lecture 2 software components ssssssss.pptx
 
Object-oriented design principles
Object-oriented design principlesObject-oriented design principles
Object-oriented design principles
 
Open event presentation.3 2
Open event presentation.3 2Open event presentation.3 2
Open event presentation.3 2
 
Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...
Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...
Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in Java
 
SOLID
SOLIDSOLID
SOLID
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
 

More from Daniel Fisher

MD DevdDays 2016: Defensive programming, resilience patterns & antifragility
MD DevdDays 2016: Defensive programming, resilience patterns & antifragilityMD DevdDays 2016: Defensive programming, resilience patterns & antifragility
MD DevdDays 2016: Defensive programming, resilience patterns & antifragility
Daniel Fisher
 
NRWConf, DE: Defensive programming, resilience patterns & antifragility
NRWConf, DE: Defensive programming, resilience patterns & antifragilityNRWConf, DE: Defensive programming, resilience patterns & antifragility
NRWConf, DE: Defensive programming, resilience patterns & antifragility
Daniel Fisher
 
2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...
2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...
2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...
Daniel Fisher
 
2011 - DotNetFranken: ASP.NET MVC Localization
2011 - DotNetFranken: ASP.NET MVC Localization2011 - DotNetFranken: ASP.NET MVC Localization
2011 - DotNetFranken: ASP.NET MVC Localization
Daniel Fisher
 
2011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 52011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 5
Daniel Fisher
 
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
Daniel Fisher
 
2010 - Basta!: IPhone Apps mit C#
2010 - Basta!: IPhone Apps mit C#2010 - Basta!: IPhone Apps mit C#
2010 - Basta!: IPhone Apps mit C#
Daniel Fisher
 
2010 - Basta: ASP.NET Controls für Web Forms und MVC
2010 - Basta: ASP.NET Controls für Web Forms und MVC2010 - Basta: ASP.NET Controls für Web Forms und MVC
2010 - Basta: ASP.NET Controls für Web Forms und MVC
Daniel Fisher
 
2010 Basta!: Massendaten mit ADO.NET
2010 Basta!: Massendaten mit ADO.NET2010 Basta!: Massendaten mit ADO.NET
2010 Basta!: Massendaten mit ADO.NET
Daniel Fisher
 
2009 - Basta!: Url rewriting mit iis, asp.net und routing engine
2009 - Basta!: Url rewriting mit iis, asp.net und routing engine2009 - Basta!: Url rewriting mit iis, asp.net und routing engine
2009 - Basta!: Url rewriting mit iis, asp.net und routing engine
Daniel Fisher
 
2009 - Basta!: Agiles requirements engineering
2009 - Basta!: Agiles requirements engineering2009 - Basta!: Agiles requirements engineering
2009 - Basta!: Agiles requirements engineering
Daniel Fisher
 
2008 - Basta!: Massendaten auf dem Client
2008 - Basta!: Massendaten auf dem Client2008 - Basta!: Massendaten auf dem Client
2008 - Basta!: Massendaten auf dem Client
Daniel Fisher
 
2008 - Afterlaunch: 10 Tipps für WCF
2008 - Afterlaunch: 10 Tipps für WCF2008 - Afterlaunch: 10 Tipps für WCF
2008 - Afterlaunch: 10 Tipps für WCF
Daniel Fisher
 
2006 - NRW Conf: Asynchronous asp.net
2006 - NRW Conf: Asynchronous asp.net2006 - NRW Conf: Asynchronous asp.net
2006 - NRW Conf: Asynchronous asp.net
Daniel Fisher
 
2006 - DDD4: Decoupling service oriented backend systems
2006 - DDD4: Decoupling service oriented backend systems2006 - DDD4: Decoupling service oriented backend systems
2006 - DDD4: Decoupling service oriented backend systemsDaniel Fisher
 

More from Daniel Fisher (15)

MD DevdDays 2016: Defensive programming, resilience patterns & antifragility
MD DevdDays 2016: Defensive programming, resilience patterns & antifragilityMD DevdDays 2016: Defensive programming, resilience patterns & antifragility
MD DevdDays 2016: Defensive programming, resilience patterns & antifragility
 
NRWConf, DE: Defensive programming, resilience patterns & antifragility
NRWConf, DE: Defensive programming, resilience patterns & antifragilityNRWConf, DE: Defensive programming, resilience patterns & antifragility
NRWConf, DE: Defensive programming, resilience patterns & antifragility
 
2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...
2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...
2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...
 
2011 - DotNetFranken: ASP.NET MVC Localization
2011 - DotNetFranken: ASP.NET MVC Localization2011 - DotNetFranken: ASP.NET MVC Localization
2011 - DotNetFranken: ASP.NET MVC Localization
 
2011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 52011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 5
 
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
 
2010 - Basta!: IPhone Apps mit C#
2010 - Basta!: IPhone Apps mit C#2010 - Basta!: IPhone Apps mit C#
2010 - Basta!: IPhone Apps mit C#
 
2010 - Basta: ASP.NET Controls für Web Forms und MVC
2010 - Basta: ASP.NET Controls für Web Forms und MVC2010 - Basta: ASP.NET Controls für Web Forms und MVC
2010 - Basta: ASP.NET Controls für Web Forms und MVC
 
2010 Basta!: Massendaten mit ADO.NET
2010 Basta!: Massendaten mit ADO.NET2010 Basta!: Massendaten mit ADO.NET
2010 Basta!: Massendaten mit ADO.NET
 
2009 - Basta!: Url rewriting mit iis, asp.net und routing engine
2009 - Basta!: Url rewriting mit iis, asp.net und routing engine2009 - Basta!: Url rewriting mit iis, asp.net und routing engine
2009 - Basta!: Url rewriting mit iis, asp.net und routing engine
 
2009 - Basta!: Agiles requirements engineering
2009 - Basta!: Agiles requirements engineering2009 - Basta!: Agiles requirements engineering
2009 - Basta!: Agiles requirements engineering
 
2008 - Basta!: Massendaten auf dem Client
2008 - Basta!: Massendaten auf dem Client2008 - Basta!: Massendaten auf dem Client
2008 - Basta!: Massendaten auf dem Client
 
2008 - Afterlaunch: 10 Tipps für WCF
2008 - Afterlaunch: 10 Tipps für WCF2008 - Afterlaunch: 10 Tipps für WCF
2008 - Afterlaunch: 10 Tipps für WCF
 
2006 - NRW Conf: Asynchronous asp.net
2006 - NRW Conf: Asynchronous asp.net2006 - NRW Conf: Asynchronous asp.net
2006 - NRW Conf: Asynchronous asp.net
 
2006 - DDD4: Decoupling service oriented backend systems
2006 - DDD4: Decoupling service oriented backend systems2006 - DDD4: Decoupling service oriented backend systems
2006 - DDD4: Decoupling service oriented backend systems
 

Recently uploaded

GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 

Recently uploaded (20)

GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 

2009 Dotnet Information Day: More effective c#

  • 1. PRESENTED BY Daniel Fisher CONTACT US daniel.fisher@devcoach.com dc EFFECTIVE, LOOSLY COUPLED Writing better code with C#
  • 2.
  • 3. LENNYBACON.COM Daniel Fisher | CTO & Software Architect CCD mit MCP, MCTS, MCPD… daniel.fisher@devcoach.com Mit-Gründer und Geschäftsführer von devcoach.com www.devcoach.com Mit-Gründer und Vorstand der gemeinnützigen www.just community.de e.V. Veranstalter des größten Entwickler & IT-Pro Community Events in Deutschland: www.nrwconf.de Mit-Gründer und Leiter der INETA Usergroup Düsseldorf www.NetUG-NiederRhein.de Mitglied im Microsoft Community Leader & Insider Program (CLIP) Connected Systems Advisory Board Expertengruppe für WCF, WF & BizTalk
  • 4. DEVCOACH.COM • Leistungen – Architektur-Beratung • Strukturierter und effizienter zu einer wartbaren Anwendung. – Prozessoptimierung • BPM • FDD, TDD, MSF Agile & SCRUM – Software-Entwicklung • Team-out-of-the-box (Near-shoring) • Objektmodelle und Datenzugriff • Kommunikations-Infrastrukturen • Identitäts- und Berechtigungsmodelle • Web 2.0 und Rich Internet Applikation – Coaching & Training • Technologien schneller verstehen und richtig einsetzen. • Technologien – Microsoft Windows & .NET Framework • ASP.NET, WCF, WF, WPF, Silverlight & Geneva • Kunden – Versicherung, Finanzindustrie, Mittelstand, Handel, Kommunikation, Softwarehersteller u.v.a. • Bundesamt für Sicherheit in der Informationstechnologie, Microsoft, Dresdner Bank… Project Experience Technology Know-how devcoach®
  • 5. AGENDA • Loose Koppelung • Konzepte • Code
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. WHAT IS BAD DESIGN? "That's not the way I would have done it..." Well, that is not a valid measure for the quality of the design! This statement is purely based on personal preferences.
  • 12. WHAT IS BAD DESIGN? • Rigid: – it's hard to change a part of the system without affection too many other parts of the system • Fragile: – when making a change, unexpected parts of the system break • Immobile: – it is hard to reuse it in another application because it cannot be disentangled from the current application.
  • 14.
  • 15.
  • 17. QUESTION? • Are you telling me that every screen the app has, there is a different object? • No, but … – Define your objects like they are "viewed" in the application.
  • 19. DESIGN GOALS • There are several design goals – Reusability – Maintainability – Performance – Scalability – … • Make decisions on the goals of you application!
  • 20. WHY MAINTAINABILITY? • The most expensive and time-consuming work of software development is the work of finding bugs and fixing them. – In the U.S. the number of bugs … averages five per function point. – The cost of finding and repairing these defects averages about 35 percent of the total development cost of building the application. – The schedule time required is about 30 percent of project development schedules. • Defect repair costs and schedules are often larger than coding costs and schedules. Capers Jones, Estimating Software Costs http://www.amazon.com/Estimating-Software-Costs-Capers-Jones/dp/0071483004/
  • 23. FRAGILE BASE CLASS • A fundamental architectural problem problem of OOP • Base classes (superclasses) are considered "fragile" – Modifications to a base class may cause derived classes to malfunction. – The programmer cannot determine whether a base class change is safe simply by examining in isolation the methods of the base class. • Solutions: "sealed" and "non-virtual" http://en.wikipedia.org/wiki/Fragile_base_class
  • 24. COMPOSITION ADVANTAGES • More flexibility • Much more resilient to change – When used properly :-) • Where inheritance represents the relationship with the most coupling between two classes, composition allows us to freely decouple two (or more) classes.
  • 25. INHERITANCE SAMPLE public class SqlRoleProvider { … } public class CachedSqlRoleProvider : SqlRoleProvider { public override string[] GetAllRoles() { //TODO: Get from Cache and return var roles = base.GetAllRoles() //TODO: Fill Cache return roles; } }
  • 26. SOLID DESING… • Single Responsibility Principle • Open Closed Principle • Liskov Substitution Principle • Interface Segregation Principle • Dependency Inversion Principle
  • 27. SINGLE RESPONSIBILITY PRINCIPLE • A class should have one, and only one, reason to change. • "Separation of concerns"
  • 28.
  • 29. OPEN CLOSE PRINCIPLE • You should be able to extend a classes behavior, without modifying it. – Keep public interfaces reduced to the neccessary… • All member fields private. • No Global Variables -- Ever.
  • 30.
  • 31. LISKOV SUBSTITUTION PRINCIPLE • Derived classes must be substitutable for their base classes.
  • 32. IMAGINE FOLLOWING public class Rectangle { public void SetWidth(double w) { itsWidth=w; } public void SetHeight(double h) { itsHeight=w; } public double GetHeight() { return itsHeight; } public double GetWidth() { return itsWidth; } private double itsWidth; private double itsHeight; };
  • 33. NOW THIS … public class Square : Rectangle { new void SetWidth(double w) { base.SetWidth(w); base.SetHeight(w); } new void SetHeight(double h) { base.SetHeight(h); base.SetWidth(h); } }
  • 34. WHAT WILL HAPPEN HERE? public void f(Rectangle r) { r.SetWidth(32); }
  • 35. AND HERE? void f<TObj>(TObj r) where T: Rectangle { r.SetWidth(32); }
  • 36. ENABLE EXTENSION… public class Rectangle { public void virtual SetWidth(double w) { itsWidth=w; } public void virtual SetHeight(double h) { itsHeight=w;} public double GetHeight() { return itsHeight; } public double GetWidth() { return itsWidth; } private double itsWidth; private double itsHeight; };
  • 37.
  • 38. INTERFACE SEGREGATION PRINCIPLE • Make fine grained interfaces that are client specific.
  • 39. IMAGINE FOLLOWING public interface IRectangle { void SetWidth(double w); void SetHeight(double h); double GetHeight(); double GetWidth(); };
  • 40. VS. THAT public interface IRectangle { double GetHeight(); double GetWidth(); }; public interface IEditableRectangle { void SetWidth(double w); void SetHeight(double h); };
  • 41.
  • 42. DEPENDENCY INVERSION PRINCIPLE • Depend on abstractions, not on concretions.
  • 43. IMAGINE FOLLOWING public class Lamp { public void TurnOff(); public void TurnOn(); }; public class Button { private Lamp _lamp; public Button(Lamp lamp) { _lamp = lamp; } public void Detect() { if (GetPhysicalState()) _lamp.TurnOn(); return; _lamp.TurnOff(); } public bool GetPhysicalState(){ return Clicked;} };
  • 44. VS. THAT public class ButtonClient { public void TurnOff(); public void TurnOn(); } public class Lamp : ButtonClient { //The button client allows us to re-use the button... } public class Button { private ButtonClient _client; public Button(ButtonClient client) { _client = client; } public void Detect() { if (GetPhysicalState()) _client.TurnOn(); return; _client.TurnOff(); } public bool GetPhysicalState(); };
  • 45.
  • 46. INVERSION OF CONTROL • Constructor Injection • Method Injection • Property Injection • Configuration Injection – Dependency Object Container
  • 47. MICROSOFT AND IOC... public interface IServiceProvider { object GetService(Type serviceType); } public interface IServiceLocator : IServiceProvider { GetAllInstances<TService>(); IEnumerable<object> GetAllInstances(Type serviceType); TService GetInstance<TService>(); TService GetInstance<TService>(string key); object GetInstance(Type serviceType); object GetInstance(Type serviceType, string key); }
  • 48. SIMPLE DESIGN “Simplicity is more complicated than you think. But it’s well worth it.” • Satisfy requirements – No Less – No more • Shape units
  • 49. DIVIDE AND CONQUER „recursively breaking down a problem into two or more sub-problems of the same (or related) type, until these become simple enough to be solved directly. “ „ The solutions to the sub-problems are then combined to give a solution to the original problem. “
  • 50. CREATE ASSEMBLIES WISELY • More assemblies = more physical stuff – Build, configuration, Deployment, File IO… • Who will pay that? • But necessary for: – Product Separation? – Different Liceses models?
  • 51. SIMPLE DESIGN CRITERIA • The code … – Fulfills the requirements. • YAGNI – Has the smallest number of classes. • FxCop Rule: At least 3 members per class. – Has the smallest number of methods • Keep your methods maintainable. – At maximum 50 lines – At least 80 chars – …
  • 52.
  • 53.
  • 54.
  • 55. SOLID References • http://www.objectmentor.com/resources/articles /srp.pdf • http://www.objectmentor.com/resources/articles /ocp.pdf • http://www.objectmentor.com/resources/articles /lsp.pdf • http://www.objectmentor.com/resources/articles /isp.pdf • http://www.objectmentor.com/resources/articles /dip.pdf