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.
Design is an art
Art requires creativity
Creativity is a product of the brain
The brain can be understood scientifically
S...
Fragile base-class problem
class File {
private String contents = “”;
void write(String more) {
contents += more;
}
void w...
Solution
interface File {
void write(String more);
void writeMany(String[] mores);
}
interface InstrumentedFile extends Fi...
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; }...
Solution
class Rectangle {
private int len;
private int wid;
Rectangle(int l, int w) { len = l; wid = w; }
int getLength()...
But I want polymorphism to compute areas
interface Areable {
int getArea();
}
class Rectangle implements Areable {
…
@Over...
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 implemen...
Further reading + coding
https://github.com/gokul2411s/patternsrepo
Read the Gang of Four book
Read books by Martin Fowler...
Duh where’s the brand?
Google
Susquehanna International Group
UPenn GRASP robotics
Schlumberger
NIT Surathkal
Software Design Thinking
Software Design Thinking
Software Design Thinking
Software Design Thinking
Upcoming SlideShare
Loading in …5
×

Software Design Thinking

331 views

Published on

Solving specific problems which fit within the following categories.
managing layers of software
creating pipelines for data processing
dealing with user input
maintaining complex business rules
dealing with class hierarchies

Most widely used Design Patterns discussed
Builder
Command
Composite
Decorator
Event-Observer
Factory
Specification
Strategy
Visitor

Speaker: Gokul Subramanian

Published in: Technology
  • Be the first to comment

Software Design Thinking

  1. 1. 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
  2. 2. 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;
  3. 3. 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; } }
  4. 4. Identify the differences (be nice)
  5. 5. The Decorator pattern
  6. 6. Proxy, Adapter, Facade
  7. 7. 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);
  8. 8. 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); } }
  9. 9. 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.
  10. 10. Euclid’s GCD algorithm
  11. 11. The Composite pattern
  12. 12. Which car do you want?
  13. 13. The Strategy pattern
  14. 14. The Builder pattern
  15. 15. There shall be no other king!
  16. 16. Code: Deep dive
  17. 17. 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
  18. 18. 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
  19. 19. Duh where’s the brand? Google Susquehanna International Group UPenn GRASP robotics Schlumberger NIT Surathkal

×