Object based programming
Download
1 / 36

Object-based Programming - PowerPoint PPT Presentation


  • 67 Views
  • Uploaded on

Object-based Programming. Intuitive explanation Two concrete examples Calculators addition BMI Programming Environment. Computer Vs Program Model. CPU. Program. ???. Compiler. Structuring in Scripts. Speech. Introduction. Body. Conclusion. Paragraph 1. Paragraph 2.

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 ' Object-based Programming' - cameran-barrett


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
Object based programming
Object-based Programming

  • Intuitive explanation

  • Two concrete examples

  • Calculators

    • addition

    • BMI

  • Programming Environment


Computer vs program model
Computer Vs Program Model

CPU

Program

???

Compiler


Structuring in scripts
Structuring in Scripts

Speech

Introduction

Body

Conclusion

Paragraph 1

Paragraph 2

Script components are abstract

Sentence 1

Sentence 2

So are program components


Program components physical objects

Natural Objects

Manufactured Objects

Program Components ~ Physical Objects

~ Program

Objects


Program objects manufactured objects

operations

manufactured by

accelerate

perform

brake

add

instance of

Class

subtract

execute

Program

Object

invoke

methods

call

Program Objects ~ Manufactured Objects

Program

Object


Classification through factories
Classification through Factories

manufactured by

manufactured by


Classification through classes
Classification through Classes

instance of

ASquareCalculator

ASquareCalculator

Instance

ASquareCalculator

Instance

instance of

ABMICalculator

ABMICalculator

Instance

ABMICalculator

Instance


A simple class
A Simple Class

publicclass ASquareCalculator

{

publicint square(int x)

{

return x*x;

}

}


2 2 nature of a function
2.2 Nature of a Function

Domain/Parameter

Values

Range/Result

Values

1

1

2

4

3

9

...

...

Mapping


Mathematics vs java function syntax

Mathematics

square: I  I

square(x) = x2

Java

publicint square(int x)

{

return x*x;

}

Mathematics Vs Java Function Syntax

Inspiration for Functional Languages





Abmicalculator

weight

(kg)

Body Mass Index

height2

(metres)

publicclass ASquareCalculator

{

publicint square(int x)

{

return x*x;

}

}

ABMICalculator

public class ABMICalculator {

public int calculateBMI (int weight, int height) {

return weight/(height*height);

}

}


Bare bone environment
Bare Bone Environment

  • MS-DOS Prompt (Command Interpreter)

  • Notepad (editor)

  • Jvc (J++ compiler)

  • Jview (J++ interpreter)

  • ObjectEditor




Using notepad to edit autoexec
Using Notepad to Edit Autoexec

notepad C:\autoexec.bat


Setting path and classpath
Setting Path and Classpath

  • Path

    • List of Command Directories

    • Must have Jvc and Jview Directories

  • Class Path

    • List of Library Directories, Jar Files, Zip Files

    • Add oe.jar, shapes.jar, swingall,jar


Setting path and classpath1

previous classpath

current directory

jar files

Reboot!

Setting Path and Classpath

SET PATH=%PATH%;C:"\Program Files\Microsoft Visual Studio\VJ98"

SET CLASSPATH=%CLASSPATH%;.;D:\Java\lib\oe.jar;D:\Java\lib\shapes.jar;D:\Java\lib\swingall.jar

may be zipped






Program development process

creates

ABMICalculator Source Code

ABMICalculator Instance

reads

Java Compiler

calculateBMI

creates

calls

instantiates

ABMICalculator Object (Byte) Code

ObjectEditor

main

calls

Program Development Process

Text Editor

Java Interpreter


Anatomy of a class

Method

Header

Method

Body

Class

Header

Class

Body

Parameter

Type

Parameter

Name

Access

Specifier

Return

Type

Return

Statement

Return

Expression

Anatomy of a Class

1.

public class ABMICalculator

2.

{

public double calculate BMI(double weight, double height

3.

4.

{

return

weight/(height*height);

5.

}

6.

7.

}


Formal vs actual parameters

Invoke method

variables

memory

weight

0

height

0

1.77

Formal Vs Actual Parameters

publicdouble calculateBMI(double weight, double height)

{

return weight / (height*height);

}

formal

parameters

assigned

actual

parameters

74


Errors

Syntax Error

Semantics Error

Logic Error

Access Error

Errors

class ABMICalculator {

double calculateBMI(double weight, double height)

{

return (height*heigh)/weight

}






Jvc error reporting

Line no

char. no

JVC Error Reporting

ABMICalculator.java (3,3) : error J0232: Expected '{' or ';'

ABMICalculator.java (3,3) : error J0021: Expected type specifier

ABMICalculator.java (3,3) : error J0019: Expected identifier

ABMICalculator.java (5,1) : error J0020: Expected 'class' or

'identifier'


Case conventions
Case Conventions

  • Start variable name with lowercase letter (weight).

  • Start class name with uppercase letter (ABMICalculator)

  • Start each new word with upper case letter (ASquareCalculator)



Identifiers
Identifiers

  • Reserved Words/KeyWords

    • double, class, int, public, return

    • boldface

  • Programmer-defined Names

    • Variable Names

    • Class Names

  • First character is letter

  • Other characters:letter, digit, _

    • calculateBMI2

    • calculate_BMI


ad