0% found this document useful (0 votes)
6 views

Lecture 2

The document introduces basic object-oriented concepts. It discusses what objects and classes are, how objects are constructed from classes, and how problem solving is approached in object-oriented languages through interaction between objects.

Uploaded by

eyepencil7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Lecture 2

The document introduces basic object-oriented concepts. It discusses what objects and classes are, how objects are constructed from classes, and how problem solving is approached in object-oriented languages through interaction between objects.

Uploaded by

eyepencil7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Basic Object- Oriented Concepts

1
OUTLINE

 Object-Oriented Paradigm
 What is an Object?
 What is a Class?
 Constructing Objects from a class
 Problem Solving in OO languages
 More OO Concepts
 Strength of Object-Oriented
Paradigm

2
Object-Oriented
Paradigm
 To truly understand Java, we need to understand the paradigm on which it is built
on: the Object-Oriented Paradigm (OOP).

 OOP is a model whereby a problem domain is modeled into objects, so that


problem solving is by interaction among objects.

 OOP is a more natural model compared to other models since OOP’s approach is
exactly the way humans view problem solving.

 We take a closer look at the main ingredients of the model: Objects and Classes.

3
What is an Object?
 An object is an individual, identifiable entity, either
real or abstract, that has a well-defined boundary.
 An object has two main properties, namely:
• State: each object has attributes, whose values
represent its state.
• Behavior, each object has a set of behavior.

 Example of an object: You, the student following this


Lecture, are an object.
• Your attributes include your name, your GPA, your
major, etc.
• You also have a set of behavior, including
attending lectures, solving home works, telling
someone your GPA, sleeping, etc.
4
… What is an Object?
 Other examples of objects are:
• The instructor delivering this lecture.
• This room.
• This lecture.
• This University.
• CMP204.
• Your Bank Account

 Try to list some of the attributes and set of behavior for


each of the above objects.
 Also look around you and identify the objects you can see
or imagine.
5
What is a Class?
 A class is a general specification of attributes and behavior for a set of objects.
 Each object is an instance of a class. It shares the behavior of the class, but has
specific values for the attributes.
 Thus, a class can be viewed as an abstract specification, while an object is a concrete
instance of that specification.

 An example of a class is Student, an abstract entity that has attributes and a set of
behavior.
 However, unless we have an actual student, we cannot say what the ID number is
or what the major is.

6
What is a Class?
(cont’d)
 The following table shows further examples of
classes and their instances:
Classes Instances of (or Objects)

Instructor Mustapha Aminu

University UDU
Course CMP204

Bank Account Ahmad’s Bank Account

7
Constructing Objects from a Class

 Our main task is to design and implement classes to be used in


creating objects.
 This involves defining the variables, methods and constructors.
 To create an object from a class, we use the new operator, a
constructor, and supply construction parameters (if any).
 Example, we create an object from the Student class as follows:
Student thisStudent = new Student(993546,
“Suhaim Adil”, 3.5);

8
… Constructing Objects from a Class
Student thisStudent =
new Student(993546, “Suhaim Adil”,

3.5);
 The relationship between the reference variable, thisStudent,
and the object created is shown by the following figure:

9
Problem Solving in OO languages
 In the real world, problems are solved by interaction among
objects.
 If you have a problem with your car, you take it to a mechanic for
repair.

 Similarly, in OO programming languages, problems


are solved by interaction among objects.
 Objects interact by sending messages among themselves.

10
Problem Solving in OO languages

Student thisStudent =new Student(993546,


“SuhaimAdil”, 3.5);
 Messages are sent using the following general syntax:
referenceVariable.methodName

To know the GPA of the student object we created, a message is sent as follows:

double gpa = thisStudent.getGPA();


 We have been sending messages to the System.out object in
previous examples.
System.out.println(“Salaaam Shabaab”);

11
Strength of the OO Paradigm

 We conclude this introduction to OOP by summarizing its


main advantages:
 It allows the production of software which is easier to
understand and maintain.
 It provides a clear mapping between objects of the problem
domain
(real world objects) and objects of the model.
 It supports code reuse and reduces redundancy.
 It allows "off the shelf” code libraries to be reused..
 It allows the production of reliable (secure) software..

12

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy