SlideShare a Scribd company logo
Object Oriented
Programming
Interview Preparation
Keet Malin Sugathadasa
Undergraduate
Department of Computer Science and Engineering
University of Moratuwa
Agenda
● Objects (Instances)
● Classes
● Advantages of OOP
● Disadvantages of OOP
● Let’s Design an OOP Solution
● OOP Concepts
● UML - Unified Modelling Language
● UML Syntax
● Associations
● Inheritance
● Cohesion and Coupling
Objects (Instances)
An Object can be used to effectively represent real world entities
● Object has
○ States (descriptive characteristics)
■ Simple Attributes- Primitive data types
■ Complex Attributes - Contains collections
○ Behaviours ( what it can do)
Example
● Keet’s Bank Account
○ State: Account number, Available balance
○ Behaviour: Make deposits, Withdraw
Classes
● An object is defined by a class
Advantages of OOP
● Code Reusing and Recycling
○ Saves development time and cost
● Encapsulation
○ Once object is created, knowledge of its implementation is not necessary for use.
● Design Benefits
○ Easy to understand. Large programs get more and more complex, but with OOP, designs can
be made with less flaws
● Software Maintenance
○ Programs are not disposable. An OOP is much easier to modify and maintain than a non-OOP
Disadvantages of OOP
● Size
○ OOPs are much larger than other programs
● Effort
○ OOPs require a lot of work and planning to develop
● Speed
○ OOPs are slower than other programs (Partially because of their size)
Object Oriented Problem Solving Approach
1. Identify the Problem
a. Carefully read the given problem and highlight the important points
2. Identify the Objects
a. Identify the main objects. Sometime two entities can be selected as one, but sometimes, it
might be better to have two instead of one complex one.
3. Identify the messages to be sent to other objects
a. Identify what kind of interactions happen between objects in classes
4. Create a sequence of messages to the objects - to solve the problem
a. Find a pattern to solve the final problem by interacting with different objects.
Let’s Design an OOP Solution
You need to create a Wedding Management System. Each wedding has a bride, a
groom, flower decorator, food provider, location etc. Each bride and groom has
their own parents and friends.
Find a way to model this problem into an OOP solution.
Just identifying the objects and the required interactions between them is
sufficient. Represent the interactions by simple arrows.
Overview of OOP
OOP Concepts
● Abstraction
○ Allows us to consider the important high level details
● Encapsulation
○ Allows us to consider what the program does and how it operates it. Without reading the
technical details of how it actually works
● Inheritance
○ Generalization and Specialization. Specialized objects can automatically inherit all the
characteristics of the more generalized objects.
● Polymorphism
○ Is the ability to interact with an object as its generalized category, regardless of its more
specialized category.
UML - Unified Modelling Language
● Class Diagrams
○ Classes show what the objects consists of and the methods
● Object Diagrams
○ Objects in the system and how they interact and the values in that object at a given state in time
● Sequence Diagrams
○ shows object interactions arranged in time sequence. How objects will interact to support one
specific function
● Package Diagrams
○ Packages and dependencies between packages
Class Consists of
● A unique Name
○ Conventionally starting with an Uppercase Letter
● A list of Attributes (Mostly Private)
○ Int, double, boolean, String, Complex Attributes
● A list of Methods (Mostly Public)
○ Unique method names starting with a Lowercase letter
Visibility Modifiers (Access Modifiers)
+ for public access
- for private access
UML allows us to suppress any information we do not wish to highlight in our
diagrams
UML Syntax
● Attributes
○ <visibility> <name> : <type> <multiplicity>
■ Eg: + custRef : int [1] → a public attribute custRef is a single int value
● Methods
○ <visibility> <name> ( <parameter 1> : <type 1> , …….) : <Return Type>
■ Eg: + addName (newName : String) : Boolean
Relationships Between Classes
● Some Class attributes can be complex
○ Can include some other class object as attributes
■ Eg: Teacher class has attribute → list of Students
○ String data type is a complex data type
■ Since it is part of the Java platform, it is implied that String is a primitive data type
Example
● ‘n’ → exactly n
● ‘*’ → zero or more
● ‘m..n; → between m and n
Types of Association
● Dependency A --------------------------> B
● Simple Association A B
● Bidirectional Association A B
● Aggregation A B
● Composition A B
Dependency
Class A in some way uses facilities defined by Class B. Changes to class B may
affect class A. There are 3 ways in which dependencies can occur
● Class A has a method, which passes as a parameter object of Class B
● Class A uses a local variable of Class B
● Class A calls static methods in Class B
Simple Association
Class A uses objects of Class B. Typically Class A has an attribute of Class B.
Navigability is from A to B.
● Class A objects can access Class B objects with which it is associated.
○ The reverse is not true.
Eg: Teacher wants to maintain a list of Students. So navigability is from Teacher to
Student. So Teacher object can access Student objects. But student objects do not
necessarily need access to teacher objects.
Bidirectional Association
This is when Class A and Class B has a two way association. Each refers to the
other class. Navigability is from A to B and B to A.
Navigability from A to B means
● Class A object can access Class B objects
● Objects of Class A “Has a” Class A
● This implies reference from A to B
Eg:
Between a “Degree” and “Student”. Given a degree, we may need to know which
students are studying on that degree. Alternatively, given a student, we may wish
to know the degree they are studying.
Aggregation
Aggregation denotes a situation where object(s) of Class B “Belongs to” Class B.
Aggregation also mentions that Objects of Class B, retain an existence
independent of Class A.
Eg:
We can think of tyres belonging to a car. Tyres “Belong To” Cars. But if our context
relates to a tyre shop or something, then Tyres can exist alone, in a garage as well.
Composition
● Composition is similar to aggregation, but implies a much stronger relationship.
● Class B objects are an integral part of Class A. In general, objects of class B
never exist other than as part of Class A. Both have the same lifetime.
Eg:
Between points, lines and shapes as elements of a picture. These objects can only
exist as part of a picture, and if the picture is deleted, they are also deleted.
Inheritance
Class A Class B
Class A inherits both implementation and interface of Class B.
This is how specialization and generalization works. Specialized classes can inherit
from generalized classes.
Interfaces
Class A Class B
● With interface inheritance, Class A will inherit only the interface of Class B.
● Class B contains only method headers
● Class A has to implement all methods defined in Class B
Cohesion
● Cohesion describes how closely all routines in a class or all the code in a
routing support a central purpose.
● Cohesion must be Strong.
● Classes must contain a strongly related functionality and aim for single
purpose
● Cohesion is an important tool for managing complexities
Coupling
● Coupling describes how tightly a class or routine is related to other classes or
routines.
● Coupling must be kept Loose.
○ Modules must depend little on each other
○ One module can be replaced easily without causing trouble
○ A module can be easily used by other modules
● Two types of Coupling
○ Tight Coupling
○ Loose Coupling
Ad

Recommended

OOP Introduction with java programming language
OOP Introduction with java programming language
Md.Al-imran Roton
 
OOP interview questions & answers.
OOP interview questions & answers.
Questpond
 
OOP java
OOP java
xball977
 
Basic concepts of object oriented programming
Basic concepts of object oriented programming
Sachin Sharma
 
Object oriented programming
Object oriented programming
Amit Soni (CTFL)
 
object oriented Programming ppt
object oriented Programming ppt
Nitesh Dubey
 
Object Oriented Programming Concepts
Object Oriented Programming Concepts
thinkphp
 
Lecture 1 oop
Lecture 1 oop
Tony Apreku
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVA
sivasundari6
 
OOPs in Java
OOPs in Java
Ranjith Sekar
 
Object Oriented Programming ppt presentation
Object Oriented Programming ppt presentation
AyanaRukasar
 
Introduction to oop
Introduction to oop
colleges
 
Ooad ch 3
Ooad ch 3
anujabeatrice2
 
Object oriented programming concept
Object oriented programming concept
Pina Parmar
 
Member Function in C++
Member Function in C++
NikitaKaur10
 
ArrayList in JAVA
ArrayList in JAVA
SAGARDAVE29
 
concept of oops
concept of oops
prince sharma
 
S.O.L.I.D. Principles for Software Architects
S.O.L.I.D. Principles for Software Architects
Ricardo Wilkins
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
Basic concept of OOP's
Basic concept of OOP's
Prof. Dr. K. Adisesha
 
SOLID - Principles of Object Oriented Design
SOLID - Principles of Object Oriented Design
Riccardo Cardin
 
Standard Template Library
Standard Template Library
GauravPatil318
 
Association agggregation and composition
Association agggregation and composition
baabtra.com - No. 1 supplier of quality freshers
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentals
AnsgarMary
 
Object oriented concepts ppt
Object oriented concepts ppt
Prof. Dr. K. Adisesha
 
Singleton design pattern
Singleton design pattern
11prasoon
 
C++ Interview Questions
C++ Interview Questions
Kaushik Raghupathi
 
Object Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshop
Mohammad Shawahneh
 
Concepts of oops
Concepts of oops
Sourabrata Mukherjee
 

More Related Content

What's hot (20)

WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVA
sivasundari6
 
OOPs in Java
OOPs in Java
Ranjith Sekar
 
Object Oriented Programming ppt presentation
Object Oriented Programming ppt presentation
AyanaRukasar
 
Introduction to oop
Introduction to oop
colleges
 
Ooad ch 3
Ooad ch 3
anujabeatrice2
 
Object oriented programming concept
Object oriented programming concept
Pina Parmar
 
Member Function in C++
Member Function in C++
NikitaKaur10
 
ArrayList in JAVA
ArrayList in JAVA
SAGARDAVE29
 
concept of oops
concept of oops
prince sharma
 
S.O.L.I.D. Principles for Software Architects
S.O.L.I.D. Principles for Software Architects
Ricardo Wilkins
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
Basic concept of OOP's
Basic concept of OOP's
Prof. Dr. K. Adisesha
 
SOLID - Principles of Object Oriented Design
SOLID - Principles of Object Oriented Design
Riccardo Cardin
 
Standard Template Library
Standard Template Library
GauravPatil318
 
Association agggregation and composition
Association agggregation and composition
baabtra.com - No. 1 supplier of quality freshers
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentals
AnsgarMary
 
Object oriented concepts ppt
Object oriented concepts ppt
Prof. Dr. K. Adisesha
 
Singleton design pattern
Singleton design pattern
11prasoon
 
C++ Interview Questions
C++ Interview Questions
Kaushik Raghupathi
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVA
sivasundari6
 
Object Oriented Programming ppt presentation
Object Oriented Programming ppt presentation
AyanaRukasar
 
Introduction to oop
Introduction to oop
colleges
 
Object oriented programming concept
Object oriented programming concept
Pina Parmar
 
Member Function in C++
Member Function in C++
NikitaKaur10
 
ArrayList in JAVA
ArrayList in JAVA
SAGARDAVE29
 
S.O.L.I.D. Principles for Software Architects
S.O.L.I.D. Principles for Software Architects
Ricardo Wilkins
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
SOLID - Principles of Object Oriented Design
SOLID - Principles of Object Oriented Design
Riccardo Cardin
 
Standard Template Library
Standard Template Library
GauravPatil318
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentals
AnsgarMary
 
Singleton design pattern
Singleton design pattern
11prasoon
 

Similar to Object oriented programming interview questions (20)

Object Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshop
Mohammad Shawahneh
 
Concepts of oops
Concepts of oops
Sourabrata Mukherjee
 
Lecture 4-oop class diagram
Lecture 4-oop class diagram
ktuonlinenotes
 
Object Oriented Programming
Object Oriented Programming
sharmisivarajah
 
Advanced Programming _Abstract Classes vs Interfaces (Java)
Advanced Programming _Abstract Classes vs Interfaces (Java)
Professor Lili Saghafi
 
2CPP05 - Modelling an Object Oriented Program
2CPP05 - Modelling an Object Oriented Program
Michael Heron
 
Unified Modelling Language
Unified Modelling Language
TRAN Khanh Dung, Khoa CNTT, Đại Học Xây Dựng
 
ER Model in DBMS
ER Model in DBMS
Kabindra Koirala
 
Problem solving with python programming OOP's Concept
Problem solving with python programming OOP's Concept
rohitsharma24121
 
oopm 2.pdf
oopm 2.pdf
jayeshsoni49
 
Introduction to OOA and UML
Introduction to OOA and UML
Veneet-BA
 
Introduction to OOA and UML
Introduction to OOA and UML
Veneet-BA
 
Introduction to OOPs second year cse.pptx
Introduction to OOPs second year cse.pptx
solemanhldr
 
CPP14 - Encapsulation
CPP14 - Encapsulation
Michael Heron
 
O6u CS-315A OOP Lecture (1).pdf
O6u CS-315A OOP Lecture (1).pdf
MohamedRamadan454985
 
object oriented programing lecture 1
object oriented programing lecture 1
Geophery sanga
 
Object -oriented analysis and design.ppt
Object -oriented analysis and design.ppt
pierrerj05
 
Software Engineering1-1-UML.ppt
Software Engineering1-1-UML.ppt
naqibullah2022faryab
 
SAD02 - Object Orientation
SAD02 - Object Orientation
Michael Heron
 
Introduction to UML
Introduction to UML
SwatiS-BA
 
Object Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshop
Mohammad Shawahneh
 
Lecture 4-oop class diagram
Lecture 4-oop class diagram
ktuonlinenotes
 
Object Oriented Programming
Object Oriented Programming
sharmisivarajah
 
Advanced Programming _Abstract Classes vs Interfaces (Java)
Advanced Programming _Abstract Classes vs Interfaces (Java)
Professor Lili Saghafi
 
2CPP05 - Modelling an Object Oriented Program
2CPP05 - Modelling an Object Oriented Program
Michael Heron
 
Problem solving with python programming OOP's Concept
Problem solving with python programming OOP's Concept
rohitsharma24121
 
Introduction to OOA and UML
Introduction to OOA and UML
Veneet-BA
 
Introduction to OOA and UML
Introduction to OOA and UML
Veneet-BA
 
Introduction to OOPs second year cse.pptx
Introduction to OOPs second year cse.pptx
solemanhldr
 
CPP14 - Encapsulation
CPP14 - Encapsulation
Michael Heron
 
object oriented programing lecture 1
object oriented programing lecture 1
Geophery sanga
 
Object -oriented analysis and design.ppt
Object -oriented analysis and design.ppt
pierrerj05
 
SAD02 - Object Orientation
SAD02 - Object Orientation
Michael Heron
 
Introduction to UML
Introduction to UML
SwatiS-BA
 
Ad

More from Keet Sugathadasa (9)

Chaos Engineering - The Art of Breaking Things in Production
Chaos Engineering - The Art of Breaking Things in Production
Keet Sugathadasa
 
Site Reliability Engineering (SRE) - Tech Talk by Keet Sugathadasa
Site Reliability Engineering (SRE) - Tech Talk by Keet Sugathadasa
Keet Sugathadasa
 
Human Computer Interaction - Facebook Messenger
Human Computer Interaction - Facebook Messenger
Keet Sugathadasa
 
Cyber Security and Cloud Computing
Cyber Security and Cloud Computing
Keet Sugathadasa
 
How to compete in hackathons
How to compete in hackathons
Keet Sugathadasa
 
Quality Engineering - When to Stop Testing
Quality Engineering - When to Stop Testing
Keet Sugathadasa
 
Training Report WSO2 internship
Training Report WSO2 internship
Keet Sugathadasa
 
Interview Facing Workshop
Interview Facing Workshop
Keet Sugathadasa
 
Revolutionizing digital authentication with gsma mobile connect
Revolutionizing digital authentication with gsma mobile connect
Keet Sugathadasa
 
Chaos Engineering - The Art of Breaking Things in Production
Chaos Engineering - The Art of Breaking Things in Production
Keet Sugathadasa
 
Site Reliability Engineering (SRE) - Tech Talk by Keet Sugathadasa
Site Reliability Engineering (SRE) - Tech Talk by Keet Sugathadasa
Keet Sugathadasa
 
Human Computer Interaction - Facebook Messenger
Human Computer Interaction - Facebook Messenger
Keet Sugathadasa
 
Cyber Security and Cloud Computing
Cyber Security and Cloud Computing
Keet Sugathadasa
 
How to compete in hackathons
How to compete in hackathons
Keet Sugathadasa
 
Quality Engineering - When to Stop Testing
Quality Engineering - When to Stop Testing
Keet Sugathadasa
 
Training Report WSO2 internship
Training Report WSO2 internship
Keet Sugathadasa
 
Revolutionizing digital authentication with gsma mobile connect
Revolutionizing digital authentication with gsma mobile connect
Keet Sugathadasa
 
Ad

Recently uploaded (20)

Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Philip Schwarz
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
Zoneranker’s Digital marketing solutions
Zoneranker’s Digital marketing solutions
reenashriee
 
Key Challenges in Troubleshooting Customer On-Premise Applications
Key Challenges in Troubleshooting Customer On-Premise Applications
Tier1 app
 
UPDASP a project coordination unit ......
UPDASP a project coordination unit ......
withrj1
 
NVIDIA Artificial Intelligence Ecosystem and Workflows
NVIDIA Artificial Intelligence Ecosystem and Workflows
SandeepKS52
 
Decipher SEO Solutions for your startup needs.
Decipher SEO Solutions for your startup needs.
mathai2
 
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
joybepari360
 
Sysinfo OST to PST Converter Infographic
Sysinfo OST to PST Converter Infographic
SysInfo Tools
 
Complete WordPress Programming Guidance Book
Complete WordPress Programming Guidance Book
Shabista Imam
 
Y - Recursion The Hard Way GopherCon EU 2025
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
Migrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right Way
Alexander (Alex) Komyagin
 
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Technologies
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
 
ElectraSuite_Prsentation(online voting system).pptx
ElectraSuite_Prsentation(online voting system).pptx
mrsinankhan01
 
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Philip Schwarz
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
Zoneranker’s Digital marketing solutions
Zoneranker’s Digital marketing solutions
reenashriee
 
Key Challenges in Troubleshooting Customer On-Premise Applications
Key Challenges in Troubleshooting Customer On-Premise Applications
Tier1 app
 
UPDASP a project coordination unit ......
UPDASP a project coordination unit ......
withrj1
 
NVIDIA Artificial Intelligence Ecosystem and Workflows
NVIDIA Artificial Intelligence Ecosystem and Workflows
SandeepKS52
 
Decipher SEO Solutions for your startup needs.
Decipher SEO Solutions for your startup needs.
mathai2
 
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
joybepari360
 
Sysinfo OST to PST Converter Infographic
Sysinfo OST to PST Converter Infographic
SysInfo Tools
 
Complete WordPress Programming Guidance Book
Complete WordPress Programming Guidance Book
Shabista Imam
 
Y - Recursion The Hard Way GopherCon EU 2025
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Technologies
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
 
ElectraSuite_Prsentation(online voting system).pptx
ElectraSuite_Prsentation(online voting system).pptx
mrsinankhan01
 

Object oriented programming interview questions

  • 1. Object Oriented Programming Interview Preparation Keet Malin Sugathadasa Undergraduate Department of Computer Science and Engineering University of Moratuwa
  • 2. Agenda ● Objects (Instances) ● Classes ● Advantages of OOP ● Disadvantages of OOP ● Let’s Design an OOP Solution ● OOP Concepts ● UML - Unified Modelling Language ● UML Syntax ● Associations ● Inheritance ● Cohesion and Coupling
  • 3. Objects (Instances) An Object can be used to effectively represent real world entities ● Object has ○ States (descriptive characteristics) ■ Simple Attributes- Primitive data types ■ Complex Attributes - Contains collections ○ Behaviours ( what it can do) Example ● Keet’s Bank Account ○ State: Account number, Available balance ○ Behaviour: Make deposits, Withdraw
  • 4. Classes ● An object is defined by a class
  • 5. Advantages of OOP ● Code Reusing and Recycling ○ Saves development time and cost ● Encapsulation ○ Once object is created, knowledge of its implementation is not necessary for use. ● Design Benefits ○ Easy to understand. Large programs get more and more complex, but with OOP, designs can be made with less flaws ● Software Maintenance ○ Programs are not disposable. An OOP is much easier to modify and maintain than a non-OOP
  • 6. Disadvantages of OOP ● Size ○ OOPs are much larger than other programs ● Effort ○ OOPs require a lot of work and planning to develop ● Speed ○ OOPs are slower than other programs (Partially because of their size)
  • 7. Object Oriented Problem Solving Approach 1. Identify the Problem a. Carefully read the given problem and highlight the important points 2. Identify the Objects a. Identify the main objects. Sometime two entities can be selected as one, but sometimes, it might be better to have two instead of one complex one. 3. Identify the messages to be sent to other objects a. Identify what kind of interactions happen between objects in classes 4. Create a sequence of messages to the objects - to solve the problem a. Find a pattern to solve the final problem by interacting with different objects.
  • 8. Let’s Design an OOP Solution You need to create a Wedding Management System. Each wedding has a bride, a groom, flower decorator, food provider, location etc. Each bride and groom has their own parents and friends. Find a way to model this problem into an OOP solution. Just identifying the objects and the required interactions between them is sufficient. Represent the interactions by simple arrows.
  • 10. OOP Concepts ● Abstraction ○ Allows us to consider the important high level details ● Encapsulation ○ Allows us to consider what the program does and how it operates it. Without reading the technical details of how it actually works ● Inheritance ○ Generalization and Specialization. Specialized objects can automatically inherit all the characteristics of the more generalized objects. ● Polymorphism ○ Is the ability to interact with an object as its generalized category, regardless of its more specialized category.
  • 11. UML - Unified Modelling Language ● Class Diagrams ○ Classes show what the objects consists of and the methods ● Object Diagrams ○ Objects in the system and how they interact and the values in that object at a given state in time ● Sequence Diagrams ○ shows object interactions arranged in time sequence. How objects will interact to support one specific function ● Package Diagrams ○ Packages and dependencies between packages
  • 12. Class Consists of ● A unique Name ○ Conventionally starting with an Uppercase Letter ● A list of Attributes (Mostly Private) ○ Int, double, boolean, String, Complex Attributes ● A list of Methods (Mostly Public) ○ Unique method names starting with a Lowercase letter Visibility Modifiers (Access Modifiers) + for public access - for private access UML allows us to suppress any information we do not wish to highlight in our diagrams
  • 13. UML Syntax ● Attributes ○ <visibility> <name> : <type> <multiplicity> ■ Eg: + custRef : int [1] → a public attribute custRef is a single int value ● Methods ○ <visibility> <name> ( <parameter 1> : <type 1> , …….) : <Return Type> ■ Eg: + addName (newName : String) : Boolean
  • 14. Relationships Between Classes ● Some Class attributes can be complex ○ Can include some other class object as attributes ■ Eg: Teacher class has attribute → list of Students ○ String data type is a complex data type ■ Since it is part of the Java platform, it is implied that String is a primitive data type
  • 15. Example ● ‘n’ → exactly n ● ‘*’ → zero or more ● ‘m..n; → between m and n
  • 16. Types of Association ● Dependency A --------------------------> B ● Simple Association A B ● Bidirectional Association A B ● Aggregation A B ● Composition A B
  • 17. Dependency Class A in some way uses facilities defined by Class B. Changes to class B may affect class A. There are 3 ways in which dependencies can occur ● Class A has a method, which passes as a parameter object of Class B ● Class A uses a local variable of Class B ● Class A calls static methods in Class B
  • 18. Simple Association Class A uses objects of Class B. Typically Class A has an attribute of Class B. Navigability is from A to B. ● Class A objects can access Class B objects with which it is associated. ○ The reverse is not true. Eg: Teacher wants to maintain a list of Students. So navigability is from Teacher to Student. So Teacher object can access Student objects. But student objects do not necessarily need access to teacher objects.
  • 19. Bidirectional Association This is when Class A and Class B has a two way association. Each refers to the other class. Navigability is from A to B and B to A. Navigability from A to B means ● Class A object can access Class B objects ● Objects of Class A “Has a” Class A ● This implies reference from A to B Eg: Between a “Degree” and “Student”. Given a degree, we may need to know which students are studying on that degree. Alternatively, given a student, we may wish to know the degree they are studying.
  • 20. Aggregation Aggregation denotes a situation where object(s) of Class B “Belongs to” Class B. Aggregation also mentions that Objects of Class B, retain an existence independent of Class A. Eg: We can think of tyres belonging to a car. Tyres “Belong To” Cars. But if our context relates to a tyre shop or something, then Tyres can exist alone, in a garage as well.
  • 21. Composition ● Composition is similar to aggregation, but implies a much stronger relationship. ● Class B objects are an integral part of Class A. In general, objects of class B never exist other than as part of Class A. Both have the same lifetime. Eg: Between points, lines and shapes as elements of a picture. These objects can only exist as part of a picture, and if the picture is deleted, they are also deleted.
  • 22. Inheritance Class A Class B Class A inherits both implementation and interface of Class B. This is how specialization and generalization works. Specialized classes can inherit from generalized classes.
  • 23. Interfaces Class A Class B ● With interface inheritance, Class A will inherit only the interface of Class B. ● Class B contains only method headers ● Class A has to implement all methods defined in Class B
  • 24. Cohesion ● Cohesion describes how closely all routines in a class or all the code in a routing support a central purpose. ● Cohesion must be Strong. ● Classes must contain a strongly related functionality and aim for single purpose ● Cohesion is an important tool for managing complexities
  • 25. Coupling ● Coupling describes how tightly a class or routine is related to other classes or routines. ● Coupling must be kept Loose. ○ Modules must depend little on each other ○ One module can be replaced easily without causing trouble ○ A module can be easily used by other modules ● Two types of Coupling ○ Tight Coupling ○ Loose Coupling