Better java with design
-
Upload
narayann-swaami -
Category
Software
-
view
295 -
download
0
Transcript of Better java with design
![Page 1: Better java with design](https://reader036.fdocuments.in/reader036/viewer/2022062900/58ed09931a28ab69758b458f/html5/thumbnails/1.jpg)
Java - Better with Design
Narayann SwaamiAgile Technical Coach
Societe Generale
![Page 2: Better java with design](https://reader036.fdocuments.in/reader036/viewer/2022062900/58ed09931a28ab69758b458f/html5/thumbnails/2.jpg)
Currently work as :
Agile Technical Coach @http://www.socgensolutions.com/
16 yrs poking around, 10+ years on Java
Interests:
Clean code, TDD, Parallel/Concurrent programming
About me
![Page 3: Better java with design](https://reader036.fdocuments.in/reader036/viewer/2022062900/58ed09931a28ab69758b458f/html5/thumbnails/3.jpg)
Summary
There are many ways of approaching best practices
Learn on your own
Learn from Industry standard books
Learn from conferences/meetups
![Page 4: Better java with design](https://reader036.fdocuments.in/reader036/viewer/2022062900/58ed09931a28ab69758b458f/html5/thumbnails/4.jpg)
How this came about
Coaching teams - working with them
Analyze what worked AND what did not work
Inspect and Adapt!
![Page 5: Better java with design](https://reader036.fdocuments.in/reader036/viewer/2022062900/58ed09931a28ab69758b458f/html5/thumbnails/5.jpg)
What we will learn today
Interesting best practices - From “Refactoring To Patterns”
![Page 6: Better java with design](https://reader036.fdocuments.in/reader036/viewer/2022062900/58ed09931a28ab69758b458f/html5/thumbnails/6.jpg)
How we do this
→ μ- Workshop → Two - three examples [ Time-Dependent ] → Refactoring workflow → Interactivity
![Page 7: Better java with design](https://reader036.fdocuments.in/reader036/viewer/2022062900/58ed09931a28ab69758b458f/html5/thumbnails/7.jpg)
Better OOP is better Java
Why?
![Page 8: Better java with design](https://reader036.fdocuments.in/reader036/viewer/2022062900/58ed09931a28ab69758b458f/html5/thumbnails/8.jpg)
Better Design is Better Java
Why?
![Page 9: Better java with design](https://reader036.fdocuments.in/reader036/viewer/2022062900/58ed09931a28ab69758b458f/html5/thumbnails/9.jpg)
What comes to mind?
S.O.L.I.D
![Page 10: Better java with design](https://reader036.fdocuments.in/reader036/viewer/2022062900/58ed09931a28ab69758b458f/html5/thumbnails/10.jpg)
S.O.L.I.D in 120 seconds
SRP - Responsibility/Ease of change of a class
OCP - Strategy/Template Method + Interface
LSP - Car Is-a Vehicle [ Square Is-a Rectangle? ]
ISP - Many specific Interfaces
DIP - High Level / Low level modules ⇒ abstractions ⇐ details
![Page 11: Better java with design](https://reader036.fdocuments.in/reader036/viewer/2022062900/58ed09931a28ab69758b458f/html5/thumbnails/11.jpg)
Creating classes - move away from Constructor?Creating classes
● Use creation methods [not necessarily factory method - overkill]
● Chain Constructors● Collecting Parameter
Consider ⇒ 3D Printed Building What comes to mind?
● 3D Printed Building● Area● Dimensions● Floors
Highlights ⇒ Intention-revealing names for
creation Methods ⇒ One constructor calling others in a chain that follows a logical Sequence (move to creation Method)
![Page 12: Better java with design](https://reader036.fdocuments.in/reader036/viewer/2022062900/58ed09931a28ab69758b458f/html5/thumbnails/12.jpg)
Replace Conditional logic with Strategy
● For one of several variants of an algorithm● Use a separate strategy for each variant and call accordingly
● 3DPrinter - how to print a building?
![Page 13: Better java with design](https://reader036.fdocuments.in/reader036/viewer/2022062900/58ed09931a28ab69758b458f/html5/thumbnails/13.jpg)
Code Study: Encapsulate classes with Factory
● “Program to interface, not to implementation”
● “Client does not need to know where the class resides”
● “Access through a common interface”
● Use intention-revealing creation Methods
Why?
See http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/util/Collections.java
Collections.synchronizedXYZ()
How?
![Page 14: Better java with design](https://reader036.fdocuments.in/reader036/viewer/2022062900/58ed09931a28ab69758b458f/html5/thumbnails/14.jpg)
Encapsulate Composite with Builder
● Let’s evaluate a Spec for the 3D Printed Building
● Like configuration files
● Creation of composites can be error-prone
● The XML Tag is joined by a composite● Loose Coupling between client and
composite
Why How
● Create a builder● Use builder to produce a one-node
Composite . Add a method to the builder to obtain the result of its build
● Make the builder capable of building children.
● Make the builder capable of setting those attributes and values.
● Refactor to make it simpler
![Page 15: Better java with design](https://reader036.fdocuments.in/reader036/viewer/2022062900/58ed09931a28ab69758b458f/html5/thumbnails/15.jpg)
![Page 16: Better java with design](https://reader036.fdocuments.in/reader036/viewer/2022062900/58ed09931a28ab69758b458f/html5/thumbnails/16.jpg)
Reference
![Page 17: Better java with design](https://reader036.fdocuments.in/reader036/viewer/2022062900/58ed09931a28ab69758b458f/html5/thumbnails/17.jpg)
धन्यवादः।