Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Better java with design

3,724 views

Published on

A peek into better java with design

Published in: Software
  • Be the first to comment

Better java with design

  1. 1. Java - Better with Design Narayann Swaami Agile Technical Coach Societe Generale
  2. 2. 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
  3. 3. Summary There are many ways of approaching best practices Learn on your own Learn from Industry standard books Learn from conferences/meetups
  4. 4. How this came about Coaching teams - working with them Analyze what worked AND what did not work Inspect and Adapt!
  5. 5. What we will learn today Interesting best practices - From “Refactoring To Patterns”
  6. 6. How we do this → μ- Workshop → Two - three examples [ Time-Dependent ] → Refactoring workflow → Interactivity
  7. 7. Better OOP is better Java Why?
  8. 8. Better Design is Better Java Why?
  9. 9. What comes to mind? S.O.L.I.D
  10. 10. 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
  11. 11. 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)
  12. 12. 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?
  13. 13. 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.grepcod e.com/java/root/jdk/openjdk/8u40- b25/java/util/Collections.java Collections.synchronizedXYZ() How?
  14. 14. 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
  15. 15. Reference
  16. 16. धन्यवादः।

×