SlideShare une entreprise Scribd logo
1  sur  23
Design is an art
Art requires creativity
Creativity is a product of the brain
The brain can be understood scientifically
So, design is a science
Fragile base-class problem
class File {
private String contents = “”;
void write(String more) {
contents += more;
}
void writeMany(String[] mores) {
for (String more : mores) {
write(more);
}
}
}
class InstrumentedFile extends File {
private int writeCount;
@Override
void write(String more) {
writeCount++;
super.write(more);
}
int getWriteCount() {
return writeCount;
}
}
contents += more;
Solution
interface File {
void write(String more);
void writeMany(String[] mores);
}
interface InstrumentedFile extends File {
int getWriteCount();
}
abstract class AbstractFile implements File {
private String contents = “”;
@Override
public void write(String more) {
contents += more;
}
@Override
public void writeMany(String[] mores) {
for (String more : mores) {
write(more);
}
}
}
class InstrumentedFileImpl implements InstrumentedFile {
private int writeCount;
private File base;
InstrumentedFileImpl(File base) {
this.base = base;
}
@Override
public void write(String more) {
writeCount++;
base.write(more);
}
@Override
public void writeMany(String[] mores) {
writeCount++;
base.writeMany(mores);
}
@Override
public int getWriteCount() { return writeCount; }
}
Identify the differences (be nice)
The Decorator pattern
Proxy, Adapter, Facade
Is a square a rectangle?
class Rectangle {
private int len;
private int wid;
Rectangle(int l, int w) { len = l; wid = w; }
int getLength() { return len; }
void setLength(int l) { len = l; }
int getWidth() { return wid; }
void setWidth(int w) { wid = w; }
}
class Square extends Rectangle {
Square(int s) { super(s, s); }
int getSide() { return getLength(); }
void setSide(int s) {
setLength(s);
setWidth(s);
}
}
Rectangle sq = new Square(100);
sq.setLength(40);
Solution
class Rectangle {
private int len;
private int wid;
Rectangle(int l, int w) { len = l; wid = w; }
int getLength() { return len; }
void setLength(int l) { len = l; }
int getWidth() { return wid; }
void setWidth(int w) { wid = w; }
}
class Square {
private Rectangle rect;
Square(int s) {
rect = new Rectangle(s, s);
}
int getSide() { return rect.getLength();}
void setSide(int s) {
rect.setLength(s);
rect.setWidth(s);
}
}
But I want polymorphism to compute areas
interface Areable {
int getArea();
}
class Rectangle implements Areable {
…
@Override
public int getArea() {
return len * wid;
}
}
class Square implements Areable {
…
@Override
public int getArea() {
return rect.getArea();
}
}
List<Areable> areables = …
for (Areable ar : areables) {
System.out.println(ar.getArea());
}
This is what OOP is all
about.
Euclid’s GCD algorithm
The Composite pattern
Which car do you want?
The Strategy pattern
The Builder pattern
There shall be no
other king!
Code: Deep dive
Prescription
Define contracts by creating interfaces
Keep interfaces small and mutually exclusive
Add behavior by implementing these interfaces
Depend only on interfaces, not implementations
Depend only on direct dependencies
Further reading + coding
https://github.com/gokul2411s/patternsrepo
Read the Gang of Four book
Read books by Martin Fowler and Robert Martin (Uncle Bob)
Experience
Duh where’s the brand?
Google
Susquehanna International Group
UPenn GRASP robotics
Schlumberger
NIT Surathkal

Contenu connexe

Tendances

All You Need is Fold in the Key of C#
All You Need is Fold in the Key of C#All You Need is Fold in the Key of C#
All You Need is Fold in the Key of C#Mike Harris
 
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : NotesCUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : NotesSubhajit Sahu
 
The Ring programming language version 1.7 book - Part 28 of 196
The Ring programming language version 1.7 book - Part 28 of 196The Ring programming language version 1.7 book - Part 28 of 196
The Ring programming language version 1.7 book - Part 28 of 196Mahmoud Samir Fayed
 
Computer Graphics Lab
Computer Graphics LabComputer Graphics Lab
Computer Graphics LabNeil Mathew
 
Pointer Events in Canvas
Pointer Events in CanvasPointer Events in Canvas
Pointer Events in Canvasdeanhudson
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma mohan
 
SE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneSE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneBhavesh Shah
 
The Algorithms of CSS @ CSSConf EU 2018
The Algorithms of CSS @ CSSConf EU 2018The Algorithms of CSS @ CSSConf EU 2018
The Algorithms of CSS @ CSSConf EU 2018Lara Schenck
 
How to extend map? Or why we need collections redesign? - Scalar 2017
How to extend map? Or why we need collections redesign? - Scalar 2017How to extend map? Or why we need collections redesign? - Scalar 2017
How to extend map? Or why we need collections redesign? - Scalar 2017Szymon Matejczyk
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALVivek Kumar Sinha
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics labPriya Goyal
 

Tendances (20)

Advance java
Advance javaAdvance java
Advance java
 
All You Need is Fold in the Key of C#
All You Need is Fold in the Key of C#All You Need is Fold in the Key of C#
All You Need is Fold in the Key of C#
 
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : NotesCUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
 
Sortings
SortingsSortings
Sortings
 
The Ring programming language version 1.7 book - Part 28 of 196
The Ring programming language version 1.7 book - Part 28 of 196The Ring programming language version 1.7 book - Part 28 of 196
The Ring programming language version 1.7 book - Part 28 of 196
 
Computer Graphics Lab
Computer Graphics LabComputer Graphics Lab
Computer Graphics Lab
 
Pointer Events in Canvas
Pointer Events in CanvasPointer Events in Canvas
Pointer Events in Canvas
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
SE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneSE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of Pune
 
The Algorithms of CSS @ CSSConf EU 2018
The Algorithms of CSS @ CSSConf EU 2018The Algorithms of CSS @ CSSConf EU 2018
The Algorithms of CSS @ CSSConf EU 2018
 
Lec16
Lec16Lec16
Lec16
 
How to extend map? Or why we need collections redesign? - Scalar 2017
How to extend map? Or why we need collections redesign? - Scalar 2017How to extend map? Or why we need collections redesign? - Scalar 2017
How to extend map? Or why we need collections redesign? - Scalar 2017
 
Python programing
Python programingPython programing
Python programing
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUAL
 
2-D array
2-D array2-D array
2-D array
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
 
CLUSTERGRAM
CLUSTERGRAMCLUSTERGRAM
CLUSTERGRAM
 
Maps&hash tables
Maps&hash tablesMaps&hash tables
Maps&hash tables
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 

Similaire à Software Design Thinking

Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldBTI360
 
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo....NET Conf UY
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kirill Rozov
 
Why Scala is the better Java
Why Scala is the better JavaWhy Scala is the better Java
Why Scala is the better JavaThomas Kaiser
 
Kotlin, Spek and tests
Kotlin, Spek and testsKotlin, Spek and tests
Kotlin, Spek and testsintive
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
Java весна 2013 лекция 2
Java весна 2013 лекция 2Java весна 2013 лекция 2
Java весна 2013 лекция 2Technopark
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlinintelliyole
 
Les nouveautés de C# 6
Les nouveautés de C# 6Les nouveautés de C# 6
Les nouveautés de C# 6Microsoft
 

Similaire à Software Design Thinking (20)

662305 10
662305 10662305 10
662305 10
 
Dotnet 18
Dotnet 18Dotnet 18
Dotnet 18
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
 
C# Is The Future
C# Is The FutureC# Is The Future
C# Is The Future
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
 
Benefits of Kotlin
Benefits of KotlinBenefits of Kotlin
Benefits of Kotlin
 
mobl
moblmobl
mobl
 
Why Scala is the better Java
Why Scala is the better JavaWhy Scala is the better Java
Why Scala is the better Java
 
Kotlin, Spek and tests
Kotlin, Spek and testsKotlin, Spek and tests
Kotlin, Spek and tests
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Java весна 2013 лекция 2
Java весна 2013 лекция 2Java весна 2013 лекция 2
Java весна 2013 лекция 2
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
C++ programs
C++ programsC++ programs
C++ programs
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
 
Les nouveautés de C# 6
Les nouveautés de C# 6Les nouveautés de C# 6
Les nouveautés de C# 6
 
Scala best practices
Scala best practicesScala best practices
Scala best practices
 
TechTalk - Dotnet
TechTalk - DotnetTechTalk - Dotnet
TechTalk - Dotnet
 
Lezione03
Lezione03Lezione03
Lezione03
 

Plus de GeekNightHyderabad

Testing strategies in microservices
Testing strategies in microservicesTesting strategies in microservices
Testing strategies in microservicesGeekNightHyderabad
 
Scaling enterprise digital platforms with kubernetes
Scaling enterprise digital platforms with kubernetesScaling enterprise digital platforms with kubernetes
Scaling enterprise digital platforms with kubernetesGeekNightHyderabad
 
FreedomBox & Community Wi-Fi networks
FreedomBox & Community Wi-Fi networksFreedomBox & Community Wi-Fi networks
FreedomBox & Community Wi-Fi networksGeekNightHyderabad
 
Rendezvous with aucovei (autonomous connected car)
Rendezvous with aucovei (autonomous connected car)Rendezvous with aucovei (autonomous connected car)
Rendezvous with aucovei (autonomous connected car)GeekNightHyderabad
 
Role of AI & ML in beauty care industry
Role of AI & ML in beauty care industryRole of AI & ML in beauty care industry
Role of AI & ML in beauty care industryGeekNightHyderabad
 
Design lean agile_thinking presentation
Design lean agile_thinking presentationDesign lean agile_thinking presentation
Design lean agile_thinking presentationGeekNightHyderabad
 
Hardware hacking and internet of things
Hardware hacking and internet of thingsHardware hacking and internet of things
Hardware hacking and internet of thingsGeekNightHyderabad
 
Spring to Cloud - REST To Microservices
Spring to Cloud - REST To MicroservicesSpring to Cloud - REST To Microservices
Spring to Cloud - REST To MicroservicesGeekNightHyderabad
 
Building Cloud Native Applications Using Spring Boot and Spring Cloud
Building Cloud Native Applications Using Spring Boot and Spring CloudBuilding Cloud Native Applications Using Spring Boot and Spring Cloud
Building Cloud Native Applications Using Spring Boot and Spring CloudGeekNightHyderabad
 
Progressive Web Applications - The Next Gen Web Technologies
Progressive Web Applications - The Next Gen Web TechnologiesProgressive Web Applications - The Next Gen Web Technologies
Progressive Web Applications - The Next Gen Web TechnologiesGeekNightHyderabad
 
Scaling a Game Server: From 500 to 100,000 Users
Scaling a Game Server: From 500 to 100,000 UsersScaling a Game Server: From 500 to 100,000 Users
Scaling a Game Server: From 500 to 100,000 UsersGeekNightHyderabad
 
Big Data - Need of Converged Data Platform
Big Data - Need of Converged Data PlatformBig Data - Need of Converged Data Platform
Big Data - Need of Converged Data PlatformGeekNightHyderabad
 
Building a Data Lake - An App Dev's Perspective
Building a Data Lake - An App Dev's PerspectiveBuilding a Data Lake - An App Dev's Perspective
Building a Data Lake - An App Dev's PerspectiveGeekNightHyderabad
 
Understanding the Intelligent Cloud
Understanding the Intelligent CloudUnderstanding the Intelligent Cloud
Understanding the Intelligent CloudGeekNightHyderabad
 

Plus de GeekNightHyderabad (20)

Testing strategies in microservices
Testing strategies in microservicesTesting strategies in microservices
Testing strategies in microservices
 
Metaprogramming ruby
Metaprogramming rubyMetaprogramming ruby
Metaprogramming ruby
 
Scaling enterprise digital platforms with kubernetes
Scaling enterprise digital platforms with kubernetesScaling enterprise digital platforms with kubernetes
Scaling enterprise digital platforms with kubernetes
 
FreedomBox & Community Wi-Fi networks
FreedomBox & Community Wi-Fi networksFreedomBox & Community Wi-Fi networks
FreedomBox & Community Wi-Fi networks
 
Rendezvous with aucovei (autonomous connected car)
Rendezvous with aucovei (autonomous connected car)Rendezvous with aucovei (autonomous connected car)
Rendezvous with aucovei (autonomous connected car)
 
Role of AI & ML in beauty care industry
Role of AI & ML in beauty care industryRole of AI & ML in beauty care industry
Role of AI & ML in beauty care industry
 
Breaking down a monolith
Breaking down a monolithBreaking down a monolith
Breaking down a monolith
 
Design lean agile_thinking presentation
Design lean agile_thinking presentationDesign lean agile_thinking presentation
Design lean agile_thinking presentation
 
Scaling pipelines
Scaling pipelinesScaling pipelines
Scaling pipelines
 
Blockchain beyond bitcoin
Blockchain beyond bitcoinBlockchain beyond bitcoin
Blockchain beyond bitcoin
 
Http/2
Http/2Http/2
Http/2
 
Hardware hacking and internet of things
Hardware hacking and internet of thingsHardware hacking and internet of things
Hardware hacking and internet of things
 
Spring to Cloud - REST To Microservices
Spring to Cloud - REST To MicroservicesSpring to Cloud - REST To Microservices
Spring to Cloud - REST To Microservices
 
Serverless
ServerlessServerless
Serverless
 
Building Cloud Native Applications Using Spring Boot and Spring Cloud
Building Cloud Native Applications Using Spring Boot and Spring CloudBuilding Cloud Native Applications Using Spring Boot and Spring Cloud
Building Cloud Native Applications Using Spring Boot and Spring Cloud
 
Progressive Web Applications - The Next Gen Web Technologies
Progressive Web Applications - The Next Gen Web TechnologiesProgressive Web Applications - The Next Gen Web Technologies
Progressive Web Applications - The Next Gen Web Technologies
 
Scaling a Game Server: From 500 to 100,000 Users
Scaling a Game Server: From 500 to 100,000 UsersScaling a Game Server: From 500 to 100,000 Users
Scaling a Game Server: From 500 to 100,000 Users
 
Big Data - Need of Converged Data Platform
Big Data - Need of Converged Data PlatformBig Data - Need of Converged Data Platform
Big Data - Need of Converged Data Platform
 
Building a Data Lake - An App Dev's Perspective
Building a Data Lake - An App Dev's PerspectiveBuilding a Data Lake - An App Dev's Perspective
Building a Data Lake - An App Dev's Perspective
 
Understanding the Intelligent Cloud
Understanding the Intelligent CloudUnderstanding the Intelligent Cloud
Understanding the Intelligent Cloud
 

Dernier

[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
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 2024Victor Rentea
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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...apidays
 
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 FMESafe Software
 
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 WoodJuan lago vázquez
 
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 AmsterdamUiPathCommunity
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
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 FMESafe Software
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
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.pdfOrbitshub
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
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, Adobeapidays
 

Dernier (20)

[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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...
 
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
 
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
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
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
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 

Software Design Thinking

  • 1.
  • 2. Design is an art Art requires creativity Creativity is a product of the brain The brain can be understood scientifically So, design is a science
  • 3.
  • 4. Fragile base-class problem class File { private String contents = “”; void write(String more) { contents += more; } void writeMany(String[] mores) { for (String more : mores) { write(more); } } } class InstrumentedFile extends File { private int writeCount; @Override void write(String more) { writeCount++; super.write(more); } int getWriteCount() { return writeCount; } } contents += more;
  • 5. Solution interface File { void write(String more); void writeMany(String[] mores); } interface InstrumentedFile extends File { int getWriteCount(); } abstract class AbstractFile implements File { private String contents = “”; @Override public void write(String more) { contents += more; } @Override public void writeMany(String[] mores) { for (String more : mores) { write(more); } } } class InstrumentedFileImpl implements InstrumentedFile { private int writeCount; private File base; InstrumentedFileImpl(File base) { this.base = base; } @Override public void write(String more) { writeCount++; base.write(more); } @Override public void writeMany(String[] mores) { writeCount++; base.writeMany(mores); } @Override public int getWriteCount() { return writeCount; } }
  • 9. Is a square a rectangle? class Rectangle { private int len; private int wid; Rectangle(int l, int w) { len = l; wid = w; } int getLength() { return len; } void setLength(int l) { len = l; } int getWidth() { return wid; } void setWidth(int w) { wid = w; } } class Square extends Rectangle { Square(int s) { super(s, s); } int getSide() { return getLength(); } void setSide(int s) { setLength(s); setWidth(s); } } Rectangle sq = new Square(100); sq.setLength(40);
  • 10. Solution class Rectangle { private int len; private int wid; Rectangle(int l, int w) { len = l; wid = w; } int getLength() { return len; } void setLength(int l) { len = l; } int getWidth() { return wid; } void setWidth(int w) { wid = w; } } class Square { private Rectangle rect; Square(int s) { rect = new Rectangle(s, s); } int getSide() { return rect.getLength();} void setSide(int s) { rect.setLength(s); rect.setWidth(s); } }
  • 11. But I want polymorphism to compute areas interface Areable { int getArea(); } class Rectangle implements Areable { … @Override public int getArea() { return len * wid; } } class Square implements Areable { … @Override public int getArea() { return rect.getArea(); } } List<Areable> areables = … for (Areable ar : areables) { System.out.println(ar.getArea()); } This is what OOP is all about.
  • 14.
  • 15. Which car do you want?
  • 17.
  • 19. There shall be no other king!
  • 21. Prescription Define contracts by creating interfaces Keep interfaces small and mutually exclusive Add behavior by implementing these interfaces Depend only on interfaces, not implementations Depend only on direct dependencies
  • 22. Further reading + coding https://github.com/gokul2411s/patternsrepo Read the Gang of Four book Read books by Martin Fowler and Robert Martin (Uncle Bob) Experience
  • 23. Duh where’s the brand? Google Susquehanna International Group UPenn GRASP robotics Schlumberger NIT Surathkal

Notes de l'éditeur

  1. Good evening ladies and gentlemen. My name is Gokul. Today, we’ll learn about design patterns and architectural principles that can help us in both our day-to-day coding activities and the relatively rarer software design exercises. There are two reasons I included this slide. Firstly, it’s the heading for what we are going to discuss here today. And secondly, because it represents an anti-pattern in making ppts. I took two good images (one of the Dancing Building in Prague, Czech Republic and another a wordart of today’s session) and superimposed them, and now the overall effect is somewhat unclean. We’ll see today how to avoid such mistakes in software.
  2. This is my answer to whether design is an art or a science. The reality is that it is a bit of both.
  3. (Get a sense from the audience about OOP concepts.) In OOP, we have objects, and the interaction between these objects constitutes a program. Objects are created from templates usually called classes. Classes encompass a structure consisting of sub-objects and behavior. At any point in the run of the program, the object has a certain state. The behavior may vary based on state. With inheritance, we can express an IS-A relationship between objects. With such a relationship, we can extend the behavior of existing objects, by first inheriting their behavior and then adding more behavior. Thus, inheritance leads to a hierarchy. Reasoning about a hierarchy of behaviors is quite tricky and can lead developers to write buggy code. As a result, there is a general principle that says “ Avoid inheritance of behavior, or in order words implementation inheritance”.
  4. Here, we have implemented a File as a class, and provided the capability to write to the file via two methods write and writeMany. The latter is meant to provide a more efficient implementation, but in this case, its not really any more efficient. But that’s not the focal point here, so its ok. Lets say we have a requirement to instrument file writes. As an example, consider the problem of counting the number of file writes. Instead of modifying the original file, which is say not in our control, we use inheritance to write a class called InstrumentedFile. This class inherits the behavior from the File class, but also overrides the write method to provide additional wrapping functionality. Since this takes care of both write and writeMany in the current implementation, all is fine. However, the problem starts when the owner of the File class decides to make this change. In this case, the implementation of InstrumentedFile is now broken since it does not account for the writeMany methods any more. Here, a change in one part of the codebase caused another part to break. This is called fragility and often a result of using inheritance to inherit behavior / implementation.
  5. Here, we make File an interface and provide a skeletal (basic) implementation via an AbstractFile class, which is an abstract class and cannot be instantiated directly. Any subclass can now either directly implement the File interface or extent the AbstractFile class, depending on whether it wants the basic functionality or not. This is how the entire Java library is structured. Then, we have the InstrumentedFile interface which adds the getWriteCount method. The implementation class InstrumentedFileImpl composes a File object and provides its functionality without introducing any coupling with the behavior of the composed File object.
  6. These three images have more in common than they have different. They all represent the same person. Maybe the shoes, clothing, hairdo and jewelry are different, but that does not change the fact that the same person has been decorated differently.
  7. The decorator pattern says Extend by decoration, not by inheritance.
  8. The six sides of a dice are all different, and yet they belong to the same dice. The decorator, proxy, adapter and facade patterns have a similar relationship. Proxies and decorators are similar because they provide additional functionality on top of an existing object. But proxies do so while adhering to the same interface and decorators enhance the interface. Thus, proxies can only provide implementation improvements like caching, or lazy loading etc, and decorators for new publicly visible behvaior. Facades and adapters are similar because they adapt from one or more interfaces to a new one. But facades do so for simplifying and removing reliance of multiple smaller interfaces. And adapters do so for transforming one contract to another. How different the two contracts are depends on the scenario.
  9. We all know that a square is a rectangle with equal sides. Here, we try to represent this fact via inheritance. Here, we inherit the structure of a rectangle, but also behavior such as setLength and setWidth, which individually do not make sense for a Square. So, client code could mistakenly call the setLength method on a square and violate the invariant that the sides of a square are equal in length. The reason for this problem is that the square has stricter constraints than a rectangle on structure, but the inherited behavior of the rectangle allows clients to violate these stricter constraints. While inheriting, we must keep in mind to ensure that the child class follows the Liskov substitution principle: “Be more forgiving in your inputs, but be stricter in your outputs.” This principle allows us to successfully use polymorphism.
  10. We solved the problem by entirely avoiding inheritance. Simple use composition, because now, the behaviors of the rectangle, except those exposed by the square do not seep through.
  11. The previous solution worked for us, and solved the problems arising due to implementation inheritance. But, what if we wanted polymorphism in order to treat rectangles and squares the same way for the purpose of computing areas? This is actually quite simple. We can continue with the current structure of the two classes, but just add a new interface and have these classes implement this interface. This gives us the required polymorphism with reuse of code in a backward compatible manner. What if we wanted to treat rectangles and squares similarly for the purposes of scaling the size? We could just add a new interface and implement it too. Thus, by creating small interfaces and adding them as required, we can accomplish our goals in an extensible manner.
  12. In the previous exercise, we saw how to implement a square in terms of a rectangle. But suppose you had to implement a rectangle in terms of squares. How can we do this? The answer dates back to 300 BC when Euclid described an algorithm to compute the greatest common divisor of two integers. The geometric interpretation of this algorithm give us what we are looking for. (Describe the algorithm.) The important matter here is that this geometric structure fits perfectly into the confines of a design pattern called the composite pattern. A composite pattern is a recursive structure. (Explain recursion.) Examples: HTML, Linux file system etc.
  13. (Show code and explain.)
  14. This is Leonardo Da Vinci. He was into “invention painting sculpting architecture science music mathematics engineering literature anatomy geology astronomy botany writing history cartography” etc. He even invented the helicopter. People with such talent and capabilities are often hard to understand. And it makes them cool. But software that is hard to understand is not cool. So, we wanted to represent complex ideas in software, how can we make it easy to understand? We can do so by breaking down logic in small mutually-exclusive pieces, and then put together these pieces to obtain the required functionality. This makes for reusable code, because we can change the behavior of the application easily by wiring existing pieces differently or adding new pieces.
  15. Consider an example. Here, we have different cars from our Indian carmaker: Tata. Each car is very complex, has different behaviors, but they also share lots of common components and behavior. What would we do if we have to do if we were to build software for representing these cars, and allow the addition of new cars easily?
  16. Often, we have huge objects (such as a car), which host a lot of functionality and we want to compose them with lots of behavior. Here, we want to make sure that the resultant class structure is flexible, because we might soon want to compose other huge objects which have only slightly different behvaior. This is where the strategy pattern comes in. It leverages the “composition over inheritance” adage. More formally, it allows us to break an application into small client-specific contracts (each with their implementations) and compose these contracts to obtain more complex functionality. (Show code and explain.)
  17. When you ask someone where they live, they might give you wildly different answers, in part because they live in wildly different places. But usually, there is a lot of variance in the structure of their answer. Someone might give you the street they live on, someone the city, some humanitarian may tell you that they live on the kind and beloved planet earth, and a astronomer may tell you that we are all part of a tiny galaxy in the universe. If you wanted to represent an address in software, you would have to allow for this variability. In the world of OOP, an Address class will have to provide exponentially many constructors, which is both a maintainability nightmare and also just not extensible. Imagine adding new field to the address object. The solution to this problem is the Builder pattern.
  18. The builder pattern says: Separate the specification of the object from the creation of the object. (Show code and explain.)
  19. Here is an image of a king trying to dominate a town and make sure that the town has no other dominant player / king. This is representative of the Singleton pattern, which I am going to skip because it should not be used frequently. The only use cases for a Singleton object are when having more than one object of a certain kind can cause harm to your program, or it does not make logical sense to have more than one. E.g. Logger that writes to a log file, Database connections, caches.
  20. There are lots of patterns out there and we cannot cover them all in the time we have today. And anyway, just rote learning patterns is not going to help in the long run. So, lets take one step further and look at some toy problems which demonstrate the use of some more useful patterns. Once you go home, you can take up these problems and try to write code yourself, and see if you are able to make design patterns a natural part of your programming arsenal.