0% found this document useful (0 votes)
20 views72 pages

2 - OO Concepts New

Uploaded by

shahmrunalstudy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views72 pages

2 - OO Concepts New

Uploaded by

shahmrunalstudy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

Object Oriented Concepts

Before you Start

What makes a great software:


Great Software
Great Software means to

• Make sure the software does what the


customer wants it to do
• Apply strategies for flexible programming
constructs (Object Orientation)
• Strive for a maintainable, reusable design
Basic Idea of Object-Oriented
Approach

Addressing Complexities
A simple system
A bit detailing …
More detailing …
Similar is the Software System
Why is Software Inherently Complex

“ The complexity of the software is an


essential property, not an accidental one.”

Brooks
Elements of Complexity

• The complexity of problem domain


• The complexity of development process
• The complexity in software
• Behavior of discrete systems
Basic Idea is

Addressing Complexities
A complex system that works is invariably found to
have evolved from a simple system that worked…

A complex system designed from scratch never works


and cannot be patched up to make it work.
Basic Principles of Object Orientation

Object Orientation

Encapsulation
Abstraction

Modularity
Hierarchy
Hierarchy - Definition

Hierarchy is a ranking or ordering of abstractions .


Hierarchy
Types of Hierarchy
Relationships
Objects
Objects have precise characterization
What is Abstraction?

Salesperson

Product
Customer

Manages Complexity
Definition

Humans manage complexity through abstraction.

An Abstraction denotes the essential


characteristics of an object that distinguishes
it from all kinds of objects and thus provide
crisply defined conceptual boundaries, relative
to the perspective of the viewer
Abstraction
• Hide implementation from clients
– Clients depend on interface

Improves Resiliency
How to implement Abstraction?
• Abstract Classes
– Abstract Class in Java does the process of hiding the intricate
code implementation details from the user and just provides
the user with the necessary information. This phenomenon is
called Data Abstraction in Object-Oriented Programming
(Java). (Focuses on Functions…)
• Interfaces
– The interface in Java is a mechanism to achieve abstraction.
– An Interface in Java programming language is defined as an
abstract type used to specify the behavior of a class.
– An interface in Java is a blueprint of a behavior. A Java
interface contains static constants and abstract methods.
Interface

• Interface is a blueprint of class itself.


• A class implements interface.
Abstract classes vs Interface
Abstract classes vs. Interface
# Abstract classes Interface
1 Some methods are abstract, while All methods must be abstract.
some methods can have
implementation.
2 0 to 100% abstraction. (up to 100% abstraction. Always 100%, not a
100%) single method can have
implementation.
3 All types of attributes can be Only final attributes can be declared.
declared.
4 Can not create object. Can not create object.
5. No Multiple Inheritance. Can not Allows Multiple Inheritance. Can
inherit from multiple classes. inherit from multiple interfaces.
Encapsulation

• Encapsulation is the process of wrapping code


and data together into a single unit.

– In java, Encapsulation is implemented with


classes.
Encapsulation

• Encapsulation is the mechanism that binds together


code and the data it manipulates, and keeps both
safe from outside interference and misuse.
• One way to think about encapsulation is as a
protective wrapper that prevents the code and data
from being arbitrarily accessed by other code
defined outside the wrapper.
• Access to the code and data inside the wrapper is
tightly controlled through a well-defined interface.
Data Hiding

• Data hiding refers to hiding data from


unauthorized users. In Java it is usually done
with the help of access modifiers.

– It is implemented using access modifiers with


attributes inside classes.
Polymorphism, Encapsulation, and
Inheritance Work Together (OOP)
• When properly applied, polymorphism, encapsulation, and
inheritance(OOP) combine to produce a programming
environment that supports the development of far more robust
and scalable programs than does the process-oriented model.
• A well-designed hierarchy of classes is the basis for reusing
the code in which you have invested time and effort
developing and testing.
• Encapsulation allows you to migrate your implementations
over time without breaking the code that depends on the public
interface of your classes.
• Polymorphism allows you to create clean, sensible, readable,
and resilient code.
Definition

Encapsulation is the process of compartmentalizing the


elements of an abstraction that constitute its structure
and behavior;

encapsulation serves to separate the contractual


interface of an abstraction and its implementation.
Compartmentalizing

It focuses upon implementing the observable


behavior of the system, hiding all secrets of the
Object like structure of the object and its
implementation..

Information Hiding
Separation of Concerns

• Different abstractions
– Different Implementations

• Interface + Implementation concept


– For abstractions to work implementations must be
encapsulated… (Means we should not allow
data(attributes) to be accessed from outside of
class.)
What is this property of objects?
What is Modularity?
The breaking up of something complex into
manageable pieces
Order
Entry
Order
Processing Order
System Fulfillment

Billing

Manages Complexity
Modularity

• It is a property of the system that has been


decomposed into a set of cohesive and loosely
coupled modules.
No Conflict of Resources
Fair Provisioning
Threads are the Key Mechanism
Concurrency – An Analogy
Some Brain Work

• You use me to keep all the parts of the code


that stay the same separate from the parts that
change; then it is really easy to make changes
to your code without breaking everything.

Encapsulation
What is this characteristic?
What is this characteristic?
JAVA Concepts
JAVA
Concepts
Extends - Hierarchy
Encapsulation by Access Modifiers
References

• Book: Java 7th edition complete reference


(Softcopy uploaded on Teams.)
• 10-Minute Guide To Abstraction In Java
(crio.do)
Levels of Abstraction
Asset
Increasing
abstraction

BankAccount Security RealEstate

Savings Checking Stock Bond

Decreasing
abstraction
Elements at the same level of the hierarchy
should be at the same level of abstraction

You might also like