object oriented concepts in real projects

34
Kalinichenko Yevhen Basic principles of Object Oriented Programming Object Oriented Concepts

Upload: epam-systems

Post on 29-Jun-2015

243 views

Category:

Software


0 download

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.

TRANSCRIPT

Page 1: Object Oriented Concepts in Real Projects

Kalinichenko Yevhen

Basic principles of Object Oriented Programming

Object Oriented Concepts

Page 2: Object Oriented Concepts in Real Projects

Statistic

50 Interviews

20 Interviews

47 Interviews

70 Interviews

60 Interviews

247 Interviews

80% don’t know what OOP is

Page 3: Object Oriented Concepts in Real Projects

Common OOP in Javascript examplesPrototypal Inheritance

Page 4: Object Oriented Concepts in Real Projects

We work in teams

Page 5: Object Oriented Concepts in Real Projects

A set of principles

Polymorphism

Page 6: Object Oriented Concepts in Real Projects

Abstraction

Polymorphism

Single responsibility

Encapsulation

Open/Closed

Principles for today

JavaScript

Page 7: Object Oriented Concepts in Real Projects

Abstraction

Page 8: Object Oriented Concepts in Real Projects

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.

Page 9: Object Oriented Concepts in Real Projects

Real Case

Task

Visual Features TeamCore Features Team

Interface

Interface

Page 10: Object Oriented Concepts in Real Projects

Abstract Classes

Core Features Team

DataStore

Real Case

Page 11: Object Oriented Concepts in Real Projects

Inheritance

Page 12: Object Oriented Concepts in Real Projects

Inheritance

Page 13: Object Oriented Concepts in Real Projects

Life case

Widget

Page 14: Object Oriented Concepts in Real Projects

New requirements

Page 15: Object Oriented Concepts in Real Projects

New requirements

Page 16: Object Oriented Concepts in Real Projects

Responsibilities and Roles

Widget

Container View

Data

Data Visualization

Configuration

Architecture solution

Customer

BE Dev

FE Dev

FE Dev

Tech Lead

FE Dev

Page 17: Object Oriented Concepts in Real Projects

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.

Page 18: Object Oriented Concepts in Real Projects

Inverse dependencies

Data Visualization Component

Data

Widget

Container

Configuration

Page 19: Object Oriented Concepts in Real Projects

Polymorphism

Page 20: Object Oriented Concepts in Real Projects

Different behavior of

method based on

arguments

length/arguments type.

Method overloading

Page 21: Object Oriented Concepts in Real Projects

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)

Page 22: Object Oriented Concepts in Real Projects

Polymorphism

Core Features Team

DataStore

Page 23: Object Oriented Concepts in Real Projects

Compose components

Container

Configuration

Data Visualization

Page 24: Object Oriented Concepts in Real Projects

Encapsulation

Page 25: Object Oriented Concepts in Real Projects

Encapsulation

Encapsulation hides the implementation details.

Expose public interface.

Page 26: Object Oriented Concepts in Real Projects

Breaking of encapsulation

We can’t change inner implementation of our

class without breaking of the client’s code.

Maintenance hell.

Page 27: Object Oriented Concepts in Real Projects

Ops…

Let’s break it

Page 28: Object Oriented Concepts in Real Projects

Everything is ok now.

Always use clear defined interface

Page 29: Object Oriented Concepts in Real Projects

Open/Closed principle

Page 30: Object Oriented Concepts in Real Projects

Open/Closed principle

Widget

Closed for modification

New data visual

Open for extension

Page 31: Object Oriented Concepts in Real Projects

Open/Closed examples

JQuery plugins.

Strategy pattern.

Page 32: Object Oriented Concepts in Real Projects

Conclusion

“Continuous refactoring”.

Principles in mind.

Page 33: Object Oriented Concepts in Real Projects

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

Page 34: Object Oriented Concepts in Real Projects

Q&A