SlideShare uma empresa Scribd logo
1 de 34
Dennis van der Stelt
Interface Segregation Principle
Dependency Inversion Principle
Dennis van der Stelt
Software Architect
Tellus
http://bloggingabout.net/blogs/dennis/
@dvdstelt
dvdstelt@tellus.com
Pascal de Jonge
Development Lead
Tellus
http://www.pazquality.com/
@pdejonge
pdejonge@tellus.com
SOLID
Dennis van der Stelt
Dennis van der Stelt
AGENDA
Dennis van der Stelt
SOLID
History
Dennis van der Stelt
Guidance
Dennis van der Stelt
SOLID
Five principles
Single Responsibility SOLID Open/Closed
Liskov Substitution Interface Segregation
Learn them, love them, live by them…
Dependency Inversion
Dennis van der Stelt
SOLID
Books
Dennis van der Stelt
SOLID
Interface Segregation Principle
Dennis van der Stelt
INTERFACE SEGREGATION PRINCIPLE
clients should not be forced
to depend on methods
they do not use
Dennis van der Stelt
INTERFACE SEGREGATION PRINCIPLE
tailor interfaces to individual client’s needs
Dennis van der Stelt
DEMO
Membership Provider
Dennis van der Stelt
INTERFACE SEGREGATION PRINCIPLE
public interface IVerifyCredentials
{
int MaxInvalidPasswordAttempts { get; }
bool ValidateUser(string username, string password);
}
public interface IManageCredentials
{
bool ChangePassword(string oldPassword, string newPassword);
int MinRequiredNonAlphanumericCharacters { get; }
int MinRequiredPasswordLength { get; }
string ResetPassword(string username);
}
public interface IManageUsers
{
MembershipUser CreateUser(string username, string password);
bool DeleteUser(string username, bool deleteAllRelatedData);
}
Dennis van der Stelt
INTERFACE SEGREGATION PRINCIPLE
Why is violation of this principle a problem?
introduces very fat interfaces
difficult to extend functionality
violates single responsibility principle
forced dependencies
02
03
04
01
Dennis van der Stelt
public interface IDoor
{
bool IsDoorOpen { get; set; }
void Lock();
void Unlock();
}
INTERFACE SEGREGATION PRINCIPLE
public class SimpleDoor : IDoor
{
public bool IsDoorOpen { get; set; }
public void Lock()
{
// Implementation here...
}
public void Unlock()
{
// Implementation here...
}
}
Dennis van der Stelt
public interface ITimerFunction
{
void TimerFunction();
}
INTERFACE SEGREGATION PRINCIPLE
class AdvancedDoor : IDoor, ITimerFunction
{
public bool IsDoorOpen { get; set; }
public void Lock() { }
public void Unlock() { }
public void TimerFunction()
{
// Implementation here...
}
}
Dennis van der Stelt
List<IDoor> doors = new List<IDoor>()
{
new SimpleDoor(),
new AdvancedDoor()
};
foreach (var door in doors)
{
if (door is ITimerFunction)
((ITimerFunction)door).TimerFunction();
}
INTERFACE SEGREGATION PRINCIPLE
Dennis van der Stelt
SOLID
Dependency Inversion Principle
Dennis van der Stelt
DEPENDENCY INVERSION PRINCIPLE
high level modules should not
depend upon low level
modules, both should depend on
abstractions.
abstractions should not
depend upon details.
details should depend on
abstractions
Dennis van der Stelt
DEPENDENCY INVERSION PRINCIPLE
Inversion of control
Component A
Component B
Component C
Dennis van der Stelt
DEPENDENCY INVERSION PRINCIPLE
Inversion of control
Component A
Component A
Service
<<interface>>
Component B
Component A
Service
Component C
<<interface>>
Dennis van der Stelt
DEPENDENCY INVERSION PRINCIPLE
Inversion of control
Component A Client Service
<<interface>>
Component B
Component A
Service
Component C
<<interface>>
Component D
Dennis van der Stelt
DEPENDENCY INVERSION PRINCIPLE
Valar Morghulis
Dennis van der Stelt
DEMO
Game on!!!
Dennis van der Stelt
DEPENDENCY INVERSION PRINCIPLE
Violations
public class SecurityService
{
public static User GetCurrentUser()
{
return Context.User;
}
}
Dependency in static method
Dennis van der Stelt
DEPENDENCY INVERSION PRINCIPLE
Violations
public class OrderProcessing
{
private IList<Product> FindProduct(int category)
{
var repository = new ProductRepository();
return repository.FindByCategory(category);
}
}
Instantiating your own dependencies
Dennis van der Stelt
DEPENDENCY INVERSION PRINCIPLE
Violations
public class OrderProcessing
{
private IList<Product> FindProduct(int category)
{
var repository = ServiceLocator.GetInstance<IProductRepository>();
return repository.FindByCategory(category);
}
}
Asking for instantiating your dependencies
only at the composition root
Dennis van der Stelt
COMPOSITION ROOT
Application entry point
Factory Pattern
Libraries & Frameworks
Dennis van der Stelt
COMPOSITION ROOT
Application entry point
Factory Pattern
Libraries & Frameworks
Dennis van der Stelt
COMPOSITION ROOT
Application entry point
Factory Pattern
Libraries & Frameworks
Dennis van der Stelt
DEPENDENCY INVERSION PRINCIPLE
Inversion of control
HomeController
ICustomer
Registration
<<interface>>
Customer
Registration
IMessageSender
Factory
MessageSender
Factory
<<interface>>
ICustomer
Repository
<<interface>>
Customer
Repository
MessageSender
Base
Dennis van der Stelt
DEMO
Dependency Injection in MVC
Dennis van der Stelt
Dennis van der Stelt
CONCLUSION
Single Responsibility SOLID Open/Closed
Liskov Substitution Interface Seggregation Dependency Inversion
Dennis van der Stelt34
Thank you
questions?
Dennis van der Stelt
Software Architect
Tellus
http://bloggingabout.net/blogs/dennis/
@dvdstelt
dvdstelt@tellus.com
Pascal de Jonge
Development Lead
Tellus
http://www.pazquality.com/
@pdejonge
pdejonge@tellus.com

Mais conteúdo relacionado

Destaque

SOLID Principles and Design Patterns
SOLID Principles and Design PatternsSOLID Principles and Design Patterns
SOLID Principles and Design PatternsGanesh Samarthyam
 
Introduction to SOLID Principles
Introduction to SOLID PrinciplesIntroduction to SOLID Principles
Introduction to SOLID PrinciplesGanesh Samarthyam
 
Refactoring Applications using SOLID Principles
Refactoring Applications using SOLID PrinciplesRefactoring Applications using SOLID Principles
Refactoring Applications using SOLID PrinciplesSteven Smith
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design PrinciplesAndreas Enbohm
 
The SOLID Principles Illustrated by Design Patterns
The SOLID Principles Illustrated by Design PatternsThe SOLID Principles Illustrated by Design Patterns
The SOLID Principles Illustrated by Design PatternsHayim Makabee
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMSfawzmasood
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing SoftwareSteven Smith
 
Operator overloading
Operator overloadingOperator overloading
Operator overloadingfarhan amjad
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ AdvancedVivek Das
 
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...Complement Verb
 
Solid Software Design Principles
Solid Software Design PrinciplesSolid Software Design Principles
Solid Software Design PrinciplesJon Kruger
 
Do we need SOLID principles during software development?
Do we need SOLID principles during software development?Do we need SOLID principles during software development?
Do we need SOLID principles during software development?Anna Shymchenko
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL乐群 陈
 

Destaque (20)

SOLID Principles and Design Patterns
SOLID Principles and Design PatternsSOLID Principles and Design Patterns
SOLID Principles and Design Patterns
 
Introduction to SOLID Principles
Introduction to SOLID PrinciplesIntroduction to SOLID Principles
Introduction to SOLID Principles
 
Refactoring Applications using SOLID Principles
Refactoring Applications using SOLID PrinciplesRefactoring Applications using SOLID Principles
Refactoring Applications using SOLID Principles
 
SOLID Principles part 1
SOLID Principles part 1SOLID Principles part 1
SOLID Principles part 1
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
 
The SOLID Principles Illustrated by Design Patterns
The SOLID Principles Illustrated by Design PatternsThe SOLID Principles Illustrated by Design Patterns
The SOLID Principles Illustrated by Design Patterns
 
SOLID principles
SOLID principlesSOLID principles
SOLID principles
 
Idiomatic C++
Idiomatic C++Idiomatic C++
Idiomatic C++
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMS
 
The Style of C++ 11
The Style of C++ 11The Style of C++ 11
The Style of C++ 11
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing Software
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ Advanced
 
Web Service Basics and NWS Setup
Web Service  Basics and NWS SetupWeb Service  Basics and NWS Setup
Web Service Basics and NWS Setup
 
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
 
Solid Software Design Principles
Solid Software Design PrinciplesSolid Software Design Principles
Solid Software Design Principles
 
Do we need SOLID principles during software development?
Do we need SOLID principles during software development?Do we need SOLID principles during software development?
Do we need SOLID principles during software development?
 
Operator overloading
Operator overloading Operator overloading
Operator overloading
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL
 
Solid principles
Solid principlesSolid principles
Solid principles
 

Semelhante a SOLID Principles part 2

Integration solution: Instant access to Web Services into IMS applications
Integration solution: Instant access to Web Services into IMS applicationsIntegration solution: Instant access to Web Services into IMS applications
Integration solution: Instant access to Web Services into IMS applicationsVirtel - SysperTec
 
David Goulden keynote at Dell EMC World
David Goulden keynote at Dell EMC WorldDavid Goulden keynote at Dell EMC World
David Goulden keynote at Dell EMC WorldDell EMC World
 
The Elastix Call Center Protocol Revealed
The Elastix Call Center Protocol RevealedThe Elastix Call Center Protocol Revealed
The Elastix Call Center Protocol RevealedPaloSanto Solutions
 
Novell Service Desk overview
Novell Service Desk overviewNovell Service Desk overview
Novell Service Desk overviewJon Giffard
 
eG Enterprise Citrix XenDesktop Monitor Product Tour
eG Enterprise Citrix XenDesktop Monitor Product ToureG Enterprise Citrix XenDesktop Monitor Product Tour
eG Enterprise Citrix XenDesktop Monitor Product ToureG Innovations
 
Smart 2530 v2 Thin Client
Smart 2530 v2 Thin Client Smart 2530 v2 Thin Client
Smart 2530 v2 Thin Client Nirav Ambani
 
Consolidation of IVI Graphic Subsystems; Weston, a Wayland Compositor, and Ge...
Consolidation of IVI Graphic Subsystems; Weston, a Wayland Compositor, and Ge...Consolidation of IVI Graphic Subsystems; Weston, a Wayland Compositor, and Ge...
Consolidation of IVI Graphic Subsystems; Weston, a Wayland Compositor, and Ge...Ryo Jin
 

Semelhante a SOLID Principles part 2 (9)

Distributed Systems principles
Distributed Systems principlesDistributed Systems principles
Distributed Systems principles
 
Integration solution: Instant access to Web Services into IMS applications
Integration solution: Instant access to Web Services into IMS applicationsIntegration solution: Instant access to Web Services into IMS applications
Integration solution: Instant access to Web Services into IMS applications
 
David Goulden keynote at Dell EMC World
David Goulden keynote at Dell EMC WorldDavid Goulden keynote at Dell EMC World
David Goulden keynote at Dell EMC World
 
SDN, com fer-ho realitat i quins avantatges puc treure-hi
SDN, com fer-ho realitat i quins avantatges puc treure-hiSDN, com fer-ho realitat i quins avantatges puc treure-hi
SDN, com fer-ho realitat i quins avantatges puc treure-hi
 
The Elastix Call Center Protocol Revealed
The Elastix Call Center Protocol RevealedThe Elastix Call Center Protocol Revealed
The Elastix Call Center Protocol Revealed
 
Novell Service Desk overview
Novell Service Desk overviewNovell Service Desk overview
Novell Service Desk overview
 
eG Enterprise Citrix XenDesktop Monitor Product Tour
eG Enterprise Citrix XenDesktop Monitor Product ToureG Enterprise Citrix XenDesktop Monitor Product Tour
eG Enterprise Citrix XenDesktop Monitor Product Tour
 
Smart 2530 v2 Thin Client
Smart 2530 v2 Thin Client Smart 2530 v2 Thin Client
Smart 2530 v2 Thin Client
 
Consolidation of IVI Graphic Subsystems; Weston, a Wayland Compositor, and Ge...
Consolidation of IVI Graphic Subsystems; Weston, a Wayland Compositor, and Ge...Consolidation of IVI Graphic Subsystems; Weston, a Wayland Compositor, and Ge...
Consolidation of IVI Graphic Subsystems; Weston, a Wayland Compositor, and Ge...
 

Mais de Dennis van der Stelt

Mais de Dennis van der Stelt (8)

Change your architecture during deployment
Change your architecture during deploymentChange your architecture during deployment
Change your architecture during deployment
 
Een andere kijk op Microservices
Een andere kijk op MicroservicesEen andere kijk op Microservices
Een andere kijk op Microservices
 
Duplicating data or replicating data in Micro Services
Duplicating data or replicating data in Micro ServicesDuplicating data or replicating data in Micro Services
Duplicating data or replicating data in Micro Services
 
Silverlight & WCF RIA
Silverlight & WCF RIASilverlight & WCF RIA
Silverlight & WCF RIA
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
AppFabric Velocity
AppFabric VelocityAppFabric Velocity
AppFabric Velocity
 
Continuous integration
Continuous integrationContinuous integration
Continuous integration
 
App fabric introduction
App fabric introductionApp fabric introduction
App fabric introduction
 

Último

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

Último (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

SOLID Principles part 2

  • 1. Dennis van der Stelt Interface Segregation Principle Dependency Inversion Principle Dennis van der Stelt Software Architect Tellus http://bloggingabout.net/blogs/dennis/ @dvdstelt dvdstelt@tellus.com Pascal de Jonge Development Lead Tellus http://www.pazquality.com/ @pdejonge pdejonge@tellus.com SOLID
  • 3. Dennis van der Stelt AGENDA
  • 4. Dennis van der Stelt SOLID History
  • 5. Dennis van der Stelt Guidance
  • 6. Dennis van der Stelt SOLID Five principles Single Responsibility SOLID Open/Closed Liskov Substitution Interface Segregation Learn them, love them, live by them… Dependency Inversion
  • 7. Dennis van der Stelt SOLID Books
  • 8. Dennis van der Stelt SOLID Interface Segregation Principle
  • 9. Dennis van der Stelt INTERFACE SEGREGATION PRINCIPLE clients should not be forced to depend on methods they do not use
  • 10. Dennis van der Stelt INTERFACE SEGREGATION PRINCIPLE tailor interfaces to individual client’s needs
  • 11. Dennis van der Stelt DEMO Membership Provider
  • 12. Dennis van der Stelt INTERFACE SEGREGATION PRINCIPLE public interface IVerifyCredentials { int MaxInvalidPasswordAttempts { get; } bool ValidateUser(string username, string password); } public interface IManageCredentials { bool ChangePassword(string oldPassword, string newPassword); int MinRequiredNonAlphanumericCharacters { get; } int MinRequiredPasswordLength { get; } string ResetPassword(string username); } public interface IManageUsers { MembershipUser CreateUser(string username, string password); bool DeleteUser(string username, bool deleteAllRelatedData); }
  • 13. Dennis van der Stelt INTERFACE SEGREGATION PRINCIPLE Why is violation of this principle a problem? introduces very fat interfaces difficult to extend functionality violates single responsibility principle forced dependencies 02 03 04 01
  • 14. Dennis van der Stelt public interface IDoor { bool IsDoorOpen { get; set; } void Lock(); void Unlock(); } INTERFACE SEGREGATION PRINCIPLE public class SimpleDoor : IDoor { public bool IsDoorOpen { get; set; } public void Lock() { // Implementation here... } public void Unlock() { // Implementation here... } }
  • 15. Dennis van der Stelt public interface ITimerFunction { void TimerFunction(); } INTERFACE SEGREGATION PRINCIPLE class AdvancedDoor : IDoor, ITimerFunction { public bool IsDoorOpen { get; set; } public void Lock() { } public void Unlock() { } public void TimerFunction() { // Implementation here... } }
  • 16. Dennis van der Stelt List<IDoor> doors = new List<IDoor>() { new SimpleDoor(), new AdvancedDoor() }; foreach (var door in doors) { if (door is ITimerFunction) ((ITimerFunction)door).TimerFunction(); } INTERFACE SEGREGATION PRINCIPLE
  • 17. Dennis van der Stelt SOLID Dependency Inversion Principle
  • 18. Dennis van der Stelt DEPENDENCY INVERSION PRINCIPLE high level modules should not depend upon low level modules, both should depend on abstractions. abstractions should not depend upon details. details should depend on abstractions
  • 19. Dennis van der Stelt DEPENDENCY INVERSION PRINCIPLE Inversion of control Component A Component B Component C
  • 20. Dennis van der Stelt DEPENDENCY INVERSION PRINCIPLE Inversion of control Component A Component A Service <<interface>> Component B Component A Service Component C <<interface>>
  • 21. Dennis van der Stelt DEPENDENCY INVERSION PRINCIPLE Inversion of control Component A Client Service <<interface>> Component B Component A Service Component C <<interface>> Component D
  • 22. Dennis van der Stelt DEPENDENCY INVERSION PRINCIPLE Valar Morghulis
  • 23. Dennis van der Stelt DEMO Game on!!!
  • 24. Dennis van der Stelt DEPENDENCY INVERSION PRINCIPLE Violations public class SecurityService { public static User GetCurrentUser() { return Context.User; } } Dependency in static method
  • 25. Dennis van der Stelt DEPENDENCY INVERSION PRINCIPLE Violations public class OrderProcessing { private IList<Product> FindProduct(int category) { var repository = new ProductRepository(); return repository.FindByCategory(category); } } Instantiating your own dependencies
  • 26. Dennis van der Stelt DEPENDENCY INVERSION PRINCIPLE Violations public class OrderProcessing { private IList<Product> FindProduct(int category) { var repository = ServiceLocator.GetInstance<IProductRepository>(); return repository.FindByCategory(category); } } Asking for instantiating your dependencies only at the composition root
  • 27. Dennis van der Stelt COMPOSITION ROOT Application entry point Factory Pattern Libraries & Frameworks
  • 28. Dennis van der Stelt COMPOSITION ROOT Application entry point Factory Pattern Libraries & Frameworks
  • 29. Dennis van der Stelt COMPOSITION ROOT Application entry point Factory Pattern Libraries & Frameworks
  • 30. Dennis van der Stelt DEPENDENCY INVERSION PRINCIPLE Inversion of control HomeController ICustomer Registration <<interface>> Customer Registration IMessageSender Factory MessageSender Factory <<interface>> ICustomer Repository <<interface>> Customer Repository MessageSender Base
  • 31. Dennis van der Stelt DEMO Dependency Injection in MVC
  • 32. Dennis van der Stelt
  • 33. Dennis van der Stelt CONCLUSION Single Responsibility SOLID Open/Closed Liskov Substitution Interface Seggregation Dependency Inversion
  • 34. Dennis van der Stelt34 Thank you questions? Dennis van der Stelt Software Architect Tellus http://bloggingabout.net/blogs/dennis/ @dvdstelt dvdstelt@tellus.com Pascal de Jonge Development Lead Tellus http://www.pazquality.com/ @pdejonge pdejonge@tellus.com

Notas do Editor

  1. There are other talks that will go into Big Data and Hadoop so we’ll only do a quick overview of that right now. We’ll spend most of our time on Hive.
  2. 5 basic principles of OOPDIntroduced in 2000By Robert C. Martin (Uncle Bob)Whenapplied, more likelyto have a bettermaintainableandextendable system over time.
  3. Guidelines, not hard rules, not a dogmaUse common senseDon’tjustthrowthemaway
  4. Add “System.Web.Applications” and implement “MembershipProvider”
  5. Also doesn’t violate SRP
  6. NotImplementedException
  7. Also doesn’t violate SRP
  8. Also doesn’t violate SRP
  9. Also doesn’t violate SRP
  10. Interfaces are packaged with higher-level components. They define higher-level components needs, not lower-level components behavior.
  11. Tight coupling- When 2 classes depend on each other