1 / 23

UQI107S3

UQI107S3. Object Orientation lecture 2. Plan. Review Tutorial 1 Testing Mayday development latlong type, boat type, boats table procedures 3 Tier application Some distinctions. Review tutorial 1. Using SQLPLUS -See notes Latitude and Longitude, Degrees and minutes

sancha
Download Presentation

UQI107S3

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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. Define the ‘Interface’ to the type: it supplies all information a user of this type needs to know create or replace type latLong as object ( latitude dm, longitude dm, member function distanceTo(x latLong) return real , member function asString return varchar ); Values of these variables will be objects of type dm parameter

  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. Now define the ‘Implementation’ of each function - the code that makes it produce the result: 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; call the asMin() function on the object in variable ‘latitude’ 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:

  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. Construct dm object Construct dm object select latlong(dm(20,0), dm(30,0)).asString() from dual; All these objects are ‘transient’ - exist for the calculation only Construct latlong object

  13. Test latlong.distanceTo(latlong) Receiving Object Surprisingly, can have blanks here! select latlong(dm(0,0), dm(0,0)) .distanceTo( latlong(dm(1,0), dm(0,0)) ) from dual; Function call Object as Parameter 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 Requests + data HTML Business rules using P|L/SQL SQL Relation (accessed by cursor) Relational Database using Oracle 9

  17. The procedure to make a form to select a boat and range create or replace procedure chooseboat is cursor allboats is select * from boats b; begin htp.print('<form action=getnearestboats method=get>'); htp.print('<br>Target boat name <select name=reqname>'); for b in allboats loop htp.print('<option>' || b.name || ' </option> ' ); end loop; htp.print('</select>'); htp.print('Range to search <input type=text name=reqrange size=5 value=100>'); htp.print('<input type=submit value=‘search’>'); htp.print('</form>'); end; 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('<h3>'|| target.name || ' at position ' || target.pos.asString() || '</h3>'); htp.print('<h4>Boats within ' || reqrange || ' miles</h4>'); htp.print('<ul>'); for b in selboats loop htp.print('<li><b>' || b.name || '</b> at ' || b.pos.asString() || ' is ' || b.pos.distanceTo(target.pos) || ' miles away</li>'); end loop; htp.print('</ul>'); 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

More Related