introduction to object oriented programming oop n.
Download
Skip this Video
Download Presentation
Introduction to Object-Oriented Programming (OOP)

Loading in 2 Seconds...

play fullscreen
1 / 19

Introduction to Object-Oriented Programming (OOP) - PowerPoint PPT Presentation


  • 138 Views
  • Uploaded on

Introduction to Object-Oriented Programming (OOP). Part 1. Objectives. Name the basic components of object-oriented programming. Differentiate classes and objects. Define class methods and attributes. Draw UML diagrams for classes and objects. OOP is about classes and objects.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Introduction to Object-Oriented Programming (OOP)' - haroun


Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
objectives
Objectives
  • Name the basic components of object-oriented programming.
  • Differentiate classes and objects.
  • Define class methods and attributes.
  • Draw UML diagrams for classes and objects.

SE-1010Dr. Mark L. Hornick

oop is about classes and objects
OOP is about classes and objects
  • These are two very basic concepts in OOP
  • …but what are they?

Java is an OOP language

SE-1010Dr. Mark L. Hornick

slide4
Alan Kay, who was instrumental in the creation of the first Apple Macintosh, was also the creator of the first OOP language called Smalltalk.

He defined OOP as follows:

SE-1010Dr. Mark L. Hornick

1 everything is an object
1. Everything is an object

An object is a thing, both tangible…

Objects often represent physical entities

SE-1010Dr. Mark L. Hornick

1 everything is an object1
1. Everything is an object

… and intangible, like

  • Time
  • Date
  • Bank Account
  • Grocery List

Or, objects can just represent ideas or concepts

SE-1010Dr. Mark L. Hornick

2 every object has a type of class
2. Every object has a type of class
  • Classes are more difficult to describe:
  • A Class is an abstraction (a blueprint, or template) that defines the attributes and behavior of Objects that belong to the Class
  • Objects assume the characteristics of a class
  • We say an Object is an Instance of a Class, kind of how a cake is an instance of a recipe for a cake.
  • We can also say that a Class Instance is an Object.

SE-1010Dr. Mark L. Hornick

3 an object is comprised of attributes and methods defined by its class
3. An object is comprised of attributes and methods defined by its class
  • attributes are data that define an object’s properties
    • Each object has its own variables where it can store the values of its attributes
  • methods are behaviors
    • Methods are executed when an object receives a message to execute it.
    • Methods often manipulate attributes

Alan Kay’s OOP definitions, continued

SE-1010Dr. Mark L. Hornick

exercise 1
Exercise 1

List some attributes and behaviors for a BankAccountclass

  • Pretend it’s used within the software of an ATM machine (or within a personal finance app)
    • What does it represent?
    • What can it do?
    • What are its properties?

SE-1010Dr. Mark L. Hornick

exercise 2
Exercise 2
  • List some attributes and behaviors for a Printer class
    • What does a printer do?
    • What properties does it have?

SE-1010Dr. Mark L. Hornick

unified modeling language uml
Unified Modeling Language (UML)

A notation for objects and classes. Can be applied to any OOP language (not just Java).

UML class diagram

SE-1010Dr. Mark L. Hornick

4 object oriented programs use objects
4. Object-oriented programs use objects
  • An object-oriented program is a bunch of objects telling each other what to do by sending and receiving messages to and from one another
    • A message instructs an object to execute one of it’s methods

Alan Kay’s OOP definitions, continued

SE-1010Dr. Mark L. Hornick

the relationship between messages and methods
The Relationship between Messages and Methods
  • To instruct an object to do something, we “send a message” to it.
  • You can send a message only to the objects that understand the message you send to them.
  • In Java (and other OO languages like C++, C#, or VB), messages are sent by calling a methoddefined within the object’s class
    • we also say “execute a method” or “invoke a method”
    • and sometimes we use “function” instead of “method”

We don’t usually send messages to classes, although there are exceptions we’ll learn about later

SE-1010Dr. Mark L. Hornick

uml again
UML again

A UML Sequence Diagram illustrating messages being sent to an instance of a class.

The object’s name hp1

The object’s class Printer

The message purge

hp1:Printer

purge

print(“report.txt”)

SE-1010Dr. Mark L. Hornick

passing values in messages
Passing values in messages

A value we pass to an object when sending a message is called an argument of the message.

The object’s name hp1

The object’s class Printer

The message print with theargument “report.txt”

hp1:Printer

print(“report.txt”)

SE-1010Dr. Mark L. Hornick

two way communication
Two-way communication

Many times, a method will return a message back to the sender.

The object’s name

The object’s class

No argument

The method

hp11:Plotter

getPaperLevel()

27

The return value

SE-1010Dr. Mark L. Hornick

many arguments can be sent in an originating message but only one return value can be sent back
Many arguments can be sent in an originating message, but only one return value can be sent back

The object’s name

The object’s class

Two arguments

The method

hp11:Plotter

setFont(“Arial”, “italic”)

“ok”

The return value

SE-1010Dr. Mark L. Hornick

object oriented programming
Object-oriented programming
  • The object-oriented (OO) approach provides tools for the programmer to represent elements in the problem, or domain space
  • Elements in the problem space, and their representation in the solution space, are referred to as “objects”
  • OO allows a programmer to define a class (the type of an object) to fit the problem, rather than being forced into existing data types representing units of storage in a machine
  • Object-orientation allows you to describe the problem in terms of the problem, rather than in terms of the solution

SE-1010Dr. Mark L. Hornick