SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Andere mochten auch

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乐群 陈
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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...
 

Mehr von Dennis van der Stelt

Mehr von 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
 

Kürzlich hochgeladen

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
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
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
[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
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 

Kürzlich hochgeladen (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
[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
 
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 ...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

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

Hinweis der Redaktion

  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