Software Design Patterns Anton Danshin Moscow Institute of Physics and Technology Dolgoprudny -...

13
Software Design Patterns Anton Danshin Moscow Institute of Physics and Technology Dolgoprudny - 2012

Transcript of Software Design Patterns Anton Danshin Moscow Institute of Physics and Technology Dolgoprudny -...

Software Design Patterns

Anton DanshinMoscow Institute of

Physics and Technology

Dolgoprudny - 2012

Contents

What is it? Why do we use it? Classification Example Criticism Anti-patterns Conclusion

2

What is it?

General repeatable solution to a commonly occurring problem in software design

Description or template for how to solve a problem that can be used in many different situations

3

Why do we use it?

Speed up development process Prevent future problems Ease comunication between developers Make your code better

Simplicity is the soul of efficiency.-- Austin Freeman, "The Eye of Osiris"

4

Classification of design patterns

Creational: Abstract factory, Builder, Factory method,

Prototype, Singleton, ...

Structural: Adapter, Bridge, Composite, Decorator, Proxy, ...

Behavioral: Chain of responsibility, Command, Iterator,

Mediator, Strategy, ...

Concurrent5

Example 1: Singleton

Intent: Create a single-instance class Provide a global point of access to it Encapsulate initialization

Problems Application needs one, and only one, instance of an

object. Lazy initialization and global access are necessary

6

Example 1: Singleton

7

Example 1: Singleton (Java)

8

Criticism

Targets the wrong problem Lacks formal foundations Leads to inefficient solutions

Do not overuse!

9

Copy and Paste Programming

Spaghetti Code Golden Hammer Magic Numbers Hard Code Boat Anchor God Object

Anti-Patterns

Soft Code Reinventing the Wheel Reinventing the Square

Wheel Blind Faith Brute Force Coding Unnecessary

comments

10

Conclusion

Design pattern is a general solution to a commonly occurring problem in software design

Using design patterns makes your code better Design patterns are devided into:

Creational Behavioral Structural Concurrent

Do NOT OVERUSE design patterns

11

References

1.SourceMaking.com – Software Design Patterns

http://sourcemaking.com/design_patterns

2.Wikipedia

http://en.wikipedia.org/wiki/Software_design_pattern

3.HabraHabr.Ru

http://habrahabr.ru/blogs/refactoring/59005/

12

Thanks for your attention!