Object Oriented Programming in Java _lecture 1

18
Object Oriented Programming Chapter 1: Introduction to OOP Prepared by: Mahmoud Rafeek Alfarra 2016

Transcript of Object Oriented Programming in Java _lecture 1

Page 1: Object Oriented Programming in Java _lecture 1

Object Oriented Programming

Chapter 1: Introduction to OOP

Prepared by: Mahmoud Rafeek Alfarra

2016

Page 2: Object Oriented Programming in Java _lecture 1

Salamo 3likom!

I am Mahmoud R. AlfarraI am here because I love to give knowledge.

Note: I have prepared this material Based on (Liang: “Introduction to Programming using Java”, 10’th edition, 2015)

Page 3: Object Oriented Programming in Java _lecture 1

Outlines◉What is Object-Oriented Programming ?

◉Procedural vs. Object-Oriented Programming

◉OO Programming Concepts

◉Concept of Objects and classes

◉UML Class Diagram

◉Visibility Modifiers and Accessor Methods

◉Full Example

Page 4: Object Oriented Programming in Java _lecture 1

عن عمر بن الخطاب رضي الله عنه ، قال : سمعت رسول الله صلى الله

: عليه وسلم يقولإنما األعمال بالنيّات ، وإنما لكل )

امريء ما نوى، فمن كانت هجرته إلى الله ورسوله ، فهجرته إلى الله ورسوله

، ومن كانت هجرته لدنيا يصيبها ، أو امرأة ينكحها ، فهجرته إلى ما هاجر إليه

) رواه البخاري ومسلم في صحيحهما

الحياة ال تحل���������و وال تس��تقيم وال تس��هل إال بطاع���ة الل���ه تعال���ى

والتأدب باآلداب واألخالق الت�����ي وردت

لنا في شريعته.

عيشها ،،، صح

Page 5: Object Oriented Programming in Java _lecture 1

Lecture Let’s start with the first set of concepts1

Page 6: Object Oriented Programming in Java _lecture 1

Our Life is a set of Objects

Page 7: Object Oriented Programming in Java _lecture 1

o To have a fine definition of OOP, Please note what you are showing in your class room now?

What is OOP?

ChairsTables Teacher

PCs..

# of legs Type of material

Color...

Page 8: Object Oriented Programming in Java _lecture 1

o Object-oriented programming (OOP) involves programming using objects.

o An object represents an entity in the real world that can be distinctly identified.

o For example, a student, a desk, a circle, a button, and even a loan can all be viewed as objects.

o An object has a unique identity, state, and behaviors.

What is OOP?

Page 9: Object Oriented Programming in Java _lecture 1

o The unit in procedural programming is function.

o Procedural programming concentrates on creating functions.

o Procedural programming separates the data of the program from the operations that manipulate the data.

Procedural vs. Object-Oriented Programming

o The unit in object-oriented programming is class.

o Object-oriented programming starts from isolating the classes, and then look for the methods inside them.

o Object-oriented programming focus on both of them.

Page 10: Object Oriented Programming in Java _lecture 1

Concepts of Object-Oriented Programming

Page 11: Object Oriented Programming in Java _lecture 1

o Abstraction is simplifying complex reality by modeling classes appropriate to the problem.

o Abstraction is mechanism to show only relevant data to the user.

o i.e: The client cares about what functionality a car offers, not about how that functionality is implemented.

Abstraction

Page 12: Object Oriented Programming in Java _lecture 1

o Encapsulation allows the programmer to group data and the methods that operate on them together in one place, and to hide details from the user.

Encapsulation

withDraw

Deposit

Transfer

Print

AccountNo

AccountValue

Name Address

Change Address

withDraw any value

Page 13: Object Oriented Programming in Java _lecture 1

o Encapsulation protects the integrity of an object's data.o Protects an object from unwanted access by clients. A bank app forbids a client to change an Account's balance.o Allows you to change the class implementation.o Allows you to constrain objects' state

Benefits of encapsulation

Page 14: Object Oriented Programming in Java _lecture 1

Abstraction Vs encapsulation

Page 15: Object Oriented Programming in Java _lecture 1

o Inheritance: The ability of a new class to be created from an existing class by extending it.

Inheritance

Student

Colleague

BCs Diploma

School

Primary Secondary

Page 16: Object Oriented Programming in Java _lecture 1

o Polymorphism enables us to "program in the general" rather than "program in the specific.

Polymorphism

Page 17: Object Oriented Programming in Java _lecture 1

PracticesGroup 1Compare between the main concepts of OOP.

Group 2Detect 5 objects from our classroom

Group 3Diffrenciate between abstraction and encabsulation.

Group 4Diffrenciate between procedural and Object-Oriented Programming

Group 5Give us 3 examples for inheritance from your life.

Group 6Summerize the first lecture using 1 complext chart.

Page 18: Object Oriented Programming in Java _lecture 1

THANKS!

Any questions?You can find me at:

Fb/mahmoudRAlfarraStaff.cst.ps/mfarraYoutube.com/mralfarra1@mralfarra