You are on page 1of 38

Lecture 1

Dr. Rami YARED


Outline
• Procedural approach vs. Object-Oriented
approach
• Basic Object Oriented concepts
• Classes and Objects
• Course Syllabus
• Summary

2
Problem Description

• “ …customers are allowed to have different


types of bank accounts, deposit money,
withdraw money and transfer money between
accounts”

3
Procedural Approach
bool MakeDeposit(int accountNum,float amount);
float Withdraw(int accountNum,float amount);

struct Account {
char *name;
int accountNum;
float balance;
char accountType;
};

4
Procedural Approach
• Focus is on procedures
• More difficult to modify
• Hard to manage complexity

5
Procedural vs. Object-Oriented

• Procedural • Object Oriented

Withdraw, deposit, transfer Customer, money, account

6
Procedural vs. Object-Oriented Programming
• The unit in procedural programming is function, and
unit in object-oriented programming is class
• Procedural programming concentrates on creating
functions, while object-oriented programming starts
from isolating the classes, and then look for the
methods inside them.
• Procedural programming separates the data of the
program from the operations that manipulate the data,
while object-oriented programming focus on both of
them

7
Outline
• Procedural approach vs. Object-Oriented
approach
• Basic Object Oriented concepts
• Classes and Objects
• Course Syllabus
• Summary

8
Concept of Class and Object
• “Class” refers to a blueprint. It defines the variables
and methods the objects support

• “Object” is an instance of a class. Each object has a


class which defines its data and behavior

9
Outline
• Procedural approach vs. Object-Oriented
approach
• Basic Object Oriented concepts
• Classes and Objects
• Course Syllabus
• Summary

10
Objects
• An object has:
– state - descriptive characteristics
– behaviors - what it can do (or what can be done to it)
• The state of a bank account includes its account
number and its current balance
• The behaviors associated with a bank account include
the ability to make deposits and withdrawals
• Note that the behavior of an object might change its
state

11
Classes
• An object is defined by a class
• A class is the blueprint of an object
• The class uses methods to define the behaviors of
the object
• A class represents a concept, and an object
represents the embodiment of that concept
• Multiple objects can be created from the same
class
12
Objects and Classes
A class An object
(the concept) (the realization)

Bank Alice’s Bank Account


Account Balance: $5,257

Bill’s Bank Account


Balance: $1,245,069
Multiple objects
from the same class
Charles’s Bank
Account
Balance: $16,833

13
Class
 What this basically means is that we provide
a blueprint, or a design of an object.

 This blueprint is valid whether we have one


or one thousand such objects.

14
Methods

 We must not only deal with data types, but


we must also deal with methods.
 A method is an operation which can modify
an objects behavior. In other words, it is
something that will change an object by
manipulating its variables.

15
Methods

This means that when we take a real world


object, in this case a bank account, when we
want to model it using computational objects,
we not only look at the data structure that it
consists of, but also all possible operations
that we might want to perform on that data.
16
Example: Class Point

OOP 17
Class Point
Class Point has:
two fields:
xCoord
yCoord
one constructor
Point(int, int)
one method
void move(int, int)

OOP 18
Programming with Points

OOP 19
Variables Declaration
• Field Declaration
– a type name followed by the field name, and optionally an
initialization clause
– primitive data type vs. Object reference
• boolean, char, byte, short, int, long, float, double
– field declarations can be preceded by different modifiers
• access modifiers
• static
• final

20
Mapping the world to software

• Objects in the problem domain are mapped to


objects in software

21
Object Oriented
• Data and operations are grouped together

Account Interface:
Withdraw
Deposit
Set of available operations
Transfer

22
Data Encapsulation
class Account {
public:
float withdraw();
void deposit(float amount);
private:
float balance;
);

23
Objects and Classes

• A class captures the common properties


of the objects instantiated from it
• A class characterizes the common
behavior of all the objects that are its
instances

24
Objects and Classes
Operations
Class BankAccount
MakeDesposit
Balance
Interest Transfer
Owner WithDraw
Account_number
GetBalance

Balance 500 Balance 10,000


Interest Interest
Owner Owner
Account_number Account_number

25
Objects as instances of Classes

• The world conceptually consists of objects


• Many objects can be said to be of the same type
or class
– My bank account, your bank account, Bill Gates’ bank
account …
• We call the object type a class

26
Instantiation
• An Object is instantiated from a Class

BankAccount myAccount;
myAccount = new BankAccount;

27
Object

• Object
– Own copy of data
– Active in running program
– Occupies memory
– Has the set of operations given in
the class

28
Summary
• What is Object Oriented Programming?
Object-oriented programming is a method of
implementation in which programs are
organized as cooperative collections of
objects, each of which represents an instance
of some class, and whose classes are all
members of one or more hierarchy of classes
united via inheritance relationships

29
Outline
• Procedural approach vs. Object-Oriented
approach
• Basic Object Oriented concepts
• Classes and Objects
• Course Syllabus
• Summary

30
Syllabus

 Introduction to Object Oriented Programming

 Class, object, methods, hierarchies, Messages,

Instances, Initialization.

 Abstract classes, abstract methods, Interfaces.

31
Syllabus

 Encapsulation and Visibility

 Inheritance & polymorphism

 Method overriding

 Generics

Implementation Strategies.

32
Outline
• Procedural approach vs. Object-Oriented
approach
• Basic Object Oriented concepts
• Classes and Objects
• Course Syllabus
• Summary

33
Object Oriented Programming
 Programming in an object oriented language
is more than just learning new functions,
syntax, etc. OOP is more than learning a new
language; it requires a new way of thinking.
 The idea is to not mainly concentrate on the
cornerstones of procedural languages - data
structures and algorithms - but instead think
in terms of objects.

34
OOP Languages

 Java is a platform-independent language


developed by Sun Microsystems.
 C# is a relatively new language developed by
Microsoft.
 C# is one language that forms part of
Microsoft's .NET platform.

35
.NET
What Is Microsoft dot NET?
 Microsoft .NET is software that connects
information, people, systems, and devices. It
spans clients, servers, and developer tools, and
consists of:
 The .NET Framework programming model that
enables developers to build Web-based
applications, smart client applications, and XML
Web services applications which expose their
functionality programmatically over a network
using standard protocols such as HTTP.

36
.NET
 Developer tools, such as Microsoft Visual Studio.NET,
which provide a rapid application integrated
development environment for programming with the
.NET Framework.

 A set of servers, including Microsoft Windows 2000,


Microsoft SQL Server that integrates, runs, operates, and
manages XML Web services and applications.

 Client software, such as Windows XP, and Microsoft


Office, that helps developers deliver a deep user
experience across a family of devices and existing
products.

37
END

You might also like