Professional Documents
Culture Documents
OOPs
OOPs
OOPs
possible
Polymorphism
inheritance
Encapsulation
Il supports
Principle Abstraction
Abstraction
Representing complex system as
a
a set of
high lend ideas without
giving too many lower level
details of the system
Encapsulation
the properties
Hiding
behaviour from outside world
i
1 Not
overloading float mi Cinta into
ist mi Cinta int b
main C
A a new AC
1 How will Runtime a m 10,20
know which is called
or int mi
float mi
How is evaluated at
assignment
Runtime
int se Add 10 20
Eg
Note For Asignment or
association is
from right to left
so runtime will calculate right
hand side
first then cast the
result with the variable on
type
left
types
is fine until child impt
Overriding
doesn't have element of
any
surprise
Inheritance Is A
relationship
Composition Support composition once
Inheritance Inheritance
creates
unnecessary couplings
SOLID
Design Principles
a Bird
Example Design
Class Bird
color
weight
type
weight
I Naive 1st Approach
fly
or
of type Crow
I do crow
else if type hen
hen
1 50 on
flya
11 keep on as
adding
new Birds
get added
Observe the that
requirement
varies most gets affected by
Isolate that
different actors
into a
different class
Cyclomatic complexity high means
method doing too
many things
Multiple people working on same
code incurs
merge conflicts
This is violation of SRP
SRP
the the
governs change of
module package class method
Identify SRP
Method have
many
if else conditional Blocks
class has too many
attributes
Violation Example
utie
packages
Coincidental cohesion
SRP
why Increase because
it asks to
reusability
create code
smaller
code
from larger
increases
readability by making
it smaller towards
a
working
single purpose
work
Many people can parallaly
with fewer because
merge conflict
it
change for a single
season
always takes
Almost case of
feature
on
Modify making changes
existing codebase
This result in
may
runtime behaviour
unexpected
which the client
of the
method not have expected
fye
may
Good code bases should
surprise as much as
reduce
possible Principle of least
surprise
Implement blank fly C method in
child
Doing nothing when its
expected to fly is kind of a
surprise
Errors should be as
caught
much as
possible compile time
at
So there would be least surprise
at Runtime Fail Fast
Leskov substitution Principle Lsp
child class
object can be
used where
anywhere parent class
is used
child where
using object
used should not
parent is
produce surprise or
unexpec ed
any
behaviour at runtime
Fly
Create subclasses to handle
each case where birds can
can't eat can't eat
fly or
decoo
fly
Bird
L T
flyingBird NonflyingBird
L
NOEInonp .ir
Eaterybird Spiffy Ebony
É
If there are N attributes will have
2N such Classes that a class
explosion which is Bad
If should be as
interfaces
lean says then as I
possible
should not be thick
inversion D1
Dependency
on
Always depend
interface not on concrete Implementation
Questions to ask
what is the context of the
system
Ask points that if changed
will affect the
design
what is start or termination