Object-Oriented Programming Concepts

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 44

Python

Programming
for Beginners
Instructor: Aung Hein
HELLO!
I am Aung Hein
Bachelor of Computer Science (UCSY)
Cyber Security & Quantum Computing
Enthusiasts

2
Python Programming for
Beiginners
0 . Fundamentals of Python
1. Object Oriented Programming Concepts

2. Data Structure & Algorithms

3. Design Pattern

4. Test Driven Development

5. Web Security & Secure Coding

6. Web Scraping

7. Automation &Testing

3
1 Object-Oriented Programming
Concepts
Why Object-Oriented Design?

⬢ Plan your program before writing a single line of code


⬢ OOP becomes the standard for everything from web development to
desktop applications
⬢ With OOP, they enable us to create applications that are flexible,
maintainable, and extensible

⬢ We won’t be writing code because during the design process, we don’t


need to. Instead, we will use UML(Unified Modelling Language) to
diagram visual models of our systems.
5
What is Object?
⬢ Just a noun e.g. The dog, the book, etc.
⬢ Each object has their own attributes such as size for shirt, colour for
laptop etc.
⬢ Attributes, properties, characteristics, state, fields, variables

⬢ All objects have …


⬡ Identity: Water bottle
⬡ Attributes: colour, size, fullness
⬡ Behaviours: fill(), empty, clean() 6
What is Object? (Cont’d)

Number: B3890 Number: E11234


Balance: 100,000MMK Balance: 90,000MMK
deposit() deposit()
withdraw() withdraw()

Bank Account Object Bank Account Object

7
What is Class?

Object

Class Object

Object
8
Class Component

Name: What is it? Attributes: What Behaviour: What


describes it? can it do?
Dog
life-span, color Sleep(),
Eat(), Run()

type properties, data operations

9
Dog
life-span
colour

sleep()
eat()
run()

Class
10
Dog
life-span 12 years 13 years
colour white brown

sleep() sleep() sleep()


eat() eat() eat()
run() run() run()

Class object(instance)
creating objects = instantiation 11
Fundamentals of OOP for creating classes
⬢ Abstraction
⬢ Polymorphism
⬢ Inheritance
⬢ Encapsulation

12
Abstraction
⬢ You would think male or female or someone you know might appear in
your mind when we tell you a person.

13
Abstraction (Cont’d )

Person
name
height
flavour
icing

sleep()
eat()
run()
14
Encapsulation
⬢ Restrict access to some of the object’s components

15
Encapsulation (Cont’d )

Cookie Jar
numCookie 10

16
Encapsulation (Cont’d )

Cookie Jar
numCookie 10

requestCookie()
requestCookie()

17
Inheritance
⬢ Base a new object or class on an existing one
⬢ Inherit the existing attributes and methods
⬢ Great form of code reuse!

18
Inheritance (Cont’d )

Customer Employee
name name
phone phone
address address
customerNumber employeeNumber

updateContact() updateContact()
purchase() promote()
retire()
19
Inheritance (Cont’d )

Customer Employee
name name
phone phone
address address
customerNumber employeeNumber

updateContact() updateContact()
purchase() promote()
retire()
20
Inheritance (Cont’d )
Person
name Superclass
(Parent class)
phone
(Base class)
“Customer inherits from Person” address

updateContact()

Customer Employee
Subclass
(Everything in (Everything in
(Child class)
Person) Person)
(Derived class)
customerID employeeID

purchase() purchase()
21
retire()
Inheritance (Cont’d )

Multiple inheritance Single inheritance


Parent1 Parent2 Parent3 Parent

Child Child

C++, Python Ruby, Swift, C#

22
Polymorphism
⬢ Use the same interface for methods on different types of objects

⬢ brew(groundCoffee, water)

23
Polymorphism (Cont’d )
BasicCoffeeMaker
size
brew()
pour()

FrenchPress
(Everything in BasicCoffeeMaker)
Overriding
brew()
24

Object-oriented

Analysis Design Programming

25

Object-oriented

Analysis – Understand your problem


(What do you need to do?)

26

Object-oriented

Design – Plan your solution


(How are you going to do it?)

27

Object-oriented
Programming – Build it

28
Requirements
Requirements = What does it need to do?
• Functional requirements = What must it do?
• Non-functional requirements = How should it do?

29
Functional requirements
What must it do?

• Inherit meal types from an abstract superclass

30
Non-functional requirements
How should it do?

• Legal
• Performance
• Support
• Security

• Compatible with Windows, Mac, Linux, iOS, and Android

31
FURPS Requirements
⬢ Functionality => Capability, Reusability, Security
⬢ Usability => Human Factors, Consistency, Documentation
⬢ Reliability => Availability, Failure Rate & Duration, Predictability
⬢ Performance => Speed, Efficiency, Scalability
⬢ Supportability => Extensibility, Configurability, Testability

32
Let’s challenge your understanding
• Please think and write down the requirements of any systems you can think
about.

• 3 Functional requirements (The system must do…)


• 3 Non-Functional requirements (The system should be…)

33
Use Cases
⬢ What the actor must do or how they accomplish a particular goal?
⬢ For this we are going to capture that is use cases
⬢ 3 things for use cases:
⬢ Title -> describes a goal
⬢ Person -> who will achieve that goal
⬢ Scenario -> the steps to complete the goal

34
Use Cases

Edit Content

Admin
Add Comment

Read the blog

Blogger
35
Let’s challenge your understanding
• Write two use cases:
1. Title
2. Primary actor
3. Scenario

36
Abstract Class
⬢ Exists for other classes to inherit
⬢ Cannot be instantiated
⬢ Contains at least one abstract method

37
Abstract Class (Cont’d )
Spaceship
Abstract class Spaceship { …
setShield()
move()

StarFighter Shuttle WarpCruiser Final class WarpRuiser { …

move() move() move() “concrete “ class

fireMissle() dropCargo()
38
Interface
⬢ List of methods for a class to implement.
⬢ It doesn’t contain any actual behaivour.

39
Interface (Cont’d )
<<interface>>

Movable
move()

Spaceship Asteroid
setshield() move()
move() detectCollision

Shuttle
move()
dropCargo()
40
Aggregation
Fleet


1

0..*
Spaceship

41
Composition
Spaceship


1 1

1..* 0..*
Engine Shield Weapon
… … …

42
Let’s challenge your understanding
• Inheritance

• Interfaces

• Aggregation

• Composition

43
THANKS!
You can find me at:
⬢ https://www.facebook.com/mgsein123
⬢ aunghein116688@gmail.com
⬢ 095120779

44

You might also like