Object%20Orientation:%20Objects%20and%20Classes - PowerPoint PPT Presentation

About This Presentation
Title:

Object%20Orientation:%20Objects%20and%20Classes

Description:

How tall is he? What is his QCA? Object vs. Class ... All the instances will be unique but based on the same set of blue prints. Convention ... – PowerPoint PPT presentation

Number of Views:114
Avg rating:3.0/5.0
Slides: 29
Provided by: davemcp
Category:

less

Transcript and Presenter's Notes

Title: Object%20Orientation:%20Objects%20and%20Classes


1
Chapter 1
  • Object Orientation Objects and Classes

2
What is Programming?
  • Phases of Programming
  • Design
  • Implementation
  • Testing
  • Repeating

3
Polyas Four Step Process
  • Four steps to any problem solving activity
  • Understand the problem
  • Devise a solution
  • Test the solution
  • Rework the solution

4
Solving Computer Problems
  • Need a tool to solve the problem
  • Use a computer language to do this
  • Different levels of languages
  • Machine Language
  • Assembly Language
  • High Level Language
  • Some are talking about 4th Level Languages

5
Algorithms
  • What is an algorithm?
  • A finite set of steps that specify a sequence of
    operations to be carried out in order to solve a
    specific problem.

6
Properties of Algorithms
  1. Finiteness
  2. Absence of Ambiguity
  3. Definition of Sequence
  4. Feasibility
  5. Input
  6. Output

7
What is a Computer?
  • Made up of many independent parts all working
    together
  • Memory Unit
  • Arithmetic/Logic Unit (ALU)
  • Control Unit
  • Input Devices
  • Output Devices
  • Auxiliary Storage Devices

8
Memory Unit
  • Can be thought of to look like a giant grid
  • Each square in the grid is a memory location
  • We can access each location in the grid, if we
    choose to

9
Objects and Classes
  • When you create a program using an
    object-oriented language, you are
  • Creating a model of the problem
  • The model is built up from objects in the problem
    domain
  • Those objects must be represented in your program

10
Object vs. Class
  • The difference between an object and a class is
    subtle.
  • We will examine a student class.
  • If we wanted to identify one particular student,
    we would need to ask some questions
  • What color is his hair?
  • How tall is he?
  • What is his QCA?

11
Object vs. Class
  • In order to answer these questions we need to
    know what student we are talking about.
  • This particular student object is an instance of
    the Student class.
  • In this example, the Student is a class and the
    instance of the Student is a student object.

12
Object vs. Class
  • A class is a generic example a blue print if you
    will.
  • An object is one particular instance of a class.
  • From one set of blue prints we can make multiple
    instances.
  • All the instances will be unique but based on the
    same set of blue prints

13
Convention
  • Names of Classes start with a Capital Letters.
  • Names of objects start with lower case letters.
  • This case convention is fairly well followed
    throughout the Java programming community.

14
BlueJ Example
  • Lets take a look at an example in BlueJ.
  • All the examples in the notes assume that you
    have BlueJ installed in C\BlueJ
  • The Shape Example

15
Calling Methods
  • When we right clicked on a object on the
    workbench in BlueJ, we got a popup menu with a
    bunch of function names listed.
  • In Java, these functions are called methods
  • When we chose one of these methods for the object
    to perform, we called or invoked the method
  • When the method requires information from the
    programmer, the method is said to have a parameter

16
Method Signatures
  • A method signature provides information about the
    method.
  • It tells us the name of the method
  • Whether or not the method requires a parameter
  • What type of information is returned from the
    method

17
Data Types
  • The values a parameter can take
  • Examples
  • int whole numbers
  • String a section of text
  • Pitfall forgetting the double quotes around a
    string. Youll get a message like Error
    undefined variable

18
Java Data Types
  • Java supports two kinds of data types
  • Built-in data types
  • Object data types
  • Built-in data types are types like integers,
    characters, etc.
  • Object data types are like Strings, Arrays, etc.

19
Built-in Types
  • Java has a limited amount of built-in types.
  • We will be most concerned with
  • int - For integer numbers
  • double - For floating point numbers
  • boolean - For true/false values
  • char For character data

20
Object Types
  • There are many objects types.
  • Some are provided for us
  • The others we will create ourselves.
  • There are some object types we can use with no
    extra work
  • String For representing strings of characters
  • System For some basic output

21
State
  • All of the attributes that define an object is
    referred to as the objects state
  • Java refers to the individual attributes as
    fields

22
Multiple Instances
  • Object-oriented programming (OOP) allows for
    creating more than one object from the same
    class.
  • The internal state of the object allows the
    computer to tell the different objects apart.

23
What is an object?
  • All objects of the same class have the same
    fields (and methods).
  • The values stored in those fields can be
    different.
  • Simply being an object of a given class
    guarantees that the objects will have the same
    fields

24
Object Interaction
  • Objects do not normally operate by themselves
  • Objects can create other objects and invoke those
    objects methods
  • Most Java programs have objects that will do just
    this
  • Question How do we do this?

25
Source Code
  • Like most programming languages, Java is written
    using plain text files or source code files
  • The source code tells the program how objects are
    created and how the objects will interact
  • After a source code file is written, it must be
    compiled so that the Java Virtual Machine (JVM)
    can interpret it

26
Return Values
  • Some methods not only take parameters, but give
    something back to you.
  • These methods are said to have a return value
  • You can tell this in the signature
  • String getName()
  • This methods returns a String
  • void moveRight()
  • This method returns void (nothing)

27
Homework
  • 1.2, 1.5, 1.6, 1.9, 1.11, 1.18, 1.26

28
Quiz
  • Explain the difference between an object and a
    class.
Write a Comment
User Comments (0)
About PowerShow.com