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 knowwhat OOP is
Common OOP in Javascriptexamples Prototypal 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 Team Core 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 VisualizationComponent 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. Strategypattern.
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

Object Oriented Concepts in Real Projects