Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why...

23
Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement procedural? What is the point? Why bother? Is it here to stay or gone tomorrow?

Transcript of Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why...

Page 1: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

Object-Oriented Software

How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement procedural? What is the point? Why bother? Is it here to stay or gone tomorrow?

Page 2: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

An Object-Oriented Program (OOP)

Is composed of a collection of individual units called objects which package data and functionality together, rather than of lists of instructions which act on external data.

Each object is capable of: – receiving calls from other objects to run methods, – executing its own methods, and – sending calls to run methods in other objects.

Page 3: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

What is an Object in OOP?

An object is a software construct that bundles together data (state) and function (behavior) which, taken together, represent an abstraction of a thing, event, service, etc.

An object is an instance of a class. A class models a group of things, events, services, etc.; an object models a particular member of that group.

Page 4: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

What is in a Class (or Object)?

A class contains attributes and methods. Attributes describe state; methods perform actions. Attributes may be Java primitives, or objects

(strings, dates, arrays, other objects, etc). Methods may be instance methods, which only work

when the class is instantiated as an object, or static methods, which may be used independently of class instantiation.

Page 5: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

Objected-Oriented vs. Procedural

Both types of language use structured programming logic; the logical architecture of a Java method will resemble that of an ILE RPG procedure.

The main difference is macro-architecture:– With OO, logic and data reside together in objects– OO design focuses on object relationships and

interactions rather than code block relationships

Page 6: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

Java Source and Object Files

Compilation Units (.java files)– With a main method– Without a main method

Java Bytecode (.class files)– Compilation-level class files– Nested class files

Page 7: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

Glazers Interfaces Package

What is a Java package? com.glazers.interfaces package Five compilation units:

– GetOpenPO – import open POs– GetInterCo – import intercompany transfers– GetOpenCO – import open customer orders– Function – class of static methods– LogMaker – class to make log object

Page 8: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

Examples of Java Files

Function.java

Function.class

GetOpenPO.java

GetOpenPO.class

ImportOpenPO.class

Page 9: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

More Examples of Java Files

LogMaker.java

LogMaker.class

LogMaker$PrintEnding.class

LogMaker$PrintHeading.class

LogMaker$PrintLine.class

LogMaker$PrintMethods.class

Page 10: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

Integration ETL Program Structure

Five Basic Steps– Open log file and database connections– Extract the result set from source system– Transform any data items– Load the data batch in target system – Close log file and database connections

Page 11: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

What are the Objects?

Log Object Database Connection Objects SQL Statement Objects Result Set Objects BatchInsert Objects String and Date Objects

Page 12: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

The Code Environment

package com.glazers.interfaces;

import java.io.*;import java.sql.*;import java.util.*;import com.ibm.as400.access.*;import com.javaranch.common.GDate;import com.javaranch.common.JDate;import com.glazers.interfaces.*;

Page 13: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

GetOpenPO Class and main

public class GetOpenPO {

public static void main(String args[]) {

// Create an ImportOpenPO object

ImportOpenPO impObj = new ImportOpenPO();

Page 14: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

Full main method

// Create an ImportOpenPO object

ImportOpenPO impObj = new ImportOpenPO();

// Call the mainLine and receive its return code

System.exit(impObj.mainLine(args[0],args[1],

args[2],args[3],args[4],args[5]));

Page 15: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

Comments

// The main method for class GetOpenPO takes six parameters:// 1) Log File Directory Path (ex. Home/JavaApps/Manu)// 2) Oracle Database Name (SCPODEV, SCPOTEST, etc.)// 3) Oracle UserID// 4) Oracle Password// 5) AS/400 UserID// 6) AS/400 Password// After creating an ImportOpenPO object, these parameters are// passed to its mainLine method.

Page 16: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

ImportOpenPO Class & mainLine

class ImportOpenPO {

public int mainLine

(String dirPath, String oraSID,

String oraUser, String oraPwd,

String as400User, String as400Pwd) {

Page 17: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

ImportOpenPO Code Structure

try [outer try/catch block] [start the log] try [inner try/catch block] open database connections extract result set from source system perform any data transformations load data batch into target system close database connections catch [catch inner exceptions] catch [catch outer exceptions]

Page 18: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

Outer try statements

try {

// Create LogMaker object and begin logging

LogMaker log = new LogMaker(dirPath,"OpenPO.log");

log.printHeading("Open PO Import Log");

// If run interactively, display running message

System.out.println ("Open PO Import is running");

Page 19: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

Inner try block job steps

Open database connections Create Sql statement objects Extract the result set Loop throught the result set:

– Extract the data items from result set object– Perform any data transformation– Set the data into the batchInsert object

Check error table for any rejects– If any rejects, print rejects to log

Close result sets and database connections

Page 20: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

Connect to the iSeries

// Register the AS400 JDBC Driver

DriverManager.registerDriver(new AS400JDBCDriver());

// Create a properties object and connect to the database

Properties as400Prop = Function.getAS400Prop(as400User,as400Pwd);

conn400 = DriverManager.getConnection ("jdbc:as400://GLAZERS",as400Prop);

Page 21: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

Connect to Oracle

// Load the Oracle JDBC driver

Class.forName("oracle.jdbc.driver.OracleDriver");

// Get the Oracle connection string

String oraConnStr = Function.getOraConnStr(oraSID,oraUser,oraPwd);

// Connect to the database server

connOra = DriverManager.getConnection(oraConnStr);

connOra.setAutoCommit(false);

Page 22: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

Extracting the Result Set

// Get the SQL statement to assign to the stmt400 sqlQuery string

String sqlQuery = getSQL(); // Create a Statement object (stmt400)stmt400 = conn400.createStatement(); // Execute the SQL Select and obtain the

ResultSet object (rs)rs = stmt400.executeQuery(sqlQuery);

Page 23: Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.

The Batch Insert Prepared Statement

// Construct the Insert Prepared Statement before entering the loop

PreparedStatement sqlInsert = connOra.prepareStatement("INSERT INTO INTINS_SCHEDRCPTS " + "(item, loc, scheddate, qty, expdate, ponum, " +"startdate, dateship, masterloadid, loadid," +"integration_stamp, integration_jobid)" +"VALUES (?,?,?,?,?,?,?,?,?,?,?,?)");