The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.

INTRODUCTION TO OOP & PROGRAMMING BASICS (PART 1)

Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by noorfadzilah.arifin, 2021-12-07 14:30:48

INTRODUCTION TO OOP & PROGRAMMING BASICS (PART 1)

INTRODUCTION TO OOP & PROGRAMMING BASICS (PART 1)

Keywords: OOP,PROGRAMMING BASIC,INTRO TO OOP

OBJECT
ORIENTED
PROGRAMMING

CHAPTER 1

Introduction to Object Oriented Programming (OOP)
& Programming Basics

Learning Outcomes

At the end of the chapter students
should be able to:

1. Understand the objects.
2. Describe the OOP characteristics.
3. Differentiate structured language vs

and OOP language.
4. Understand array of primitives data

types

CONTENT OF THIS CHAPTER

PART 1. INTRODUCTION TO OOP (OOP)

1) Introduction to object
2) Elements of an object: attributes and behaviours
3) Characteristics of OOP: abstraction, encapsulation, inheritance, and polymorphism

PART 2. PROGRAMMING BASICS 4) Control structures
5) Array of primitives data types
1) Structured language vs OOP language. 6) Packages
2) Introduction to Java Application.
3) Data types – primitives and references.

PART 1. INTRODUCTION TO OOP

INTRODUCTION TO OBJECT

DEFINITION OF OBJECT

§ Object-oriented programs use objects. EXAMPLE
§ An object is a thing, both tangible and intangible. Vehicle, Employee, Clock
Account, Loan, Time, Date
TYPE
Tangible (can be seen & touched)

Intangible (conceptual)

§ To create an object inside the computer program, we must provide a definition for objects—
how they behave and what kinds of information they maintain —called a class.

§ An object is an instance of class.

ELEMENTS OF OBJECT

For example, you want to write a program for video rental. The objects involved are video and
customer. This segment uses VIDEO as the object. Elements of object are:
1. Attribute (data related to the object)

For the video object, the data or attributes might be movie name, production name and number of
copies in stock

2. Behaviour (operations on a video object)

For example, checking the name of movie, reducing the number of copies in stock by one after a copy

ELEMENTS OF OBJECT

What are the attributes and behaviour of this object?

ELEMENTS OF OBJECT

Attributes What are the attributes and behaviour of this object?

§ Plat Number Behaviour
§ Model
§ Color § Move forward
§ Engine Size § Reverse
§ Stop

OOP CHARACTERISTICS (AEIP)

ABSTRACTION ENCAPSULATION/
DATA HIDING

INHERITANCE POLYMORPHISM

ABSTRACTION

Definition
Process of taking away or removing characteristics from an object in order to reduce it to a set
of essential characteristics (attributes and behavior of an object).

q Abstraction in Java allows the user to hide non essential details relevant to user in order to
reduce complexity and increase efficiency.

q It allows only to show the essential features of the object to the end user.
q A user’s code should not access the implementation details of the class used.
q In other sense we can say it deals with the outside view of an object (interface).

ABSTRACTION

Analogy
§ When you drive a car, you don’t have to know how the gasoline and air are mixed and

ignited.
§ Instead you only have to know how to use the controls.

ENCAPSULATION

Definition
Binding or wrapping-up of data and associated methods into a single unit (class)

q The mechanism that binds together code and the data it manipulates and keeps both safe
from the outside interference and misuse.

q Access to the code & data inside the wrapper is tightly controlled through a well-defined
interface.

q Also known as data hiding.
q Only object’s methods can modify information in the object.

ENCAPSULATION

EXAMPLE

INHERITANCE

Definition
Inheritance is a mechanism in OOP to design two or more entities that are different but share
many common features.

q The capability of a class to use the properties and methods of another class while adding its own
functionality.

– The new class will have the features of the old class.
- “is-a” relationship
- Concept of reusability

q Features common to all classes are defined in the superclass (ancestor).
q The classes that inherit common features from the superclass are called subclasses (descendant).

Subclasses INHERITANCE Superclass

Account

EXAMPLE 1

Current Savings

INHERITANCE

Superclass Student

EXAMPLE 2 Graduate Undergraduate
Masters Doctoral
Law Commuting Resident

Subclasses

POLYMORPHISM

Definition
The capability of an action or method to do different things based on the object that it is acting
upon

q From the Greek, meaning “many forms”.
q A feature that allows one interface to be used fora general class of actions.
q “one interface, multiple methods”
q Can be applied in the overloaded methods (a few methods that have the same name but with

different parameters).
q The same word or phrase can mean different things in different contexts
q Analogy: In English, bank can mean side of a river or a place to put money

POLYMORPHISM

POLYMORPHISM

EXAMPLE 1

POLYMORPHISM

EXAMPLE 2 Class : Rectangle
Variables : length, width, height
Methods : ….

displayShape(char simbol)
displayShape(int a)

This class has two methods with the same name but

with different type of parameters


Click to View FlipBook Version