25
SOLIDify Your Microsoft ASP.NET MVC Applications Simon Laroche Architecte Logiciel PCMS Conseil [email protected]

SOLIDify Your Microsoft ASP.NET MVC Applications

  • Upload
    shayna

  • View
    52

  • Download
    0

Embed Size (px)

DESCRIPTION

SOLIDify Your Microsoft ASP.NET MVC Applications. Simon Laroche Architecte Logiciel PCMS Conseil [email protected]. Risks of Poorly Designed Code. Difficult and Expensive to Maintain Buggy Speed of development degrades rapidly Longer and longer test cycles - PowerPoint PPT Presentation

Citation preview

Page 1: SOLIDify  Your Microsoft ASP.NET MVC Applications

SOLIDify Your MicrosoftASP.NET MVC Applications

Simon LarocheArchitecte LogicielPCMS [email protected]

Page 2: SOLIDify  Your Microsoft ASP.NET MVC Applications

Risks of Poorly Designed Code• Difficult and Expensive to Maintain• Buggy• Speed of development degrades rapidly• Longer and longer test cycles

• A BIG BALL OF MUD is a casually, even haphazardly, structured system. Its organization, if one can call it that, is dictated more by expediency than design.http://www.laputan.org/mud/ http://en.wikipedia.org/wiki/Big_ball_of_mud

Page 3: SOLIDify  Your Microsoft ASP.NET MVC Applications

What is ASP.NET MVC?• Model• The representation of the business rules and data

• View• The representation of a single UI component

(a form or page, typically)• Controller• Maintains the logic of which View to display, and what data

the view needs.

Page 4: SOLIDify  Your Microsoft ASP.NET MVC Applications

ASP.NET Runtime

MVC

Controller

View

ModelRequest

Response

2

3

14

Page 5: SOLIDify  Your Microsoft ASP.NET MVC Applications

demoA Simple ASP.NET MVC Application

Page 6: SOLIDify  Your Microsoft ASP.NET MVC Applications

Benefits of OOP• -ilities• Reliability• Extensibility• Maintainability• Flexibility

• Management of Complexity

Page 7: SOLIDify  Your Microsoft ASP.NET MVC Applications

S O L I D Principles

Page 8: SOLIDify  Your Microsoft ASP.NET MVC Applications

SOLID Development Principles• SRP – Single Responsibility Principle• OCP – Open / Closed Principle• LSP – Liskov Substitution Principle• ISP – Interface Segregation Principle• DIP – Dependency Inversion Principle

Page 9: SOLIDify  Your Microsoft ASP.NET MVC Applications

SRP: What’s a Responsibility?• Persistence• Logging• Exception Handling• Formatting• Rendering / User Interface

• “A class should have one, and only one, reason to change.”

Page 10: SOLIDify  Your Microsoft ASP.NET MVC Applications

demoSRP Violation

Page 11: SOLIDify  Your Microsoft ASP.NET MVC Applications

OCP: Changes = New Code• “Modules should be open for extension, but closed for

modification.”

• Adding features should be handled by adding new code, not changing existing code.

Page 12: SOLIDify  Your Microsoft ASP.NET MVC Applications

demoOCP Violation

Page 13: SOLIDify  Your Microsoft ASP.NET MVC Applications

LSP: Subclasses Extend, Not Remove

• “Derived classes must be usable through the base class interface without the need for the user to know the difference”

• Subclasses cannot remove functionality, or change expected behaviors, of classes from which they inherit

Page 14: SOLIDify  Your Microsoft ASP.NET MVC Applications

demoLSP Violation

Page 15: SOLIDify  Your Microsoft ASP.NET MVC Applications

ISP: Clients Control Interfaces• “Separate interfaces so callers are only dependent on

what they actually use”• Avoid “fat” interfaces• Tailor interfaces to clients• Consider packaging interface with client

Page 16: SOLIDify  Your Microsoft ASP.NET MVC Applications

demoISP Violation

Page 17: SOLIDify  Your Microsoft ASP.NET MVC Applications

DIP: Depend on Abstractions• “Inject” dependencies into classes• Infrastructure should depend on core domain classes,

not the other way around• Classes should not decide particulars of how their

collaborators’ work is done – separate concern

Page 18: SOLIDify  Your Microsoft ASP.NET MVC Applications

DIP: Depend on Abstractions

Page 19: SOLIDify  Your Microsoft ASP.NET MVC Applications

DIP: Depend on Abstractions

Page 20: SOLIDify  Your Microsoft ASP.NET MVC Applications

demoDIP Violation

Page 21: SOLIDify  Your Microsoft ASP.NET MVC Applications

Simple Design Rules• Runs all the tests• Contains no duplication• Expresses the intent of the programmer• Minimizes the number of classes and methods

• The rules are given in order of importance.

Kent Beck, Extreme Programming Explained

Page 22: SOLIDify  Your Microsoft ASP.NET MVC Applications

Don’t Repeat Yourself (DRY)• "Every piece of knowledge must have a single,

unambiguous, authoritative representation within a system."

• Eliminating duplication is at the heart of many design patterns and OOP principles

Page 23: SOLIDify  Your Microsoft ASP.NET MVC Applications

demoRefactoring : Make It Right

Page 24: SOLIDify  Your Microsoft ASP.NET MVC Applications

Recommended Books• Agile Software Development

• Agile Principles, Patterns, and Practices in C#

• Clean Code

All written by Robert C. “Uncle Bob” MartinAlso see: http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod

Page 25: SOLIDify  Your Microsoft ASP.NET MVC Applications

Q & A