Download presentation
Presentation is loading. Please wait.
1
UQI107S3 Object Orientation lecture 2
2
Plan Review Tutorial 1 Testing Mayday development –latlong type, boat type, boats table –procedures 3 Tier application Some distinctions
3
Review tutorial 1 Using SQLPLUS -See notes Latitude and Longitude, Degrees and minutes Variables and values - see later Additions to tests - – asString() not tested – should be able to predict answer to test
4
new method -asDegrees() Add to definition of dm type member function asDegrees return real, Add to body member function asDegrees return real is begin return degrees + sign(degrees) * minutes/60; end; Compile sqlplus user/password < dm.sql Test it select dm(0,30).asDegrees() from dual;
5
Review Tutorial - constructors Test scripts use the constructor to create an object of the new type: –dm(30,45) –creates an object of type dm with degrees = 30 minutes = 45 same thing happens when you enter a date - ‘04/02/03’ in a date field - a date value is constructed
6
Testing Develop - test –develop small units, bottom-up –develop test scripts so that tests can be repeated whenever a change is made - ‘regression testing’ select dm(30,30).asMin() from dual; Predict output before running test value should be 30*60 + 30 = 1860 select dm(30,30).asMin()- 1830 from dual; output should be 0 Testing strategy part of ‘Extreme Programming’ and ‘Agile Development’
7
Mayday development –Define base degrees/minutes type test –Define two further types - latlong and boat test –Define table of boat types - to store objects –Define some boats test –Create PL/SQL procedures to access data from a browser test
8
create or replace type latLong as object ( latitude dm, longitude dm, member function distanceTo(x latLong) return real, member function asString return varchar ); parameter Define the ‘Interface’ to the type: it supplies all information a user of this type needs to know Values of these variables will be objects of type dm
9
Values and variables Base types - in the type dm: –degrees is a variable of type number –30 is a value of type number Defined types –latitude is a variable of type dm –dm(30,0) is a value (an object) of type dm
10
create or replace type body latLong as member function distanceTo(x latLong) return real is dlat real; dlong real; -- this is an approximation for short distances begin dlat:= latitude.asMin()- x.latitude.asMin(); dlong:=longitude.asMin() - x.longitude.asMin(); dlong:=dlong*cos((latitude.asRad()+x.latitude.asRad())/2); return round(sqrt((dlat*dlat) + (dlong*dlong))); end; Local variables Return computed distance This calculation is a bit tricky, so good to put it in one place, test it and then simply use it: Now define the ‘Implementation’ of each function - the code that makes it produce the result: call the asMin() function on the object in variable ‘latitude’
11
member function asString return varchar is hemi char(2); pole char(2); begin if (latitude.degrees < 0) then pole:='S '; else pole:='N '; end if; if (longitude.degrees < 0) then hemi:='E '; else hemi:='W '; end if; return pole || latitude.abs().asString() || ' ' || hemi || longitude.abs().asString(); end;
12
select latlong(dm(20,0), dm(30,0)).asString() from dual; Construct dm object Construct latlong object All these objects are ‘transient’ - exist for the calculation only All these objects are ‘transient’ - exist for the calculation only
13
Test latlong.distanceTo(latlong) select latlong(dm(0,0), dm(0,0)).distanceTo( latlong(dm(1,0), dm(0,0)) ) from dual; Surprisingly, can have blanks here! Receiving Object Object as Parameter Function call Result should be 60
14
Creating persistent Objects Define create or replace type boat as object ( name varchar(20),pos latlong ); Test select boat('Perdika', latlong(dm(53,20), dm (2,48))) from dual; Create table create table boats of boat; Create some persistent objects insert into boats values('Perdika',latlong(dm(20,30),dm(10,20))); insert into boats values('Flash',latlong(dm(21,35),dm(12,20)));
15
UML Class Model Using Rational Rose
16
3-tier system User interface using Browser Business rules using P|L/SQL Requests + data HTML Relational Database using Oracle 9 SQLRelation (accessed by cursor)
17
create or replace procedure chooseboat is cursor allboats is select * from boats b; begin htp.print(' '); htp.print(' Target boat name '); for b in allboats loop htp.print(' ' || b.name || ' ' ); end loop; htp.print(' '); htp.print('Range to search <input type=text name=reqrange size=5 value=100>'); htp.print(' '); end; The procedure to make a form to select a boat and range SQL statement html
18
Procedure to find boats in range create or replace procedure getnearestboats (reqname varchar, reqrange varchar) is target boat; cursor selboats is select * from boats b where b.name !=target.name -- dont want target and b.pos.distanceTo(target.pos) < reqrange order by b.pos.distanceTo(target.pos); begin select value(b) into target from boats b where name=reqname; …..
19
Generating the output htp.print(' '|| target.name || ' at position ' || target.pos.asString() || ' '); htp.print(' Boats within ' || reqrange || ' miles '); htp.print(' '); for b in selboats loop htp.print(' ' || b.name || ' at ' || b.pos.asString() || ' is ' || b.pos.distanceTo(target.pos) || ' miles away '); end loop; htp.print(' '); end;
20
Distinctions -1 Type and Object –type defines the structure and behaviour of all the objects of that kinds –object is a single instance of that type –compare with: Base type String and ‘String’ Table EMP and tuple (3456,’Smith’,’Accounting’)
21
Distinctions - 2 Variable and Value –a value is fixed, a variable is a name for a place to store values Interface and Implementation –interface defines what a user of an object can do, implementation defines how it works internally
22
Distinctions - 3 Transient and Persistent –Transient objects exist only while a program is executing –Persistent objects are stored in permanent storage (e.g. a Database) and are deleted on command
23
Next week Tutorial –install this application and make small changes to the procedures Lecture –Inheritance –UML diagrams
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.