SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante a Taming Brownfield Codebases with AOP

Semelhante a 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
 

Mais de 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
 

Mais de 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
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
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
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 
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
 
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...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
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...
 
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
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
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
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
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
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

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

Notas do Editor

  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