SlideShare a Scribd company logo
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

More Related Content

What's hot

Swings in java
Swings in javaSwings in java
Swings in java
Jyoti Totla
 
Strategy Design Pattern
Strategy Design PatternStrategy Design Pattern
Strategy Design Pattern
Ganesh 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 patterns
Geeks Anonymes
 
GWT Widgets
GWT WidgetsGWT Widgets
Creational pattern 2
Creational pattern 2Creational pattern 2
Creational pattern 2
Naga 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 Swing
adil raja
 
Abstract factory
Abstract factoryAbstract factory
Abstract factory
Muthukumar P
 
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
 
Java swing
Java swingJava swing
Java swing
Arati Gadgil
 

What's hot (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 to Modularization Strategies - Fixing Class and Package Tangles

Java Generics
Java GenericsJava Generics
Java Generics
jeslie
 
SOLID principles with Typescript examples
SOLID principles with Typescript examplesSOLID principles with Typescript examples
SOLID principles with Typescript examples
Andrew Nester
 
SystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummarySystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features Summary
Amal Khailtash
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
Andres Almiray
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEDarwin Durand
 
Diifeerences In C#
Diifeerences In C#Diifeerences In C#
Diifeerences In C#
rohit_gupta_mrt
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languages
Rafael Winterhalter
 
Java interface
Java interfaceJava interface
Java interface
Md. Tanvir Hossain
 
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
Danairat Thanabodithammachari
 
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-ch4
Matt
 
Java Programs
Java ProgramsJava Programs
Java Programs
vvpadhu
 
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
MuhammadTalha436
 
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
honey725342
 
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
Florina Muntenescu
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
Ducat India
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
Pankhuree Srivastava
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developers
Pavel Lahoda
 

Similar to 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#
 
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
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developers
 

More from 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 meetup
CodeOps Technologies LLP
 
Understanding azure batch service
Understanding azure batch serviceUnderstanding azure batch service
Understanding azure batch service
CodeOps Technologies LLP
 
DEVOPS AND MACHINE LEARNING
DEVOPS AND MACHINE LEARNINGDEVOPS AND MACHINE LEARNING
DEVOPS AND MACHINE LEARNING
CodeOps Technologies LLP
 
SERVERLESS MIDDLEWARE IN AZURE FUNCTIONS
SERVERLESS MIDDLEWARE IN AZURE FUNCTIONSSERVERLESS MIDDLEWARE IN AZURE FUNCTIONS
SERVERLESS MIDDLEWARE IN AZURE FUNCTIONS
CodeOps Technologies LLP
 
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONSBUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
CodeOps 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 SERVICES
CodeOps 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 DEVOPS
CodeOps 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 MANNER
CodeOps 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 SERVERLESS
CodeOps 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 Sharma
CodeOps 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 Saluja
CodeOps 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 Khare
CodeOps 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 Jha
CodeOps Technologies LLP
 
Jet brains space intro presentation
Jet brains space intro presentationJet brains space intro presentation
Jet brains space intro presentation
CodeOps 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 Streams
CodeOps Technologies LLP
 
Distributed Tracing: New DevOps Foundation
Distributed Tracing: New DevOps FoundationDistributed Tracing: New DevOps Foundation
Distributed Tracing: New DevOps Foundation
CodeOps 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
 

More from 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
 

Recently uploaded

Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 

Recently uploaded (20)

Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 

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