SlideShare a Scribd company logo
Object-Oriented
Programming
PROGRAMMING?
• Just writing some text in a specific format
2
PROGRAMMING LANGUAGES
3
SO, WHAT IS TRICK HERE?
• A compiler/interpreter does the actual job!
• Read text file, interpret the contents, output another file more
understandable by machines, less understandable by us 
4
MODERN IDES
• Previous slide is not a modern day practice.
– At least only computer engineers likes to do it.
• Now we have IDEs (Integrated Development Environment)
– Providing
 Text editors
 Compilers
 And many other useful features
5
IDE SAMPLES
6
IDE SAMPLES
7
WHAT IS A PROGRAM?
• Just some sequential lines to instruct the computer what to do!
8
WHAT IS A PROGRAMMING LANGUAGE?
• Provides the developer useful constructs
– Defining variables
– Looping
– Conditionals
– Many more…
• And advanced constructs
– Data management
– Memory management
– Networking
– Scheduling
9
WHICH LANGUAGE
• According to Google*:
– The fastest language is C++
– BUT
 If you don’t optimize your code, you may end up slower than other languages
– See C++ Dbg vs other languages
10*Loop Recognition in C++/Java/Go/Scala by Robert Hundt - Google
OF COURSE…
• The programs are not small any more!
– Chrome browser: 17 millions LOC (lines of code)
– Office 2013: 45 millions LOC
– Facebook: 60 millions LOC
• You can’t just put all the lines sequentially and expect someone to
understand!
– First, it is impossible.
– Second, it is torture.
• Of course we need extra structures to handle the complexity
11
WHEN THINGS GET BIGGER - MODULARIZE
12
We can define methods in order to make our
program mode readable.
MODULARIZE EVEN MORE
13
We can make this
method parametric.
And use parametrized
version whenever needed.
FUN PART
14
Spoiler alert:
You will see some
code in action!
ENOUGH OF THE LINES, GIVE ME SOMETHING
15
I want to do this 3 times?
MODULARIZING - PARAMETRIZED
16
MODULARIZING – MORE PARAMETRIZED
17
We still have a lot of repetitions.
EPIPHANY
• Wouldn’t it be nice if there is a special structure that:
– Knows what kind of an animal it is.
– Knows how many legs it has.
– Can make sound by itself.
– Has a name.
• So that, I don’t have to write them every time.
18
EPIPHANY
19
So, we are basically
talking about a dog?
It has a name, knows how
many legs it has, can
make sound itself.
EPIPHANY
• So we need to mimic the real life in our applications.
• Because a program is for the developer to write/understand
easily, not for the computer.
20*Author of the renowned Structure and Interpretation of Computer Programs book (with Jay Sussman)
“First, we want to establish the idea that a computer
language is not just a way of getting a computer to perform
operations but rather it is a novel formal medium for
expressing ideas about methodology.
Thus, programs must be written for people to read, and only
incidentally for machines to execute.”
Harold Abelson*
EPIPHANY
• Wouldn’t it be nice if there is a special structure that:
– Knows what kind of an animal it is.
– Knows how many legs it has.
– Can make sound by itself.
– Has a name.
• We already have a system for this.
– Object-oriented programming.
 A.k.a.
– Object-oriented methodology
– Object-oriented paradigm
– Object-oriented design and analysis
21
OBJECT-ORIENTED PROGRAMMING
• Basically, we have objects that know:
– Its attributes
– Its operations
• Whenever, I need a square or triangle, I will use them.
– I ask for information and they answer.
22
Side
Area = side*side
Side
Height
Base
Area =
(height*base)/2
height
base
OBJECT IDENTIFICATION
• Car, glass, bike, bus
– All can be objects
• Dog, cat, person, laptop
– Again, can be objects
• Running, walking, making a sound etc… ?
– No, these are not objects!
– These are actions (methods/operations) that can be done by an object
 Like a Rectangle can compute its own area
 A people can run.
• Side, height, numberOfLegs etc… ?
– No, these are not objects!
– These are properties (attributes) that can be owned by an object
 Like side of a Rectangle.
 Numberoflegs of a Person.
23
EVERYTHING CAN BE AN OBJECT
• It just depends on the context!
• Distance between two cities can be an object
– If it is the main focus of the problem.
• Relationship between two people can be an object
– If we are solving a problem about this.
24
LET’S IDENTIFY SOME OBJECTS
• Company XYZ is a manufacturing company that produces cartoon
action figurines for big entertainment companies.
• This company is using an inventory and tracking system.
• The inventory system keeps track of how many of each figurine is
stored in each warehouse.
• Figures are stored in cases.
• Clients order the figurines and the cases are eventually shipped to
clients.
25
OBJECTS IDENTIFIED
• Company XYZ is a manufacturing company that produces cartoon
action figurines for big entertainment companies.
• This company is using an inventory and tracking system.
• The inventory system keeps track of how many of each figurine is
stored in each warehouse.
• Figures are stored in cases.
• Clients order the figurines and the cases are eventually shipped to
clients.
26
ANY MORE?
• Company XYZ is a manufacturing company that produces cartoon
action figurines for big entertainment companies.
• This company is using an inventory and tracking system.
• The inventory system keeps track of how many of each figurine is
stored in each warehouse.
• Figures are stored in cases.
• Clients order the figurines and the cases are eventually shipped to
clients.
27
ANOTHER EXAMPLE
• An ATM needs to allow a customer to identify themselves
– Each customer has a debit card and PIN
• Customers should be presented with some kind of menu to help
direct them.
• Customers can perform two transactions:
– They should be able to deposit funds
– They should be able to withdraw funds upto $200
 These funds must be withdrawn in units of $20
• The ATM should tell some banking software to update the
customers’ account at the end of transaction
• The ATM should also give the customer some record of the
transaction.
28
OBJECTS IDENTIFIED
• An ATM needs to allow a customer to identify themselves
– Each customer has a debit card and PIN
• Customers should be presented with some kind of menu to help
direct them.
• Customers can perform two transactions:
– They should be able to deposit funds
– They should be able to withdraw funds upto $200
 These funds must be withdrawn in units of $20
• The ATM should tell some banking software to update the
customers’ account at the end of transaction
• The ATM should also give the customer some record of the
transaction.
29
This PIN number object
seems redundant.
We can make it a property
of either customer or debit
card.
This small design decision
will make a lot of
difference.
OBJECT-ORIENTED LANGUAGES
• Most modern languages support object-orientation now
– Java
– C++ (C with classes)
– C#
– Python
– Even Fortran
– Any many more
30
A REPRESENTATION SYSTEM
• Various languages support object-orientation.
• So, there should be a way to represent this system regardless of
the language we use.
• UML is here.
31
UML BASICS - CLASS
32
Side
Area = side*side
Side
Height
Base
Area =
(height*base)/2
height
base
CLASS IN C#
33
WAIT
• We were talking about objects, now what the heck is a class?
• Time to define the relation between these two.
• Basically, we get the properties that all the dogs have and define a Dog class
with them.
– A class is a generalization of objects.
– And objects are just instances of the class.
34
OBJECTS FROM CLASSES
• Constructor
• Now we can create objects
– From classes
– Using a constructor
35
CONCEPTS & DESIGN PRINCIPLES
IN OBJECT-ORIENTED PROGRAMMING
• Concepts:
– Encapsulation
– Inheritance
– Polymorphism
– Cohesion
– Coupling
• Principles
– Open-Closed Principle
– Don’t Repeat Yourself Principle
– Single Responsibility Principle
– Liskov Substitution Principle
– Interface Seggregation Principle
– Dependency Inversion Principle
36
If we don’t use these
concepts and obey
these principles, we
aren’t coding in proper
object-oriented way.
ENCAPSULATION
• Protecting your information from being used incorrectly.
37
PROBLEM?
What if speed if out of limits?
What if we want some
adjustments before setting the
speed?
ENCAPSULATION
38
SOLUTION?
INHERITANCE
• A class’ inheriting properties and operations from another class.
• Both Dogs and Cats have names, right?
– Then, why shouldn’t we create a base class Animal for them?
39
POLYMORPHISM
• Having different forms of same operations.
40
POLYMORPHISM
41
COHESION
• A class should do one thing really well, and shouldn’t try to do or
be someone else.
• Strong cohesion means: all methods of a class are more or less
related.
– A Math class which can compute sqrt, power, exp, cos etc.
• If a class has methods for:
– Printing a document
– Sending an email
– Working with trigonometric functions
– How should we name it? Complicated, right?
42
COUPLING
• The extent to which classes depend on one another.
– A class should work independently without being coupled too much to
other classes.
– This helps us making them modules and available on demand.
43
OPEN-CLOSED PRINCIPLE
• Classes should be open to extension, but closed for modification.
44
PROBLEM?
Whenever we add a
new shape, we
should modify the
calculateTotalArea
method.
OPEN-CLOSED PRINCIPLE
45
SOLUTION?
OPEN-CLOSED PRINCIPLE
46
DON’T REPEAT YOURSELF PRINCIPLE
• Avoid duplicate code by abstracting common things out and
placing them in a single location.
47
SINGLE RESPONSIBILITY PRINCIPLE
• Every object in the system should have one responsibility
– Each object has only one reason to change
– Doesn’t mean it should only have one method
• Usually the violation of this principle can be identified by asking:
– Can _______ _________ itself?
 Example: Can Automobile changeTires itself?
 If it is no, it is violating SRP.
48
SINGLE RESPONSIBILITY PRINCIPLE
49
LISKOV SUBSTITUTION PRINCIPLE
• Sub-classes must be substitutable for their base classes.
– If you inherit from a wrong base class, then you can’t do this.
50
PROBLEM?
We inherit from the
board, but we hardly
use its methods or
properties. Because
they don’t match
with 3D board.
LISKOV SUBSTITUTION PRINCIPLE
• Sub-classes must be substitutable for their base classes.
– If you inherit from a wrong base class, then you can’t do this.
51
SOLUTION?
INTERFACE SEGGREGATION PRINCIPLE
• A class should never be forced to have some unnecessary
methods.
52
PROBLEM?
We force Square to have
a computeVolume
method, which it
doesn’t have!
INTERFACE SEGGREGATION PRINCIPLE
53
SOLUTION?
DEPENDENCY INVERSION PRINCIPLE
• Entities must depend on abstractions/interfaces rather than
actual classes.
– So that they can be decoupled.
54
PROBLEM?We have to treat each shape
separately. Because we have links to
actual classes.
DEPENDENCY INVERSION PRINCIPLE
55
SOLUTION?
WHAT CAN WE ACHIEVE FROM THIS?
SOME IDEAS
• Read data from various sources but our program can stay the
same
• Easily switch between different algorithms on the same data
• Make any module work independent from others
• Make the output of the project independent from the data or the
algorithm itself
• Test the correctness of each class independently
• Model the problem in a human-readable way
• And most importantly, reuse and maintain your application better.
– Future-proof.
56
OTHER TOOLS & TECHNOLOGIES IN ORDER TO
IMPROVE YOUR PROGRAMMING
• Versioning (github, bitbucket etc.)
– Version your code in order to access any change you made (and backup)
• Unit tests
– Test each unit independently, be sure it is doing whatever it is supposed to
do.
– Most languages have support for this. Look for it.
• Documentation (Doxygen, Javadoc etc.)
– Always comment your code. You can even produce automatic
documentation from these comments.
• Diagramming
– Your code may not be understandable, but your diagrams will be. Learn
UML Class diagram and use it in your projects.
57
CONCLUSION
• Object-oriented programming provides very flexible structures for
our programs.
– It can be applied in many languages, as long as the language supports
object-orientation.
• If we obey the principles, it will be an actual system.
– Otherwise, it is just the same code with classes and additional complexity.
• Object-oriented system is not a perfect system and it has its own
flaws. But it is still the best system.
• Always strive for the best design.
58
QUESTIONS?
• Thanks for listening…
• For offline questions, find my contact info here:
www.objectivelook.net
59
SOME RESOURCES
• Object-oriented programming with C# (The book itself is nice and free,
chapter 20 is OOP): http://www.introprogramming.info/english-intro-
csharp-book/read-online/
• For new starters to OOP, this book is fun:
https://www.amazon.com/Head-First-Object-Oriented-Analysis-
Design/dp/0596008678
• Detailed explanation, nicely done, 2 pages (Java):
– https://www.ntu.edu.sg/home/ehchua/programming/java/J3a_OOPBasics.ht
ml
– https://www.ntu.edu.sg/home/ehchua/programming/java/J3b_OOPInheritan
cePolymorphism.html
• Same as above but with C++:
– https://www.ntu.edu.sg/home/ehchua/programming/cpp/cp3_OOP.html
• Even though, there are a lot of resources. I suggest to work with
someone who you can ask questions immediately. Because OOP
requires a change of mindset.
60
Ad

Recommended

oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
Intro C# Book
 
From the book: 50 Proven Ways to Be Persuasive
From the book: 50 Proven Ways to Be Persuasive
Hüseyin Ergin
 
Software Versioning with Bitbucket and Eclipse
Software Versioning with Bitbucket and Eclipse
Hüseyin Ergin
 
Object Oriented Programming
Object Oriented Programming
baabtra.com - No. 1 supplier of quality freshers
 
the Concept of Object-Oriented Programming
the Concept of Object-Oriented Programming
Aida Ramlan II
 
Algorithm and flowchart
Algorithm and flowchart
IamPe Khamkhum
 
Chapter8.coding
Chapter8.coding
Daniel Downs
 
Programming skills
Programming skills
COMMON Europe
 
Best Techniques To Design Programs - Program Designing Techniques
Best Techniques To Design Programs - Program Designing Techniques
Tech
 
Microcontroller lec 3
Microcontroller lec 3
Ibrahim Reda
 
Coding Your Results
Coding Your Results
Celia Emmelhainz
 
C++ oop
C++ oop
Sunil OS
 
10 fun projects to improve your coding skills
10 fun projects to improve your coding skills
jan_mindmatters
 
Algorithm and flowchart
Algorithm and flowchart
Sachin Goyani
 
Introduction to object oriented programming
Introduction to object oriented programming
Abzetdin Adamov
 
Java Object Oriented Programming
Java Object Oriented Programming
University of Potsdam
 
Chain of Responsibility Pattern
Chain of Responsibility Pattern
Hüseyin Ergin
 
Programming skills for test automation
Programming skills for test automation
Romania Testing
 
Algorithm and flowchart
Algorithm and flowchart
Rabin BK
 
Compilation and Execution
Compilation and Execution
Chong-Kuan Chen
 
C Prog. - Introduction to Hardware, Software, Algorithm & Flowchart
C Prog. - Introduction to Hardware, Software, Algorithm & Flowchart
vinay arora
 
Object-Oriented Programming Using C++
Object-Oriented Programming Using C++
Salahaddin University-Erbil
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
C Programming : Arrays
C Programming : Arrays
Gagan Deep
 
Flowchart and algorithm
Flowchart and algorithm
Sayali Shivarkar
 
Globalisation and its links to the five dimensions of poverty
Globalisation and its links to the five dimensions of poverty
Noel J Harrison
 
Object Oriented Paradigm
Object Oriented Paradigm
Hüseyin Ergin
 
Computational Thinking - 101
Computational Thinking - 101
WhizThinkers
 

More Related Content

Viewers also liked (20)

Chapter8.coding
Chapter8.coding
Daniel Downs
 
Programming skills
Programming skills
COMMON Europe
 
Best Techniques To Design Programs - Program Designing Techniques
Best Techniques To Design Programs - Program Designing Techniques
Tech
 
Microcontroller lec 3
Microcontroller lec 3
Ibrahim Reda
 
Coding Your Results
Coding Your Results
Celia Emmelhainz
 
C++ oop
C++ oop
Sunil OS
 
10 fun projects to improve your coding skills
10 fun projects to improve your coding skills
jan_mindmatters
 
Algorithm and flowchart
Algorithm and flowchart
Sachin Goyani
 
Introduction to object oriented programming
Introduction to object oriented programming
Abzetdin Adamov
 
Java Object Oriented Programming
Java Object Oriented Programming
University of Potsdam
 
Chain of Responsibility Pattern
Chain of Responsibility Pattern
Hüseyin Ergin
 
Programming skills for test automation
Programming skills for test automation
Romania Testing
 
Algorithm and flowchart
Algorithm and flowchart
Rabin BK
 
Compilation and Execution
Compilation and Execution
Chong-Kuan Chen
 
C Prog. - Introduction to Hardware, Software, Algorithm & Flowchart
C Prog. - Introduction to Hardware, Software, Algorithm & Flowchart
vinay arora
 
Object-Oriented Programming Using C++
Object-Oriented Programming Using C++
Salahaddin University-Erbil
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
C Programming : Arrays
C Programming : Arrays
Gagan Deep
 
Flowchart and algorithm
Flowchart and algorithm
Sayali Shivarkar
 
Globalisation and its links to the five dimensions of poverty
Globalisation and its links to the five dimensions of poverty
Noel J Harrison
 
Best Techniques To Design Programs - Program Designing Techniques
Best Techniques To Design Programs - Program Designing Techniques
Tech
 
Microcontroller lec 3
Microcontroller lec 3
Ibrahim Reda
 
10 fun projects to improve your coding skills
10 fun projects to improve your coding skills
jan_mindmatters
 
Algorithm and flowchart
Algorithm and flowchart
Sachin Goyani
 
Introduction to object oriented programming
Introduction to object oriented programming
Abzetdin Adamov
 
Chain of Responsibility Pattern
Chain of Responsibility Pattern
Hüseyin Ergin
 
Programming skills for test automation
Programming skills for test automation
Romania Testing
 
Algorithm and flowchart
Algorithm and flowchart
Rabin BK
 
Compilation and Execution
Compilation and Execution
Chong-Kuan Chen
 
C Prog. - Introduction to Hardware, Software, Algorithm & Flowchart
C Prog. - Introduction to Hardware, Software, Algorithm & Flowchart
vinay arora
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
C Programming : Arrays
C Programming : Arrays
Gagan Deep
 
Globalisation and its links to the five dimensions of poverty
Globalisation and its links to the five dimensions of poverty
Noel J Harrison
 

Similar to Object oriented programming (20)

Object Oriented Paradigm
Object Oriented Paradigm
Hüseyin Ergin
 
Computational Thinking - 101
Computational Thinking - 101
WhizThinkers
 
Low Cost Assistive Technology Solutions
Low Cost Assistive Technology Solutions
will wade
 
computer programming introduction ppt.ppt
computer programming introduction ppt.ppt
AlazarAlemayehu2
 
Learning How To Code
Learning How To Code
CoachPineda
 
Domain-Driven Design: The "What" and the "Why"
Domain-Driven Design: The "What" and the "Why"
bincangteknologi
 
Chp-1 DAA (2).pptx design analysis and algoritham presentation
Chp-1 DAA (2).pptx design analysis and algoritham presentation
vaishnavbhavna17
 
Why Code Is Cool (And Why You Should Learn It)
Why Code Is Cool (And Why You Should Learn It)
Andrew Marks
 
Artificial intelligence
Artificial intelligence
Gangeshwar Krishnamurthy
 
Unit no_1.pptx
Unit no_1.pptx
Ganeshpatil499846
 
CS101- Introduction to Computing- Lecture 34
CS101- Introduction to Computing- Lecture 34
Bilal Ahmed
 
Week4 grasp-into
Week4 grasp-into
Alexandru-Gala Popescu
 
CPP02 - The Structure of a Program
CPP02 - The Structure of a Program
Michael Heron
 
Agile Engineering for Managers Workshop
Agile Engineering for Managers Workshop
Paul Boos
 
Algorithms 1
Algorithms 1
Muhammad Uzair Rasheed
 
Deep learning introduction
Deep learning introduction
Adwait Bhave
 
Problem solving
Problem solving
hamza239523
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
Mike Harris
 
CS101- Introduction to Computing- Lecture 45
CS101- Introduction to Computing- Lecture 45
Bilal Ahmed
 
The Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with android
Stanojko Markovik
 
Object Oriented Paradigm
Object Oriented Paradigm
Hüseyin Ergin
 
Computational Thinking - 101
Computational Thinking - 101
WhizThinkers
 
Low Cost Assistive Technology Solutions
Low Cost Assistive Technology Solutions
will wade
 
computer programming introduction ppt.ppt
computer programming introduction ppt.ppt
AlazarAlemayehu2
 
Learning How To Code
Learning How To Code
CoachPineda
 
Domain-Driven Design: The "What" and the "Why"
Domain-Driven Design: The "What" and the "Why"
bincangteknologi
 
Chp-1 DAA (2).pptx design analysis and algoritham presentation
Chp-1 DAA (2).pptx design analysis and algoritham presentation
vaishnavbhavna17
 
Why Code Is Cool (And Why You Should Learn It)
Why Code Is Cool (And Why You Should Learn It)
Andrew Marks
 
CS101- Introduction to Computing- Lecture 34
CS101- Introduction to Computing- Lecture 34
Bilal Ahmed
 
CPP02 - The Structure of a Program
CPP02 - The Structure of a Program
Michael Heron
 
Agile Engineering for Managers Workshop
Agile Engineering for Managers Workshop
Paul Boos
 
Deep learning introduction
Deep learning introduction
Adwait Bhave
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
Mike Harris
 
CS101- Introduction to Computing- Lecture 45
CS101- Introduction to Computing- Lecture 45
Bilal Ahmed
 
The Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with android
Stanojko Markovik
 
Ad

Recently uploaded (20)

Proposal for folders structure division in projects.pdf
Proposal for folders structure division in projects.pdf
Mohamed Ahmed
 
Cadastral Maps
Cadastral Maps
Google
 
Industry 4.o the fourth revolutionWeek-2.pptx
Industry 4.o the fourth revolutionWeek-2.pptx
KNaveenKumarECE
 
Abraham Silberschatz-Operating System Concepts (9th,2012.12).pdf
Abraham Silberschatz-Operating System Concepts (9th,2012.12).pdf
Shabista Imam
 
NEW Strengthened Senior High School Gen Math.pptx
NEW Strengthened Senior High School Gen Math.pptx
DaryllWhere
 
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
 
IPL_Logic_Flow.pdf Mainframe IPLMainframe IPL
IPL_Logic_Flow.pdf Mainframe IPLMainframe IPL
KhadijaKhadijaAouadi
 
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
resming1
 
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Shabista Imam
 
Introduction to sensing and Week-1.pptx
Introduction to sensing and Week-1.pptx
KNaveenKumarECE
 
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
System design handwritten notes guidance
System design handwritten notes guidance
Shabista Imam
 
DESIGN OF REINFORCED CONCRETE ELEMENTS S
DESIGN OF REINFORCED CONCRETE ELEMENTS S
prabhusp8
 
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
 
Introduction to Python Programming Language
Introduction to Python Programming Language
merlinjohnsy
 
60 Years and Beyond eBook 1234567891.pdf
60 Years and Beyond eBook 1234567891.pdf
waseemalazzeh
 
Mechanical Vibration_MIC 202_iit roorkee.pdf
Mechanical Vibration_MIC 202_iit roorkee.pdf
isahiliitr
 
Complete University of Calculus :: 2nd edition
Complete University of Calculus :: 2nd edition
Shabista Imam
 
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Mark Billinghurst
 
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
Proposal for folders structure division in projects.pdf
Proposal for folders structure division in projects.pdf
Mohamed Ahmed
 
Cadastral Maps
Cadastral Maps
Google
 
Industry 4.o the fourth revolutionWeek-2.pptx
Industry 4.o the fourth revolutionWeek-2.pptx
KNaveenKumarECE
 
Abraham Silberschatz-Operating System Concepts (9th,2012.12).pdf
Abraham Silberschatz-Operating System Concepts (9th,2012.12).pdf
Shabista Imam
 
NEW Strengthened Senior High School Gen Math.pptx
NEW Strengthened Senior High School Gen Math.pptx
DaryllWhere
 
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
 
IPL_Logic_Flow.pdf Mainframe IPLMainframe IPL
IPL_Logic_Flow.pdf Mainframe IPLMainframe IPL
KhadijaKhadijaAouadi
 
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
resming1
 
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Shabista Imam
 
Introduction to sensing and Week-1.pptx
Introduction to sensing and Week-1.pptx
KNaveenKumarECE
 
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
System design handwritten notes guidance
System design handwritten notes guidance
Shabista Imam
 
DESIGN OF REINFORCED CONCRETE ELEMENTS S
DESIGN OF REINFORCED CONCRETE ELEMENTS S
prabhusp8
 
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
 
Introduction to Python Programming Language
Introduction to Python Programming Language
merlinjohnsy
 
60 Years and Beyond eBook 1234567891.pdf
60 Years and Beyond eBook 1234567891.pdf
waseemalazzeh
 
Mechanical Vibration_MIC 202_iit roorkee.pdf
Mechanical Vibration_MIC 202_iit roorkee.pdf
isahiliitr
 
Complete University of Calculus :: 2nd edition
Complete University of Calculus :: 2nd edition
Shabista Imam
 
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Mark Billinghurst
 
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
Ad

Object oriented programming

  • 2. PROGRAMMING? • Just writing some text in a specific format 2
  • 4. SO, WHAT IS TRICK HERE? • A compiler/interpreter does the actual job! • Read text file, interpret the contents, output another file more understandable by machines, less understandable by us  4
  • 5. MODERN IDES • Previous slide is not a modern day practice. – At least only computer engineers likes to do it. • Now we have IDEs (Integrated Development Environment) – Providing  Text editors  Compilers  And many other useful features 5
  • 8. WHAT IS A PROGRAM? • Just some sequential lines to instruct the computer what to do! 8
  • 9. WHAT IS A PROGRAMMING LANGUAGE? • Provides the developer useful constructs – Defining variables – Looping – Conditionals – Many more… • And advanced constructs – Data management – Memory management – Networking – Scheduling 9
  • 10. WHICH LANGUAGE • According to Google*: – The fastest language is C++ – BUT  If you don’t optimize your code, you may end up slower than other languages – See C++ Dbg vs other languages 10*Loop Recognition in C++/Java/Go/Scala by Robert Hundt - Google
  • 11. OF COURSE… • The programs are not small any more! – Chrome browser: 17 millions LOC (lines of code) – Office 2013: 45 millions LOC – Facebook: 60 millions LOC • You can’t just put all the lines sequentially and expect someone to understand! – First, it is impossible. – Second, it is torture. • Of course we need extra structures to handle the complexity 11
  • 12. WHEN THINGS GET BIGGER - MODULARIZE 12 We can define methods in order to make our program mode readable.
  • 13. MODULARIZE EVEN MORE 13 We can make this method parametric. And use parametrized version whenever needed.
  • 14. FUN PART 14 Spoiler alert: You will see some code in action!
  • 15. ENOUGH OF THE LINES, GIVE ME SOMETHING 15 I want to do this 3 times?
  • 17. MODULARIZING – MORE PARAMETRIZED 17 We still have a lot of repetitions.
  • 18. EPIPHANY • Wouldn’t it be nice if there is a special structure that: – Knows what kind of an animal it is. – Knows how many legs it has. – Can make sound by itself. – Has a name. • So that, I don’t have to write them every time. 18
  • 19. EPIPHANY 19 So, we are basically talking about a dog? It has a name, knows how many legs it has, can make sound itself.
  • 20. EPIPHANY • So we need to mimic the real life in our applications. • Because a program is for the developer to write/understand easily, not for the computer. 20*Author of the renowned Structure and Interpretation of Computer Programs book (with Jay Sussman) “First, we want to establish the idea that a computer language is not just a way of getting a computer to perform operations but rather it is a novel formal medium for expressing ideas about methodology. Thus, programs must be written for people to read, and only incidentally for machines to execute.” Harold Abelson*
  • 21. EPIPHANY • Wouldn’t it be nice if there is a special structure that: – Knows what kind of an animal it is. – Knows how many legs it has. – Can make sound by itself. – Has a name. • We already have a system for this. – Object-oriented programming.  A.k.a. – Object-oriented methodology – Object-oriented paradigm – Object-oriented design and analysis 21
  • 22. OBJECT-ORIENTED PROGRAMMING • Basically, we have objects that know: – Its attributes – Its operations • Whenever, I need a square or triangle, I will use them. – I ask for information and they answer. 22 Side Area = side*side Side Height Base Area = (height*base)/2 height base
  • 23. OBJECT IDENTIFICATION • Car, glass, bike, bus – All can be objects • Dog, cat, person, laptop – Again, can be objects • Running, walking, making a sound etc… ? – No, these are not objects! – These are actions (methods/operations) that can be done by an object  Like a Rectangle can compute its own area  A people can run. • Side, height, numberOfLegs etc… ? – No, these are not objects! – These are properties (attributes) that can be owned by an object  Like side of a Rectangle.  Numberoflegs of a Person. 23
  • 24. EVERYTHING CAN BE AN OBJECT • It just depends on the context! • Distance between two cities can be an object – If it is the main focus of the problem. • Relationship between two people can be an object – If we are solving a problem about this. 24
  • 25. LET’S IDENTIFY SOME OBJECTS • Company XYZ is a manufacturing company that produces cartoon action figurines for big entertainment companies. • This company is using an inventory and tracking system. • The inventory system keeps track of how many of each figurine is stored in each warehouse. • Figures are stored in cases. • Clients order the figurines and the cases are eventually shipped to clients. 25
  • 26. OBJECTS IDENTIFIED • Company XYZ is a manufacturing company that produces cartoon action figurines for big entertainment companies. • This company is using an inventory and tracking system. • The inventory system keeps track of how many of each figurine is stored in each warehouse. • Figures are stored in cases. • Clients order the figurines and the cases are eventually shipped to clients. 26
  • 27. ANY MORE? • Company XYZ is a manufacturing company that produces cartoon action figurines for big entertainment companies. • This company is using an inventory and tracking system. • The inventory system keeps track of how many of each figurine is stored in each warehouse. • Figures are stored in cases. • Clients order the figurines and the cases are eventually shipped to clients. 27
  • 28. ANOTHER EXAMPLE • An ATM needs to allow a customer to identify themselves – Each customer has a debit card and PIN • Customers should be presented with some kind of menu to help direct them. • Customers can perform two transactions: – They should be able to deposit funds – They should be able to withdraw funds upto $200  These funds must be withdrawn in units of $20 • The ATM should tell some banking software to update the customers’ account at the end of transaction • The ATM should also give the customer some record of the transaction. 28
  • 29. OBJECTS IDENTIFIED • An ATM needs to allow a customer to identify themselves – Each customer has a debit card and PIN • Customers should be presented with some kind of menu to help direct them. • Customers can perform two transactions: – They should be able to deposit funds – They should be able to withdraw funds upto $200  These funds must be withdrawn in units of $20 • The ATM should tell some banking software to update the customers’ account at the end of transaction • The ATM should also give the customer some record of the transaction. 29 This PIN number object seems redundant. We can make it a property of either customer or debit card. This small design decision will make a lot of difference.
  • 30. OBJECT-ORIENTED LANGUAGES • Most modern languages support object-orientation now – Java – C++ (C with classes) – C# – Python – Even Fortran – Any many more 30
  • 31. A REPRESENTATION SYSTEM • Various languages support object-orientation. • So, there should be a way to represent this system regardless of the language we use. • UML is here. 31
  • 32. UML BASICS - CLASS 32 Side Area = side*side Side Height Base Area = (height*base)/2 height base
  • 34. WAIT • We were talking about objects, now what the heck is a class? • Time to define the relation between these two. • Basically, we get the properties that all the dogs have and define a Dog class with them. – A class is a generalization of objects. – And objects are just instances of the class. 34
  • 35. OBJECTS FROM CLASSES • Constructor • Now we can create objects – From classes – Using a constructor 35
  • 36. CONCEPTS & DESIGN PRINCIPLES IN OBJECT-ORIENTED PROGRAMMING • Concepts: – Encapsulation – Inheritance – Polymorphism – Cohesion – Coupling • Principles – Open-Closed Principle – Don’t Repeat Yourself Principle – Single Responsibility Principle – Liskov Substitution Principle – Interface Seggregation Principle – Dependency Inversion Principle 36 If we don’t use these concepts and obey these principles, we aren’t coding in proper object-oriented way.
  • 37. ENCAPSULATION • Protecting your information from being used incorrectly. 37 PROBLEM? What if speed if out of limits? What if we want some adjustments before setting the speed?
  • 39. INHERITANCE • A class’ inheriting properties and operations from another class. • Both Dogs and Cats have names, right? – Then, why shouldn’t we create a base class Animal for them? 39
  • 40. POLYMORPHISM • Having different forms of same operations. 40
  • 42. COHESION • A class should do one thing really well, and shouldn’t try to do or be someone else. • Strong cohesion means: all methods of a class are more or less related. – A Math class which can compute sqrt, power, exp, cos etc. • If a class has methods for: – Printing a document – Sending an email – Working with trigonometric functions – How should we name it? Complicated, right? 42
  • 43. COUPLING • The extent to which classes depend on one another. – A class should work independently without being coupled too much to other classes. – This helps us making them modules and available on demand. 43
  • 44. OPEN-CLOSED PRINCIPLE • Classes should be open to extension, but closed for modification. 44 PROBLEM? Whenever we add a new shape, we should modify the calculateTotalArea method.
  • 47. DON’T REPEAT YOURSELF PRINCIPLE • Avoid duplicate code by abstracting common things out and placing them in a single location. 47
  • 48. SINGLE RESPONSIBILITY PRINCIPLE • Every object in the system should have one responsibility – Each object has only one reason to change – Doesn’t mean it should only have one method • Usually the violation of this principle can be identified by asking: – Can _______ _________ itself?  Example: Can Automobile changeTires itself?  If it is no, it is violating SRP. 48
  • 50. LISKOV SUBSTITUTION PRINCIPLE • Sub-classes must be substitutable for their base classes. – If you inherit from a wrong base class, then you can’t do this. 50 PROBLEM? We inherit from the board, but we hardly use its methods or properties. Because they don’t match with 3D board.
  • 51. LISKOV SUBSTITUTION PRINCIPLE • Sub-classes must be substitutable for their base classes. – If you inherit from a wrong base class, then you can’t do this. 51 SOLUTION?
  • 52. INTERFACE SEGGREGATION PRINCIPLE • A class should never be forced to have some unnecessary methods. 52 PROBLEM? We force Square to have a computeVolume method, which it doesn’t have!
  • 54. DEPENDENCY INVERSION PRINCIPLE • Entities must depend on abstractions/interfaces rather than actual classes. – So that they can be decoupled. 54 PROBLEM?We have to treat each shape separately. Because we have links to actual classes.
  • 56. WHAT CAN WE ACHIEVE FROM THIS? SOME IDEAS • Read data from various sources but our program can stay the same • Easily switch between different algorithms on the same data • Make any module work independent from others • Make the output of the project independent from the data or the algorithm itself • Test the correctness of each class independently • Model the problem in a human-readable way • And most importantly, reuse and maintain your application better. – Future-proof. 56
  • 57. OTHER TOOLS & TECHNOLOGIES IN ORDER TO IMPROVE YOUR PROGRAMMING • Versioning (github, bitbucket etc.) – Version your code in order to access any change you made (and backup) • Unit tests – Test each unit independently, be sure it is doing whatever it is supposed to do. – Most languages have support for this. Look for it. • Documentation (Doxygen, Javadoc etc.) – Always comment your code. You can even produce automatic documentation from these comments. • Diagramming – Your code may not be understandable, but your diagrams will be. Learn UML Class diagram and use it in your projects. 57
  • 58. CONCLUSION • Object-oriented programming provides very flexible structures for our programs. – It can be applied in many languages, as long as the language supports object-orientation. • If we obey the principles, it will be an actual system. – Otherwise, it is just the same code with classes and additional complexity. • Object-oriented system is not a perfect system and it has its own flaws. But it is still the best system. • Always strive for the best design. 58
  • 59. QUESTIONS? • Thanks for listening… • For offline questions, find my contact info here: www.objectivelook.net 59
  • 60. SOME RESOURCES • Object-oriented programming with C# (The book itself is nice and free, chapter 20 is OOP): http://www.introprogramming.info/english-intro- csharp-book/read-online/ • For new starters to OOP, this book is fun: https://www.amazon.com/Head-First-Object-Oriented-Analysis- Design/dp/0596008678 • Detailed explanation, nicely done, 2 pages (Java): – https://www.ntu.edu.sg/home/ehchua/programming/java/J3a_OOPBasics.ht ml – https://www.ntu.edu.sg/home/ehchua/programming/java/J3b_OOPInheritan cePolymorphism.html • Same as above but with C++: – https://www.ntu.edu.sg/home/ehchua/programming/cpp/cp3_OOP.html • Even though, there are a lot of resources. I suggest to work with someone who you can ask questions immediately. Because OOP requires a change of mindset. 60