SlideShare una empresa de Scribd logo
1 de 20
Descargar para leer sin conexión
MODULARIZING STRATEGIES:
FIXING CLASS & PACKAGE TANGLES
ganesh samarthyam
(ganesh@codeops.tech)
WHAT’S A “TANGLE”?
➤ “A tangle is a portion of a dependency graph within which all
the items are directly or indirectly dependent on all the other
nodes in the tangle.” (Source: structure101.com)
Example of a class tangle (cycle)
Example of a package tangle
REMOVING TANGLES - VISUALISING IN STRUCTURE101
REFACTORING CLASS TANGLES
DEPENDENCIES BETWEEN CONCRETE CLASSES - TANGLE
import java.util.List;
public class Customer {
List<Order> orders;
}
class Order {
Customer purchaser;
}
A direct cyclic dependency between the Customer & Order class because
they contain instances of each other’s type
DEPENDENCIES BETWEEN CONCRETE CLASSES - TANGLE - FIX
import java.util.List;
public class Customer {
List<Order> orders;
}
class Order {
Customer purchaser;
}
Depend on the interface instead of the implementation (and the cycle is gone)
import java.util.List;
interface Buyer {}
public class Customer implements Buyer {
List<Buyable> orders;
}
interface Buyable {}
class Order implements Buyable {
Buyer purchaser;
}
BASE CLASS REFERS TO ITS DERIVED TYPES(S)
enum ImageType { JPEG, BMP, PNG };
abstract class Image {
public static Image getImage(ImageType imageType,
String name) {
switch (imageType) {
// JPEGImage, BMPImage, PNGImage are
// derived classes of the abstract class Image
case JPEG: return new JPEGImage(name);
case BMP: return new BMPImage(name);
case PNG: return new PNGImage(name);
}
return null;
}
}
This is a special kind of cyclic dependency - the base type knows about its
derived type! Here it is creation of its derived objects results in a tangle
BASE CLASS REFERS TO ITS DERIVED TYPES(S) - FIX
It’s easy to break this cyclic dependency - move the getImage() method to a
dedicated class named ImageFactory!
AVOIDABLE REFERENCES TO CLASSES - TANGLE
In this case, the Target abstract class has unnecessary references to concrete
classes; instead of overloading, could be specific method calls instead
package main;
abstract class Target {
public abstract void genCode(Constant constant);
public abstract void genCode(Plus plus);
public abstract void genCode(Mult mult);
}
class JVMTarget extends Target {
public void genCode(Constant constant) {
System.out.println("bipush " + constant.getValue());
}
public void genCode(Plus plus) {
System.out.println("iadd");
}
public void genCode(Mult mult) {
System.out.println("imul");
}
}
class DotNetTarget extends Target {
public void genCode(Constant constant) {
System.out.println("ldarg " + constant.getValue());
}
public void genCode(Plus plus) {
System.out.println("add");
}
public void genCode(Mult mult) {
System.out.println("mul");
}
}
abstract class ExprNode {
protected static Target target = new JVMTarget();
public static void setTarget(Target newTarget) {
target = newTarget;
}
public abstract void genCode();
}
class Constant extends ExprNode {
int val;
public Constant(int arg) {
val = arg;
}
public int getValue() {
return val;
}
public void genCode() {
target.genCode(this);
}
}
UNNECESSARY REFERENCES TO CLASSES - TANGLE - FIX
abstract class Target {
public abstract void genCodeConstant(int constValue);
public abstract void genCodePlus();
public abstract void genCodeMult();
}
class JVMTarget extends Target {
public void genCodeConstant(int constValue) {
System.out.println("bipush " + constValue);
}
public void genCodePlus() {
System.out.println("iadd");
}
public void genCodeMult() {
System.out.println("imul");
}
}
abstract class Target {
public abstract void genCode(Constant constant);
public abstract void genCode(Plus plus);
public abstract void genCode(Mult mult);
}
class JVMTarget extends Target {
public void genCode(Constant constant) {
System.out.println("bipush " + constant.getValue());
}
public void genCode(Plus plus) {
System.out.println("iadd");
}
public void genCode(Mult mult) {
System.out.println("imul");
}
}
By making the Target class not refer to the concrete ExprNode classes, the
tangle is gone!
SUMMARY - STRATEGIES FOR BREAKING CLASS TANGLES
Cause(s) Potential Solution(s)
References among concrete classes
causes cycle(s)/tangle(s)
Depend on the interfaces than on the
concrete classes (extract interfaces
if they are absent)
A base class refers to one or more
of its derived class(es) causing
tangle(s) (e.g., base class creates
objects of its derived types)
Remove the offending references
from base class to the derived
class(es) (e.g., move the object
creation to a dedicated factory class)
Unnecessary references to classes
causes tangles
Remove the unnecessary references
REFACTORING PACKAGE TANGLES
INTERFACE & IMPLEMENTATION PACKAGED TOGETHER
Packaging the interface & corresponding implementation together causes tangle!
package buyers;
import buyables.Buyable;
import java.util.List;
interface Buyer {}
public class Customer implements Buyer {
List<Buyable> orders;
}
package buyables;
interface Buyable {}
public class Order implements Buyable {
Buyer purchaser;
}
INTERFACE & IMPLEMENTATION PACKAGED TOGETHER - FIX
Separating the interfaces as a separate package (from the
implementation package) disentangles the structure!
MISPLACED ENTITY - PACKAGE TANGLE
An entity misplaced in a package causes a tangle (where does enum
ImageType belong? In the “factory” package or “image” package?
package image;
import factory.ImageType;
public abstract class Image {
public abstract ImageType getType();
}
package factory;
public enum ImageType { JPEG, BMP, PNG }
package imagetypes;
import factory.ImageType;
import image.Image;
public class BMPImage extends Image {
public BMPImage(String name) {
super();
}
public ImageType getType() {
return ImageType.BMP;
}
}
MISPLACED ENTITY - PACKAGE TANGLE - FIX
Here, the entity “enum ImageType” arguably belongs better in “image”
package than in the “factory” package (moving the enum breaks the tangle)
MIXED PACKAGE - PACKAGE TANGLE
Here, the Expr class and the builder class ExprBuilder (that builds objects) are put
together in the same “core” package - this results in a tangle
package core;
import nodes.*;
public class ExprBuilder {
private Expr expr = null;
public ExprBuilder() {}
public ExprBuilder Const(int arg) {
expr = Constant.make(arg);
return this;
}
public ExprBuilder Plus(int arg) {
expr = new Addition(expr, Constant.make(arg));
return this;
}
public ExprBuilder Mult(int arg) {
expr = new Multiplication(expr, Constant.make(arg));
return this;
}
public Expr Build() {
return expr;
}
}
MIXED PACKAGE - PACKAGE TANGLE - FIX
The tangle is broken by splitting the 

“core” package into two packages (“core” and “builder”)
SUMMARY - STRATEGIES FOR BREAKING PACKAGE TANGLES
Cause(s) Potential Solution(s)
Interfaces and implementations are
mixed together
Separate the interfaces and
implementations to separate
packages
A class is misplaced in a package
causing a tangle
Move the offending class to a more
suitable package
Classes that may not belong
together packaged into a single
package cause a tangle
Split the package
www.codeops.tech
www.konfhub.com
www.designsmells.com

Más contenido relacionado

La actualidad más candente

Strategy Design Pattern
Strategy Design PatternStrategy Design Pattern
Strategy Design PatternGanesh Kolhe
 
Mieux programmer grâce aux design patterns
Mieux programmer grâce aux design patternsMieux programmer grâce aux design patterns
Mieux programmer grâce aux design patternsGeeks Anonymes
 
Creational pattern 2
Creational pattern 2Creational pattern 2
Creational pattern 2Naga Muruga
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Kuldeep Jain
 
The AWT and Swing
The AWT and SwingThe AWT and Swing
The AWT and Swingadil raja
 
CRM Science - Dreamforce '14: Generic Package Extension Architecture for App...
CRM Science - Dreamforce '14:  Generic Package Extension Architecture for App...CRM Science - Dreamforce '14:  Generic Package Extension Architecture for App...
CRM Science - Dreamforce '14: Generic Package Extension Architecture for App...CRMScienceKirk
 

La actualidad más candente (11)

Swings in java
Swings in javaSwings in java
Swings in java
 
Strategy Design Pattern
Strategy Design PatternStrategy Design Pattern
Strategy Design Pattern
 
Mieux programmer grâce aux design patterns
Mieux programmer grâce aux design patternsMieux programmer grâce aux design patterns
Mieux programmer grâce aux design patterns
 
GWT Widgets
GWT WidgetsGWT Widgets
GWT Widgets
 
Creational pattern 2
Creational pattern 2Creational pattern 2
Creational pattern 2
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
 
Chapter 1 swings
Chapter 1 swingsChapter 1 swings
Chapter 1 swings
 
The AWT and Swing
The AWT and SwingThe AWT and Swing
The AWT and Swing
 
Abstract factory
Abstract factoryAbstract factory
Abstract factory
 
CRM Science - Dreamforce '14: Generic Package Extension Architecture for App...
CRM Science - Dreamforce '14:  Generic Package Extension Architecture for App...CRM Science - Dreamforce '14:  Generic Package Extension Architecture for App...
CRM Science - Dreamforce '14: Generic Package Extension Architecture for App...
 
Java swing
Java swingJava swing
Java swing
 

Similar a Modularization Strategies - Fixing Class and Package Tangles

Java Generics
Java GenericsJava Generics
Java Genericsjeslie
 
SOLID principles with Typescript examples
SOLID principles with Typescript examplesSOLID principles with Typescript examples
SOLID principles with Typescript examplesAndrew Nester
 
SystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummarySystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummaryAmal Khailtash
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEDarwin Durand
 
JAVA,WITH__N^E^T&BE)ANS)()()(((&(&&^&^^&^$.pdf
JAVA,WITH__N^E^T&BE)ANS)()()(((&(&&^&^^&^$.pdfJAVA,WITH__N^E^T&BE)ANS)()()(((&(&&^&^^&^$.pdf
JAVA,WITH__N^E^T&BE)ANS)()()(((&(&&^&^^&^$.pdfarchanenterprises
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languagesRafael Winterhalter
 
Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012Anton Arhipov
 
Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4Matt
 
Java Programs
Java ProgramsJava Programs
Java Programsvvpadhu
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsMuhammadTalha436
 
1 MVC – Ajax and Modal Views AJAX stands for Asynch.docx
1  MVC – Ajax and Modal Views AJAX stands for Asynch.docx1  MVC – Ajax and Modal Views AJAX stands for Asynch.docx
1 MVC – Ajax and Modal Views AJAX stands for Asynch.docxhoney725342
 
MVM - It's all in the (Implementation) Details
MVM - It's all in the (Implementation) DetailsMVM - It's all in the (Implementation) Details
MVM - It's all in the (Implementation) DetailsFlorina Muntenescu
 

Similar a Modularization Strategies - Fixing Class and Package Tangles (20)

Java Generics
Java GenericsJava Generics
Java Generics
 
SOLID principles with Typescript examples
SOLID principles with Typescript examplesSOLID principles with Typescript examples
SOLID principles with Typescript examples
 
SystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummarySystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features Summary
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
 
Diifeerences In C#
Diifeerences In C#Diifeerences In C#
Diifeerences In C#
 
JAVA,WITH__N^E^T&BE)ANS)()()(((&(&&^&^^&^$.pdf
JAVA,WITH__N^E^T&BE)ANS)()()(((&(&&^&^^&^$.pdfJAVA,WITH__N^E^T&BE)ANS)()()(((&(&&^&^^&^$.pdf
JAVA,WITH__N^E^T&BE)ANS)()()(((&(&&^&^^&^$.pdf
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languages
 
Inheritance
InheritanceInheritance
Inheritance
 
Java interface
Java interfaceJava interface
Java interface
 
Java Programming - 05 access control in java
Java Programming - 05 access control in javaJava Programming - 05 access control in java
Java Programming - 05 access control in java
 
Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012
 
droidparts
droidpartsdroidparts
droidparts
 
Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
1 MVC – Ajax and Modal Views AJAX stands for Asynch.docx
1  MVC – Ajax and Modal Views AJAX stands for Asynch.docx1  MVC – Ajax and Modal Views AJAX stands for Asynch.docx
1 MVC – Ajax and Modal Views AJAX stands for Asynch.docx
 
MVM - It's all in the (Implementation) Details
MVM - It's all in the (Implementation) DetailsMVM - It's all in the (Implementation) Details
MVM - It's all in the (Implementation) Details
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 

Más de CodeOps Technologies LLP

AWS Serverless Event-driven Architecture - in lastminute.com meetup
AWS Serverless Event-driven Architecture - in lastminute.com meetupAWS Serverless Event-driven Architecture - in lastminute.com meetup
AWS Serverless Event-driven Architecture - in lastminute.com meetupCodeOps Technologies LLP
 
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONSBUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONSCodeOps Technologies LLP
 
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICES
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICESAPPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICES
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICESCodeOps Technologies LLP
 
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPS
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPSBUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPS
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPSCodeOps Technologies LLP
 
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNER
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNERCREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNER
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNERCodeOps Technologies LLP
 
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...CodeOps Technologies LLP
 
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESS
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESSWRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESS
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESSCodeOps Technologies LLP
 
Training And Serving ML Model Using Kubeflow by Jayesh Sharma
Training And Serving ML Model Using Kubeflow by Jayesh SharmaTraining And Serving ML Model Using Kubeflow by Jayesh Sharma
Training And Serving ML Model Using Kubeflow by Jayesh SharmaCodeOps Technologies LLP
 
Deploy Microservices To Kubernetes Without Secrets by Reenu Saluja
Deploy Microservices To Kubernetes Without Secrets by Reenu SalujaDeploy Microservices To Kubernetes Without Secrets by Reenu Saluja
Deploy Microservices To Kubernetes Without Secrets by Reenu SalujaCodeOps Technologies LLP
 
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...CodeOps Technologies LLP
 
YAML Tips For Kubernetes by Neependra Khare
YAML Tips For Kubernetes by Neependra KhareYAML Tips For Kubernetes by Neependra Khare
YAML Tips For Kubernetes by Neependra KhareCodeOps Technologies LLP
 
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...CodeOps Technologies LLP
 
Monitor Azure Kubernetes Cluster With Prometheus by Mamta Jha
Monitor Azure Kubernetes Cluster With Prometheus by Mamta JhaMonitor Azure Kubernetes Cluster With Prometheus by Mamta Jha
Monitor Azure Kubernetes Cluster With Prometheus by Mamta JhaCodeOps Technologies LLP
 
Functional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and StreamsFunctional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and StreamsCodeOps Technologies LLP
 
Distributed Tracing: New DevOps Foundation
Distributed Tracing: New DevOps FoundationDistributed Tracing: New DevOps Foundation
Distributed Tracing: New DevOps FoundationCodeOps Technologies LLP
 
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire  "Distributed Tracing: New DevOps Foundation" by Jayesh Ahire
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire CodeOps Technologies LLP
 

Más de CodeOps Technologies LLP (20)

AWS Serverless Event-driven Architecture - in lastminute.com meetup
AWS Serverless Event-driven Architecture - in lastminute.com meetupAWS Serverless Event-driven Architecture - in lastminute.com meetup
AWS Serverless Event-driven Architecture - in lastminute.com meetup
 
Understanding azure batch service
Understanding azure batch serviceUnderstanding azure batch service
Understanding azure batch service
 
DEVOPS AND MACHINE LEARNING
DEVOPS AND MACHINE LEARNINGDEVOPS AND MACHINE LEARNING
DEVOPS AND MACHINE LEARNING
 
SERVERLESS MIDDLEWARE IN AZURE FUNCTIONS
SERVERLESS MIDDLEWARE IN AZURE FUNCTIONSSERVERLESS MIDDLEWARE IN AZURE FUNCTIONS
SERVERLESS MIDDLEWARE IN AZURE FUNCTIONS
 
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONSBUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
 
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICES
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICESAPPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICES
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICES
 
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPS
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPSBUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPS
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPS
 
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNER
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNERCREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNER
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNER
 
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...
 
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESS
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESSWRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESS
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESS
 
Training And Serving ML Model Using Kubeflow by Jayesh Sharma
Training And Serving ML Model Using Kubeflow by Jayesh SharmaTraining And Serving ML Model Using Kubeflow by Jayesh Sharma
Training And Serving ML Model Using Kubeflow by Jayesh Sharma
 
Deploy Microservices To Kubernetes Without Secrets by Reenu Saluja
Deploy Microservices To Kubernetes Without Secrets by Reenu SalujaDeploy Microservices To Kubernetes Without Secrets by Reenu Saluja
Deploy Microservices To Kubernetes Without Secrets by Reenu Saluja
 
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...
 
YAML Tips For Kubernetes by Neependra Khare
YAML Tips For Kubernetes by Neependra KhareYAML Tips For Kubernetes by Neependra Khare
YAML Tips For Kubernetes by Neependra Khare
 
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
 
Monitor Azure Kubernetes Cluster With Prometheus by Mamta Jha
Monitor Azure Kubernetes Cluster With Prometheus by Mamta JhaMonitor Azure Kubernetes Cluster With Prometheus by Mamta Jha
Monitor Azure Kubernetes Cluster With Prometheus by Mamta Jha
 
Jet brains space intro presentation
Jet brains space intro presentationJet brains space intro presentation
Jet brains space intro presentation
 
Functional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and StreamsFunctional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and Streams
 
Distributed Tracing: New DevOps Foundation
Distributed Tracing: New DevOps FoundationDistributed Tracing: New DevOps Foundation
Distributed Tracing: New DevOps Foundation
 
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire  "Distributed Tracing: New DevOps Foundation" by Jayesh Ahire
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire
 

Último

MUT4SLX: Extensions for Mutation Testing of Stateflow Models
MUT4SLX: Extensions for Mutation Testing of Stateflow ModelsMUT4SLX: Extensions for Mutation Testing of Stateflow Models
MUT4SLX: Extensions for Mutation Testing of Stateflow ModelsUniversity of Antwerp
 
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...jackiepotts6
 
User Experience Designer | Kaylee Miller Resume
User Experience Designer | Kaylee Miller ResumeUser Experience Designer | Kaylee Miller Resume
User Experience Designer | Kaylee Miller ResumeKaylee Miller
 
VuNet software organisation powerpoint deck
VuNet software organisation powerpoint deckVuNet software organisation powerpoint deck
VuNet software organisation powerpoint deckNaval Singh
 
Mobile App Development process | Expert Tips
Mobile App Development process | Expert TipsMobile App Development process | Expert Tips
Mobile App Development process | Expert Tipsmichealwillson701
 
Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfPractical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfICS
 
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...Maxim Salnikov
 
Large Scale Architecture -- The Unreasonable Effectiveness of Simplicity
Large Scale Architecture -- The Unreasonable Effectiveness of SimplicityLarge Scale Architecture -- The Unreasonable Effectiveness of Simplicity
Large Scale Architecture -- The Unreasonable Effectiveness of SimplicityRandy Shoup
 
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...Splashtop Inc
 
Unlocking the Power of IoT: A comprehensive approach to real-time insights
Unlocking the Power of IoT: A comprehensive approach to real-time insightsUnlocking the Power of IoT: A comprehensive approach to real-time insights
Unlocking the Power of IoT: A comprehensive approach to real-time insightsconfluent
 
8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdf8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdfOffsiteNOC
 
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdfFlutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdfMind IT Systems
 
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...telebusocialmarketin
 
Technical improvements. Reasons. Methods. Estimations. CJ
Technical improvements.  Reasons. Methods. Estimations. CJTechnical improvements.  Reasons. Methods. Estimations. CJ
Technical improvements. Reasons. Methods. Estimations. CJpolinaucc
 
BusinessGPT - SECURITY AND GOVERNANCE FOR GENERATIVE AI.pptx
BusinessGPT  - SECURITY AND GOVERNANCE  FOR GENERATIVE AI.pptxBusinessGPT  - SECURITY AND GOVERNANCE  FOR GENERATIVE AI.pptx
BusinessGPT - SECURITY AND GOVERNANCE FOR GENERATIVE AI.pptxAGATSoftware
 
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptxCYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptxBarakaMuyengi
 
Boost Efficiency: Sabre API Integration Made Easy
Boost Efficiency: Sabre API Integration Made EasyBoost Efficiency: Sabre API Integration Made Easy
Boost Efficiency: Sabre API Integration Made Easymichealwillson701
 
Leveling Up your Branding and Mastering MERN: Fullstack WebDev
Leveling Up your Branding and Mastering MERN: Fullstack WebDevLeveling Up your Branding and Mastering MERN: Fullstack WebDev
Leveling Up your Branding and Mastering MERN: Fullstack WebDevpmgdscunsri
 
Enterprise Content Managements Solutions
Enterprise Content Managements SolutionsEnterprise Content Managements Solutions
Enterprise Content Managements SolutionsIQBG inc
 

Último (20)

MUT4SLX: Extensions for Mutation Testing of Stateflow Models
MUT4SLX: Extensions for Mutation Testing of Stateflow ModelsMUT4SLX: Extensions for Mutation Testing of Stateflow Models
MUT4SLX: Extensions for Mutation Testing of Stateflow Models
 
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
 
User Experience Designer | Kaylee Miller Resume
User Experience Designer | Kaylee Miller ResumeUser Experience Designer | Kaylee Miller Resume
User Experience Designer | Kaylee Miller Resume
 
VuNet software organisation powerpoint deck
VuNet software organisation powerpoint deckVuNet software organisation powerpoint deck
VuNet software organisation powerpoint deck
 
Mobile App Development process | Expert Tips
Mobile App Development process | Expert TipsMobile App Development process | Expert Tips
Mobile App Development process | Expert Tips
 
Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfPractical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdf
 
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...
 
Large Scale Architecture -- The Unreasonable Effectiveness of Simplicity
Large Scale Architecture -- The Unreasonable Effectiveness of SimplicityLarge Scale Architecture -- The Unreasonable Effectiveness of Simplicity
Large Scale Architecture -- The Unreasonable Effectiveness of Simplicity
 
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
 
Unlocking the Power of IoT: A comprehensive approach to real-time insights
Unlocking the Power of IoT: A comprehensive approach to real-time insightsUnlocking the Power of IoT: A comprehensive approach to real-time insights
Unlocking the Power of IoT: A comprehensive approach to real-time insights
 
8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdf8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdf
 
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdfFlutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
 
20140812 - OBD2 Solution
20140812 - OBD2 Solution20140812 - OBD2 Solution
20140812 - OBD2 Solution
 
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...
 
Technical improvements. Reasons. Methods. Estimations. CJ
Technical improvements.  Reasons. Methods. Estimations. CJTechnical improvements.  Reasons. Methods. Estimations. CJ
Technical improvements. Reasons. Methods. Estimations. CJ
 
BusinessGPT - SECURITY AND GOVERNANCE FOR GENERATIVE AI.pptx
BusinessGPT  - SECURITY AND GOVERNANCE  FOR GENERATIVE AI.pptxBusinessGPT  - SECURITY AND GOVERNANCE  FOR GENERATIVE AI.pptx
BusinessGPT - SECURITY AND GOVERNANCE FOR GENERATIVE AI.pptx
 
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptxCYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
 
Boost Efficiency: Sabre API Integration Made Easy
Boost Efficiency: Sabre API Integration Made EasyBoost Efficiency: Sabre API Integration Made Easy
Boost Efficiency: Sabre API Integration Made Easy
 
Leveling Up your Branding and Mastering MERN: Fullstack WebDev
Leveling Up your Branding and Mastering MERN: Fullstack WebDevLeveling Up your Branding and Mastering MERN: Fullstack WebDev
Leveling Up your Branding and Mastering MERN: Fullstack WebDev
 
Enterprise Content Managements Solutions
Enterprise Content Managements SolutionsEnterprise Content Managements Solutions
Enterprise Content Managements Solutions
 

Modularization Strategies - Fixing Class and Package Tangles

  • 1. MODULARIZING STRATEGIES: FIXING CLASS & PACKAGE TANGLES ganesh samarthyam (ganesh@codeops.tech)
  • 2. WHAT’S A “TANGLE”? ➤ “A tangle is a portion of a dependency graph within which all the items are directly or indirectly dependent on all the other nodes in the tangle.” (Source: structure101.com) Example of a class tangle (cycle) Example of a package tangle
  • 3. REMOVING TANGLES - VISUALISING IN STRUCTURE101
  • 5. DEPENDENCIES BETWEEN CONCRETE CLASSES - TANGLE import java.util.List; public class Customer { List<Order> orders; } class Order { Customer purchaser; } A direct cyclic dependency between the Customer & Order class because they contain instances of each other’s type
  • 6. DEPENDENCIES BETWEEN CONCRETE CLASSES - TANGLE - FIX import java.util.List; public class Customer { List<Order> orders; } class Order { Customer purchaser; } Depend on the interface instead of the implementation (and the cycle is gone) import java.util.List; interface Buyer {} public class Customer implements Buyer { List<Buyable> orders; } interface Buyable {} class Order implements Buyable { Buyer purchaser; }
  • 7. BASE CLASS REFERS TO ITS DERIVED TYPES(S) enum ImageType { JPEG, BMP, PNG }; abstract class Image { public static Image getImage(ImageType imageType, String name) { switch (imageType) { // JPEGImage, BMPImage, PNGImage are // derived classes of the abstract class Image case JPEG: return new JPEGImage(name); case BMP: return new BMPImage(name); case PNG: return new PNGImage(name); } return null; } } This is a special kind of cyclic dependency - the base type knows about its derived type! Here it is creation of its derived objects results in a tangle
  • 8. BASE CLASS REFERS TO ITS DERIVED TYPES(S) - FIX It’s easy to break this cyclic dependency - move the getImage() method to a dedicated class named ImageFactory!
  • 9. AVOIDABLE REFERENCES TO CLASSES - TANGLE In this case, the Target abstract class has unnecessary references to concrete classes; instead of overloading, could be specific method calls instead package main; abstract class Target { public abstract void genCode(Constant constant); public abstract void genCode(Plus plus); public abstract void genCode(Mult mult); } class JVMTarget extends Target { public void genCode(Constant constant) { System.out.println("bipush " + constant.getValue()); } public void genCode(Plus plus) { System.out.println("iadd"); } public void genCode(Mult mult) { System.out.println("imul"); } } class DotNetTarget extends Target { public void genCode(Constant constant) { System.out.println("ldarg " + constant.getValue()); } public void genCode(Plus plus) { System.out.println("add"); } public void genCode(Mult mult) { System.out.println("mul"); } } abstract class ExprNode { protected static Target target = new JVMTarget(); public static void setTarget(Target newTarget) { target = newTarget; } public abstract void genCode(); } class Constant extends ExprNode { int val; public Constant(int arg) { val = arg; } public int getValue() { return val; } public void genCode() { target.genCode(this); } }
  • 10. UNNECESSARY REFERENCES TO CLASSES - TANGLE - FIX abstract class Target { public abstract void genCodeConstant(int constValue); public abstract void genCodePlus(); public abstract void genCodeMult(); } class JVMTarget extends Target { public void genCodeConstant(int constValue) { System.out.println("bipush " + constValue); } public void genCodePlus() { System.out.println("iadd"); } public void genCodeMult() { System.out.println("imul"); } } abstract class Target { public abstract void genCode(Constant constant); public abstract void genCode(Plus plus); public abstract void genCode(Mult mult); } class JVMTarget extends Target { public void genCode(Constant constant) { System.out.println("bipush " + constant.getValue()); } public void genCode(Plus plus) { System.out.println("iadd"); } public void genCode(Mult mult) { System.out.println("imul"); } } By making the Target class not refer to the concrete ExprNode classes, the tangle is gone!
  • 11. SUMMARY - STRATEGIES FOR BREAKING CLASS TANGLES Cause(s) Potential Solution(s) References among concrete classes causes cycle(s)/tangle(s) Depend on the interfaces than on the concrete classes (extract interfaces if they are absent) A base class refers to one or more of its derived class(es) causing tangle(s) (e.g., base class creates objects of its derived types) Remove the offending references from base class to the derived class(es) (e.g., move the object creation to a dedicated factory class) Unnecessary references to classes causes tangles Remove the unnecessary references
  • 13. INTERFACE & IMPLEMENTATION PACKAGED TOGETHER Packaging the interface & corresponding implementation together causes tangle! package buyers; import buyables.Buyable; import java.util.List; interface Buyer {} public class Customer implements Buyer { List<Buyable> orders; } package buyables; interface Buyable {} public class Order implements Buyable { Buyer purchaser; }
  • 14. INTERFACE & IMPLEMENTATION PACKAGED TOGETHER - FIX Separating the interfaces as a separate package (from the implementation package) disentangles the structure!
  • 15. MISPLACED ENTITY - PACKAGE TANGLE An entity misplaced in a package causes a tangle (where does enum ImageType belong? In the “factory” package or “image” package? package image; import factory.ImageType; public abstract class Image { public abstract ImageType getType(); } package factory; public enum ImageType { JPEG, BMP, PNG } package imagetypes; import factory.ImageType; import image.Image; public class BMPImage extends Image { public BMPImage(String name) { super(); } public ImageType getType() { return ImageType.BMP; } }
  • 16. MISPLACED ENTITY - PACKAGE TANGLE - FIX Here, the entity “enum ImageType” arguably belongs better in “image” package than in the “factory” package (moving the enum breaks the tangle)
  • 17. MIXED PACKAGE - PACKAGE TANGLE Here, the Expr class and the builder class ExprBuilder (that builds objects) are put together in the same “core” package - this results in a tangle package core; import nodes.*; public class ExprBuilder { private Expr expr = null; public ExprBuilder() {} public ExprBuilder Const(int arg) { expr = Constant.make(arg); return this; } public ExprBuilder Plus(int arg) { expr = new Addition(expr, Constant.make(arg)); return this; } public ExprBuilder Mult(int arg) { expr = new Multiplication(expr, Constant.make(arg)); return this; } public Expr Build() { return expr; } }
  • 18. MIXED PACKAGE - PACKAGE TANGLE - FIX The tangle is broken by splitting the 
 “core” package into two packages (“core” and “builder”)
  • 19. SUMMARY - STRATEGIES FOR BREAKING PACKAGE TANGLES Cause(s) Potential Solution(s) Interfaces and implementations are mixed together Separate the interfaces and implementations to separate packages A class is misplaced in a package causing a tangle Move the offending class to a more suitable package Classes that may not belong together packaged into a single package cause a tangle Split the package