View
243
Download
0
Category
Tags:
Preview:
DESCRIPTION
Yevhen Kalinichenko, Senior JavaScript Developer “Object oriented concepts in real projects” - Abstraction. What is it and what abstraction gives us - Inheritance. Why do we need inheritance? Composition over inheritance. - Encapsulation. Why it’s so important to hide implementation. Breaking of encapsulation leads us to maintenance hell - Polymorphism. Working with interface but not with concrete implementation - Single responsibility. Why “classes” must adhere single responsibility - Open/Closed principle - Related topics – cohesion, coupling, interfaces, separation of responsibilities for each team member.
Citation preview
Kalinichenko Yevhen
Basic principles of Object Oriented Programming
Object Oriented Concepts
Statistic
50 Interviews
20 Interviews
47 Interviews
70 Interviews
60 Interviews
247 Interviews
80% don’t know what OOP is
Common OOP in Javascript examplesPrototypal Inheritance
We work in teams
A set of principles
Polymorphism
Abstraction
Polymorphism
Single responsibility
Encapsulation
Open/Closed
Principles for today
JavaScript
Abstraction
Abstraction
The concept of describing something in simpler terms.
Abstracting away the details, in order to focus on what is
important.
Abstraction helps us to reduce complexity and increase
efficiency.
Real Case
Task
Visual Features TeamCore Features Team
Interface
Interface
Abstract Classes
Core Features Team
DataStore
Real Case
Inheritance
Inheritance
Life case
Widget
New requirements
New requirements
Responsibilities and Roles
Widget
Container View
Data
Data Visualization
Configuration
Architecture solution
Customer
BE Dev
FE Dev
FE Dev
Tech Lead
FE Dev
Single Responsibility Principle
A class should have only one reason to change.
Class should have a cohesive set of behaviors, together
comprising a single responsibility.
Inverse dependencies
Data Visualization Component
Data
Widget
Container
Configuration
Polymorphism
Different behavior of
method based on
arguments
length/arguments type.
Method overloading
Duck typing
We work with objects of different types identically if
these objects adhere the same contract.
“When I see a bird that walks like a duck
and swims like a duck and quacks like a duck,
I call that bird a duck.” (c)
Polymorphism
Core Features Team
DataStore
Compose components
Container
Configuration
Data Visualization
Encapsulation
Encapsulation
Encapsulation hides the implementation details.
Expose public interface.
Breaking of encapsulation
We can’t change inner implementation of our
class without breaking of the client’s code.
Maintenance hell.
Ops…
Let’s break it
Everything is ok now.
Always use clear defined interface
Open/Closed principle
Open/Closed principle
Widget
Closed for modification
New data visual
Open for extension
Open/Closed examples
JQuery plugins.
Strategy pattern.
Conclusion
“Continuous refactoring”.
Principles in mind.
Related materials
SOLID JavaScript - http://freshbrewedcode.com/derekgreer/2011/12/08/solid-
javascript-single-responsibility-principle/
Pro JavaScript design Patterns - http://www.amazon.com/Pro-JavaScript-Design-
Patterns-Object-Oriented/dp/159059908X
Head First Object-Oriented Analysis and Design -
http://shop.oreilly.com/product/9780596008673.do
Head First Design Patterns - http://shop.oreilly.com/product/9780596007126.do
Code Complete - http://www.amazon.com/Code-Complete-Practical-
Handbook-Construction/dp/0735619670
Q&A
Recommended