130 likes | 255 Vues
Object Oriented COBOL. Terminology. Objects replace files & programs “an entity that has a unique identity, specific data values, and specific behaviors or program code” - COBOL 2000 standard Messages communication between objects Method
E N D
Terminology • Objects • replace files & programs • “an entity that has a unique identity, specific data values, and specific behaviors or program code” - COBOL 2000 standard • Messages • communication between objects • Method • “procedural code that defines a specific function…A method may be thought of as a module or a subroutine” - COBOL 2000 standard • Invoking a method • when one object requests another object to perform a method • Class • a generic definition of an object • Instance • a specific occurrence of an object
TERMINOLOGY • A SUBCLASS uses the attributes (data) and methods of its SUPERCLASS • INHERITANCE - attributes, methods, and relationships from a SUPERCLASS are inherited by its SUBCLASS • Persistence - remembering an object’s previous state
Classes and Instance A customer is represented by an instance Sue Smith 12334 Sommset Customer CHANGE-ADDRESS CUSTOMER NameAddress CHANGE-ADDRESS All Customers are represented by a CLASS
SUPERCLASSES AND SUBCLASSES SUPERCLASS SUBCLASS
CLASSES by FUNCTION • Problem Domain - These classes do the primary work of the system. • UI Classes - Handle such things as the interactive screens to communicate with the user and report printing or other external documents • System Interaction provides interfaces to other systems. Handling files passed between systems, corporate Database access, and telecommunications • Data Management - manage the storage and retrieval of data used by the Problem Domain • Drivers - used to initiate and test objects. May be temporary in nature
Table 20.1 Student-Look-Up System Design Driver & Classes CLASS CATEGORY FUNCTIONS Student-Look-Up Driver Initiates the system and creates the Registrar object. Registrar Problem Domain Maintains overall control of the system, creates the utility objects: StudentUI, StudentDM, and StudentPRT. Interacts with Student to get the student name. Student Problem Domain Maintains the Student data. Can produce the student’s name, credit hours taken, and major. Person Problem Domain Parent Class to Student. Maintains the student name information. StudentDM Data Management Controls the processing of the Student File and creates Student Instances based on requested parameters. StudentPRT User Interface Controls the production of the report. StudentUI User Interface Controls the interactive dialog with the user of the system.
1 StudentUI GetParametersDisplayHoursRequest DisplayMajorRequest 1 1 1 Person Name GetName PopulateName Registrar ProcessRequests StudentPRT OpenPrinterWriteHeaderWriteDetailFinalizeReport 1-n ‘Contains” symbol 1 StudentDM GetStudentCreateStudentReadRecord Student StudentMajorHoursCompleted PopulateStudent 1 ‘Inheritance’ symbol 1 1 n Student-Look-Up System Design
Structured Little reuse Concerned with files Focus is on Verbs PRINT CHECKS UPDATE PAYROLL Elaborate control structures No data change authorization OO Programming Optimum reuse Objects communicate Messages Focus on the entities Employees Departments Simple structures Data access Control Structured vs OO Programming
COBOL Changes • OBJECT SECTION - part of the ENIVIRONMENT DIVISION and defines the interfaces to CLASSES used by the program • CLASS-CONTROL paragraph - relates the classes use to the class template files. Template files contain the definitions and are linked to the program or class when it is compiled. • Object Reference - a new data type used to store the address (pointer) to objects used by the program. Referred to as handles. • INVOKE - similar to CALL but passes control to the OBJECT it addresses. May pass parameters to or from the invoked procedure.
Figure 20.3 Syntax of INVOKE INVOKE object-name { literal-1 | data-name-1 } [ USING { data-name-2 } … [ RETURNING data-name-3 ] ]
MEMORY Leakage • Occurs when a new instance’s address replaces an previous instance - caused by using the same handle • Original instance remains in memory with no way to access - it has become an orphan • Some OO languages provide for garbage collection - COBO 20XX standard • Destroy unneeded instances INVOKE identifier-1 ‘FINALIZE’ RETURNING identifier-1