SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
 
Java Basic Oops Concept
Java Basic Oops ConceptJava Basic Oops Concept
Java Basic Oops Concept
 
Object and class relationships
Object and class relationshipsObject and class relationships
Object and class relationships
 
06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classes
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
 
CS3391 OOP UT-I T3 FEATURES OF OBJECT ORIENTED PROGRAMMING
CS3391 OOP UT-I T3 FEATURES OF OBJECT ORIENTED PROGRAMMINGCS3391 OOP UT-I T3 FEATURES OF OBJECT ORIENTED PROGRAMMING
CS3391 OOP UT-I T3 FEATURES OF OBJECT ORIENTED PROGRAMMING
 
Object Oriented programming - Introduction
Object Oriented programming - IntroductionObject Oriented programming - Introduction
Object Oriented programming - Introduction
 
Oops ppt
Oops pptOops ppt
Oops ppt
 
Object Oriented Language
Object Oriented LanguageObject Oriented Language
Object Oriented Language
 
Python-Encapsulation.pptx
Python-Encapsulation.pptxPython-Encapsulation.pptx
Python-Encapsulation.pptx
 
Abstraction and Encapsulation
Abstraction and EncapsulationAbstraction and Encapsulation
Abstraction and Encapsulation
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Classes and Objects
Classes and Objects  Classes and Objects
Classes and Objects
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Polymorphism in oop
Polymorphism in oopPolymorphism in oop
Polymorphism in oop
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 

Semelhante a Object oriented programming interview questions

Object Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshopObject Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshopMohammad Shawahneh
 
Lecture 4-oop class diagram
Lecture 4-oop class diagramLecture 4-oop class diagram
Lecture 4-oop class diagramktuonlinenotes
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programmingsharmisivarajah
 
Advanced Programming _Abstract Classes vs Interfaces (Java)
Advanced Programming _Abstract Classes vs Interfaces (Java)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 Program2CPP05 - Modelling an Object Oriented Program
2CPP05 - Modelling an Object Oriented ProgramMichael Heron
 
Problem solving with python programming OOP's Concept
Problem solving with python programming OOP's ConceptProblem solving with python programming OOP's Concept
Problem solving with python programming OOP's Conceptrohitsharma24121
 
Introduction to OOA and UML
Introduction to OOA and UMLIntroduction to OOA and UML
Introduction to OOA and UMLVeneet-BA
 
Introduction to OOA and UML
Introduction to OOA and UMLIntroduction to OOA and UML
Introduction to OOA and UMLVeneet-BA
 
CPP14 - Encapsulation
CPP14 - EncapsulationCPP14 - Encapsulation
CPP14 - EncapsulationMichael Heron
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1Geophery sanga
 
SAD02 - Object Orientation
SAD02 - Object OrientationSAD02 - Object Orientation
SAD02 - Object OrientationMichael Heron
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UMLSwatiS-BA
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming ConceptsSanmatiRM
 
UML Training for Business Analysts
UML Training for Business AnalystsUML Training for Business Analysts
UML Training for Business AnalystsSwatiS-BA
 

Semelhante a Object oriented programming interview questions (20)

Object Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshopObject Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshop
 
Concepts of oops
Concepts of oopsConcepts of oops
Concepts of oops
 
Lecture 4-oop class diagram
Lecture 4-oop class diagramLecture 4-oop class diagram
Lecture 4-oop class diagram
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Advanced Programming _Abstract Classes vs Interfaces (Java)
Advanced Programming _Abstract Classes vs Interfaces (Java)Advanced Programming _Abstract Classes vs Interfaces (Java)
Advanced Programming _Abstract Classes vs Interfaces (Java)
 
2CPP05 - Modelling an Object Oriented Program
2CPP05 - Modelling an Object Oriented Program2CPP05 - Modelling an Object Oriented Program
2CPP05 - Modelling an Object Oriented Program
 
Unified Modelling Language
Unified Modelling Language Unified Modelling Language
Unified Modelling Language
 
ER Model in DBMS
ER Model in DBMSER Model in DBMS
ER Model in DBMS
 
Problem solving with python programming OOP's Concept
Problem solving with python programming OOP's ConceptProblem solving with python programming OOP's Concept
Problem solving with python programming OOP's Concept
 
oopm 2.pdf
oopm 2.pdfoopm 2.pdf
oopm 2.pdf
 
Introduction to OOA and UML
Introduction to OOA and UMLIntroduction to OOA and UML
Introduction to OOA and UML
 
Introduction to OOA and UML
Introduction to OOA and UMLIntroduction to OOA and UML
Introduction to OOA and UML
 
CPP14 - Encapsulation
CPP14 - EncapsulationCPP14 - Encapsulation
CPP14 - Encapsulation
 
O6u CS-315A OOP Lecture (1).pdf
O6u CS-315A OOP Lecture (1).pdfO6u CS-315A OOP Lecture (1).pdf
O6u CS-315A OOP Lecture (1).pdf
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1
 
Software Engineering1-1-UML.ppt
Software Engineering1-1-UML.pptSoftware Engineering1-1-UML.ppt
Software Engineering1-1-UML.ppt
 
SAD02 - Object Orientation
SAD02 - Object OrientationSAD02 - Object Orientation
SAD02 - Object Orientation
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
UML Training for Business Analysts
UML Training for Business AnalystsUML Training for Business Analysts
UML Training for Business Analysts
 

Mais de Keet Sugathadasa

Chaos Engineering - The Art of Breaking Things in Production
Chaos Engineering - The Art of Breaking Things in ProductionChaos Engineering - The Art of Breaking Things in Production
Chaos Engineering - The Art of Breaking Things in ProductionKeet Sugathadasa
 
Site Reliability Engineering (SRE) - Tech Talk by Keet Sugathadasa
Site Reliability Engineering (SRE) - Tech Talk by Keet SugathadasaSite Reliability Engineering (SRE) - Tech Talk by Keet Sugathadasa
Site Reliability Engineering (SRE) - Tech Talk by Keet SugathadasaKeet Sugathadasa
 
Human Computer Interaction - Facebook Messenger
Human Computer Interaction - Facebook MessengerHuman Computer Interaction - Facebook Messenger
Human Computer Interaction - Facebook MessengerKeet Sugathadasa
 
Cyber Security and Cloud Computing
Cyber Security and Cloud ComputingCyber Security and Cloud Computing
Cyber Security and Cloud ComputingKeet Sugathadasa
 
How to compete in hackathons
How to compete in hackathonsHow to compete in hackathons
How to compete in hackathonsKeet Sugathadasa
 
Quality Engineering - When to Stop Testing
Quality Engineering - When to Stop TestingQuality Engineering - When to Stop Testing
Quality Engineering - When to Stop TestingKeet Sugathadasa
 
Training Report WSO2 internship
Training Report  WSO2 internshipTraining Report  WSO2 internship
Training Report WSO2 internshipKeet Sugathadasa
 
Revolutionizing digital authentication with gsma mobile connect
Revolutionizing digital authentication with gsma mobile connectRevolutionizing digital authentication with gsma mobile connect
Revolutionizing digital authentication with gsma mobile connectKeet Sugathadasa
 

Mais de Keet Sugathadasa (9)

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

Último

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 

Último (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 

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