Application
Architecture
Topalov Alex 2016
BORING!!!
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2847740/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2847741/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2847742/pasted-from-clipboard.png)
Intro
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2847258/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2611226/pasted-from-clipboard.png)
duplication is far cheaper than the wrong abstraction
- Sandi Metz. RailsConf 2014
Happy Case
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2841289/pasted-from-clipboard.png)
After awhile
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2841316/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2841317/pasted-from-clipboard.png)
And sometimes...
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2841348/pasted-from-clipboard.png)
DRY?!
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
- Andy Hunt and Dave Thomas.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2834391/pasted-from-clipboard.png)
What to DRY
- Things that changes rarely
- When same concepts in different places
- When same concepts have different names
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2841367/pasted-from-clipboard.png)
Abstraction
Abstraction is the unsplittable block of a knowledge representation.
Collect Duplication
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2841382/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2841383/pasted-from-clipboard.png)
Collect Duplication
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2841386/pasted-from-clipboard.png)
Collect Duplication
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2841388/pasted-from-clipboard.png)
Something not right
Weird
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2843869/pasted-from-clipboard.png)
Weirder
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2843794/pasted-from-clipboard.png)
Weirdest
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2843843/pasted-from-clipboard.png)
Why and how that happens
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2843881/pasted-from-clipboard.png)
Why and how that happens
1. Unreasonable expectations because of tight budget or else
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2843894/pasted-from-clipboard.png)
Why and how that happens
1. Unreasonable expectations because of tight budget or else.
Solution: Try to at least squeeze some integration testing or(and!) re-write in a future completely.
Why and how that happens
1. Unreasonable expectations because of tight budget or else.
Solution: Try to at least squeeze some integration testing or(and!) re-write in a future completely.
2. Lack of application design understanding.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2844023/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2844028/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2844049/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2844052/pasted-from-clipboard.png)
Some common solutions
- Adapters
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2847054/pasted-from-clipboard.png)
Some common solutions
- Adapters
- Unify API for different classes.
- Reduce conditional branching.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2847063/pasted-from-clipboard.png)
Some common solutions
- Adapters
- Decorators
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2847083/pasted-from-clipboard.png)
Some common solutions
- Adapters
- Decorators
- Remove logic from views or other contexts
- Do not mixup business and representation logic.
Solutions:
- Draper
- Own/Custom
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2847078/pasted-from-clipboard.png)
Some common solutions
- Adapters
- Decorators
- Services
- Extracting complex business interactions/routine in separate class.
- Reduce code in controllers/models
Solutions:
1. Interactor
2. Light-service
3. Custom/Own
Some common solutions
- Adapters
- Decorators
- Services
- Validators
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2847100/pasted-from-clipboard.png)
Some common solutions
- Adapters
- Decorators
- Services
- Validators
- Remove conditional validations.
- Remove or unify logic for specific validations.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2847117/pasted-from-clipboard.png)
Some common solutions
- Adapters
- Decorators
- Services
- Validators
- Serializers
- Represent objects in a special format by a special rules
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2847162/pasted-from-clipboard.png)
Some common solutions
- Adapters
- Decorators
- Services
- Validators
- Serializers
- Strategies
Delegate tasks to Strategy objects which have same interface
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2847199/pasted-from-clipboard.png)
Some common solutions
- Adapters
- Decorators
- Services
- Validators
- Serializers
- Strategies
- Concerns/Policies
Rails concerns or non-rails.
Idea is to encapsulate logic around some functionality that used only in one context.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2847214/pasted-from-clipboard.png)
Some common solutions
- Adapters
- Decorators
- Services
- Validators
- Serializers
- Strategies
- Concerns/Policies
- Observers
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2847729/pasted-from-clipboard.png)
Some common solutions
- Adapters
- Decorators
- Services
- Validators
- Serializers
- Strategies
- Concerns/Policies
- Observers
- Duck typing(technique)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/2847734/pasted-from-clipboard.png)
Some common solutions
- Adapters
- Decorators
- Services
- Validators
- Serializers
- Strategies
- Concerns/Policies
- Observers
- Duck typing(technique)
- Repository object
- Data object
12. Factory
13. Abstract Factory
14. Proxy
15. Command
16. Iterator
17. Builder
18. Singleton
19. Interpreter
20. etc
Junior Sindrome
Symptomps:
- Sunk Cost fallacy
- Cowboy coding
Treatment:
- Code review
- Peace of internal mind
Big boss syndrome
Symptomps:
- Over Engineering
- Pattern Seeking
Treatment:
- Refactoring of old pieces of own code
- Real life examples
- Code review
How develop with ease
- Wait for a code to tell when to reveal abstraction
How develop with ease
- Wait for a code to tell when to reveal abstraction
- Be ready to break rules that you thought is unbreakable
How develop with ease
- Wait for a code to tell when to reveal abstraction
- Be ready to break rules that you thought is unbreakable
- Be open to new ideas
How develop with ease
- Wait for a code to tell when to reveal abstraction
- Be ready to break rules that you thought is unbreakable
- Be open to new ideas
- Read books and review legacy projects
How develop with ease
- Wait for a code to tell when to reveal abstraction
- Be ready to break rules that you thought is unbreakable
- Be open to new ideas
- Read books and review legacy projects
- Write integration/contract tests !? FTW
Conclusion
It's not a framework issue - it's your issue
Architecture
By Alex Topalov
Architecture
- 2,862