SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Taming Brownfield
Codebases with AOP
The typical Brownfield codebase
• Spaghetti code
• Tightly coupled
• Lack of organization
• Inconsistent
• Dangerous to change
Brownfield reclamation
• Introduce consistency
• Require minimal effort
• Introduce limited risk
How AOP can help
• Introduce consistency
• Aspects are isolated and centralized features
• Require minimal effort
• Make use of pre-existing aspects
• Introduce limited risk
• Granularity choices
• AOP is reversible
AOP choices
• Interceptors
• Depends on Inversion of Control Containers
• Requires Dependency Inversion/Injection patterns in the code
• Existing frameworks
• Many have injection points
• Isolated functionality added at these points is AOP
• IL Weaving
• Modifies the code post compilation
• Limited codebase changes
IL Weaving
• Each aspect is an implementation
• Granular attachment options
• Changes are usually additive
Implementation
[NotifyPropertyChanged]
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName
{
get { return this.FirstName + " " + this.LastName; }
}
}
Implied Functionality
public class Person : INotifyPropertyChanged
{
private string firstName;
private string lastName;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if ( this.PropertyChanged != null )
{
this.PropertyChanged( this,
new PropertyChangedEventArgs(propertyName) );
}
}
public string FirstName
{
get { return this.firstName; }
set
{
if ( this.firstName != value )
{
this.firstName = value;
this.OnPropertyChanged("FirstName");
this.OnPropertyChanged("FullName");
}
}
}
public string LastName
{
get { return this.lastName; }
set
{
if ( this.lastName != value )
{
this.lastName = value;
this.OnPropertyChanged("LastName");
this.OnPropertyChanged("FullName");
}
}
}
public string FullName
{
get { return this.FirstName + " " + this.LastName; }
}
Implementation
public class OrderFulfillmentService
{
[HandleException]
public void Fulfill( Order order )
{
// Do stuff.
}
}
Implied Functionality
public class OrderFulfillmentService
{
public void Fulfill( Order order )
{
try
{
// Do stuff.
}
catch ( Exception e )
{
if ( ExceptionHandler.Handle(e) )
throw;
}
}
}
Implementation
[assembly:
Log(AttributeTargetTypes="Contoso.Crm.Orders.*",
AttributeTargetMemberAttributes = MulticastAttributes.Public)]
public class OrderFulfillmentService
{
public bool IsValid( Order order )
{
if ( order.Lines.Count == 0 )
return false;
if ( order.Amount < 0 )
return false;
return true;
}
}
Existing implementations
• Toolkits exist for many common needs
• Logging
• INotifyPropertyChanged
• Exception handling
• Some will be difficult to use in brownfield scenarios
Moving forward with AOP and Brownfield
• IL weaving is the
• Easiest technique to add non-functional requirements
• Lowest impact to existing code
• Easiest to back out
• Make use of existing aspects
• Don’t forget to leverage frameworks already used
Donald Belcham
@dbelcham
donald.belcham@igloocoder.com

Weitere ähnliche Inhalte

Was ist angesagt?

Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
Deepak Singh
 
Command line arguments.21
Command line arguments.21Command line arguments.21
Command line arguments.21
myrajendra
 

Was ist angesagt? (20)

Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
 
Closures
ClosuresClosures
Closures
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
 
Callback Function
Callback FunctionCallback Function
Callback Function
 
Firebase Remote Config + Kotlin = EasyFRC
Firebase Remote Config + Kotlin = EasyFRCFirebase Remote Config + Kotlin = EasyFRC
Firebase Remote Config + Kotlin = EasyFRC
 
AngularJS Testing Strategies
AngularJS Testing StrategiesAngularJS Testing Strategies
AngularJS Testing Strategies
 
Testing most things in JavaScript - LeedsJS 31/05/2017
Testing most things in JavaScript - LeedsJS 31/05/2017Testing most things in JavaScript - LeedsJS 31/05/2017
Testing most things in JavaScript - LeedsJS 31/05/2017
 
Command line arguments.21
Command line arguments.21Command line arguments.21
Command line arguments.21
 
Introduction to php 5
Introduction to php   5Introduction to php   5
Introduction to php 5
 
Tdd iPhone For Dummies
Tdd iPhone For DummiesTdd iPhone For Dummies
Tdd iPhone For Dummies
 
Basic math operations using dataweave
Basic math operations using dataweaveBasic math operations using dataweave
Basic math operations using dataweave
 
CFML Enhancements in ColdFusion 10
CFML Enhancements in ColdFusion 10 CFML Enhancements in ColdFusion 10
CFML Enhancements in ColdFusion 10
 
Bca 2nd sem u-4 operator overloading
Bca 2nd sem u-4 operator overloadingBca 2nd sem u-4 operator overloading
Bca 2nd sem u-4 operator overloading
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond Smalltak
 
Unit tests in node.js
Unit tests in node.jsUnit tests in node.js
Unit tests in node.js
 
Full Stack Unit Testing
Full Stack Unit TestingFull Stack Unit Testing
Full Stack Unit Testing
 
85ec7 session2 c++
85ec7 session2 c++85ec7 session2 c++
85ec7 session2 c++
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
 

Ähnlich wie Taming Brownfield Codebases with AOP

Ähnlich wie Taming Brownfield Codebases with AOP (20)

Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
ASP.Net 5 and C# 6
ASP.Net 5 and C# 6ASP.Net 5 and C# 6
ASP.Net 5 and C# 6
 
Java 8 Feature Preview
Java 8 Feature PreviewJava 8 Feature Preview
Java 8 Feature Preview
 
Solid principles
Solid principlesSolid principles
Solid principles
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
 
Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basics
 
Google guava
Google guavaGoogle guava
Google guava
 
Getting Started with Test-Driven Development at Midwest PHP 2021
Getting Started with Test-Driven Development at Midwest PHP 2021Getting Started with Test-Driven Development at Midwest PHP 2021
Getting Started with Test-Driven Development at Midwest PHP 2021
 
What's new in c# 8.0
What's new in c# 8.0What's new in c# 8.0
What's new in c# 8.0
 
Core java
Core javaCore java
Core java
 
Gradle For Beginners (Serbian Developer Conference 2013 english)
Gradle For Beginners (Serbian Developer Conference 2013 english)Gradle For Beginners (Serbian Developer Conference 2013 english)
Gradle For Beginners (Serbian Developer Conference 2013 english)
 
Design principles - SOLID
Design principles - SOLIDDesign principles - SOLID
Design principles - SOLID
 
Intro to JavaScript - Week 2: Function
Intro to JavaScript - Week 2: FunctionIntro to JavaScript - Week 2: Function
Intro to JavaScript - Week 2: Function
 
Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contd
 
Post Sharp Talk
Post Sharp TalkPost Sharp Talk
Post Sharp Talk
 
Beyond java8
Beyond java8Beyond java8
Beyond java8
 
Functional Programming In Java
Functional Programming In JavaFunctional Programming In Java
Functional Programming In Java
 
How Testability Inspires AngularJS Design / Ran Mizrahi
How Testability Inspires AngularJS Design / Ran MizrahiHow Testability Inspires AngularJS Design / Ran Mizrahi
How Testability Inspires AngularJS Design / Ran Mizrahi
 

Mehr von Donald Belcham

Design patterns you didn't know about
Design patterns you didn't know aboutDesign patterns you didn't know about
Design patterns you didn't know about
Donald Belcham
 
Programming Closer to the Iron
Programming Closer to the IronProgramming Closer to the Iron
Programming Closer to the Iron
Donald Belcham
 
The Dark Side of Code Metrics
The Dark Side of Code MetricsThe Dark Side of Code Metrics
The Dark Side of Code Metrics
Donald Belcham
 

Mehr von Donald Belcham (20)

Introduction to Messaging
Introduction to MessagingIntroduction to Messaging
Introduction to Messaging
 
Advanced messaging patterns
Advanced messaging patternsAdvanced messaging patterns
Advanced messaging patterns
 
Microservices: The Nitty Gritty
Microservices: The Nitty GrittyMicroservices: The Nitty Gritty
Microservices: The Nitty Gritty
 
Microservices: A Gentle Introduction
Microservices: A Gentle IntroductionMicroservices: A Gentle Introduction
Microservices: A Gentle Introduction
 
AOP & Patterns
AOP & PatternsAOP & Patterns
AOP & Patterns
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
 
Source Control Abominations
Source Control AbominationsSource Control Abominations
Source Control Abominations
 
Is There Room for Craftsmanship in Software Development
Is There Room for Craftsmanship in Software DevelopmentIs There Room for Craftsmanship in Software Development
Is There Room for Craftsmanship in Software Development
 
Reducing External Risk
Reducing External RiskReducing External Risk
Reducing External Risk
 
Performance Tuning in the Trenches
Performance Tuning in the TrenchesPerformance Tuning in the Trenches
Performance Tuning in the Trenches
 
Reliability and Resilience
Reliability and ResilienceReliability and Resilience
Reliability and Resilience
 
Reliability and Reslience
Reliability and ReslienceReliability and Reslience
Reliability and Reslience
 
Introduction To AOP
Introduction To AOPIntroduction To AOP
Introduction To AOP
 
Design patterns you didn't know about
Design patterns you didn't know aboutDesign patterns you didn't know about
Design patterns you didn't know about
 
Programming Closer to the Iron
Programming Closer to the IronProgramming Closer to the Iron
Programming Closer to the Iron
 
Domain Driven Design Primer
Domain Driven Design PrimerDomain Driven Design Primer
Domain Driven Design Primer
 
Hacking Hardware
Hacking HardwareHacking Hardware
Hacking Hardware
 
Advanced AOP
Advanced AOPAdvanced AOP
Advanced AOP
 
The Dark Side of Code Metrics
The Dark Side of Code MetricsThe Dark Side of Code Metrics
The Dark Side of Code Metrics
 
Continuous Deployment
Continuous DeploymentContinuous Deployment
Continuous Deployment
 

Kürzlich hochgeladen

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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
 
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
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
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
 
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
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

Taming Brownfield Codebases with AOP

  • 2. The typical Brownfield codebase • Spaghetti code • Tightly coupled • Lack of organization • Inconsistent • Dangerous to change
  • 3. Brownfield reclamation • Introduce consistency • Require minimal effort • Introduce limited risk
  • 4. How AOP can help • Introduce consistency • Aspects are isolated and centralized features • Require minimal effort • Make use of pre-existing aspects • Introduce limited risk • Granularity choices • AOP is reversible
  • 5. AOP choices • Interceptors • Depends on Inversion of Control Containers • Requires Dependency Inversion/Injection patterns in the code • Existing frameworks • Many have injection points • Isolated functionality added at these points is AOP • IL Weaving • Modifies the code post compilation • Limited codebase changes
  • 6. IL Weaving • Each aspect is an implementation • Granular attachment options • Changes are usually additive
  • 7. Implementation [NotifyPropertyChanged] public class Person { public string FirstName { get; set; } public string LastName { get; set; } public string FullName { get { return this.FirstName + " " + this.LastName; } } }
  • 8. Implied Functionality public class Person : INotifyPropertyChanged { private string firstName; private string lastName; public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { if ( this.PropertyChanged != null ) { this.PropertyChanged( this, new PropertyChangedEventArgs(propertyName) ); } } public string FirstName { get { return this.firstName; } set { if ( this.firstName != value ) { this.firstName = value; this.OnPropertyChanged("FirstName"); this.OnPropertyChanged("FullName"); } } } public string LastName { get { return this.lastName; } set { if ( this.lastName != value ) { this.lastName = value; this.OnPropertyChanged("LastName"); this.OnPropertyChanged("FullName"); } } } public string FullName { get { return this.FirstName + " " + this.LastName; } }
  • 10. Implied Functionality public class OrderFulfillmentService { public void Fulfill( Order order ) { try { // Do stuff. } catch ( Exception e ) { if ( ExceptionHandler.Handle(e) ) throw; } } }
  • 11. Implementation [assembly: Log(AttributeTargetTypes="Contoso.Crm.Orders.*", AttributeTargetMemberAttributes = MulticastAttributes.Public)] public class OrderFulfillmentService { public bool IsValid( Order order ) { if ( order.Lines.Count == 0 ) return false; if ( order.Amount < 0 ) return false; return true; } }
  • 12. Existing implementations • Toolkits exist for many common needs • Logging • INotifyPropertyChanged • Exception handling • Some will be difficult to use in brownfield scenarios
  • 13. Moving forward with AOP and Brownfield • IL weaving is the • Easiest technique to add non-functional requirements • Lowest impact to existing code • Easiest to back out • Make use of existing aspects • Don’t forget to leverage frameworks already used

Hinweis der Redaktion

  1. Lots of brownfield codebases are a messed mix of procedural, OO and functional programming styles. It’s not uncommon to see an OO language used to write an application in purely procedural code. The result is that the code is tightly coupled through out. Add to this a lack of file, code and namespace organization and you’ll quickly feel like you’re running around in circles when you’re trying to navigate through the code.Once you do get a feeling for the code you’ll notice that there are glaring consistency issues. One API might have logging enabled on it while another doesn’t. When logging is implemented the messages entered into the log may differ method to method. Different techniques for transaction management may be used in different locations. In short, every time you step into a section of code it’s a learning experience.All of these things culminate in one undeniable fact; any change you make to the codebase is a dangerous change. No matter how trivial the change you make there will always be some unintended side effect that cascades through the application breaking something. You can’t easily protect yourself from this either. The previous developers didn’t create a full suite of unit/integration tests for you to rely on, and those that they did create don’t really test anything of significance. To add tests that protect you from breaking changes you need to change the code to make it more testable; a classic chicken and egg issue.
  2. Consistency - how features are implemented - where features are implementedEvery new feature, or gain in consistency, can’t require a rewrite.Have to understand the risk in each change and be able to back out the change if the risk assessment was wrong
  3. Granularity – each aspect can be attached where appropriate; class, method, event, etc.Reversibility – AOP can be backed out and individual aspects can be backed out
  4. Existing frameworksMVC inherit from HandleError and apply via ConfigWCF add transaction mgmt to every callNhibernate add auditing to every CUD action
  5. - Implementation isolationapplication, class, method/property/event level attachment gives optionsAdditive changes are the least risky. Modification