". . . . Questions: SQL in VB.">
23 object oriented programming in asp
This presentation is the property of its rightful owner.
Sponsored Links
1 / 18

23 – Object Oriented Programming in ASP PowerPoint PPT Presentation


  • 28 Views
  • Uploaded on
  • Presentation posted in: General

23 – Object Oriented Programming in ASP. Questions: HTML in VB. Are these correct (assume variables and fields exist)? s = s + <td> + rs.Fields(" Model ").value s = s rs.Fields(" Length ").value h = "< div >" + h + "</ div >". . . . Questions: SQL in VB.

Download Presentation

23 – Object Oriented Programming in ASP

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


23 object oriented programming in asp

23 – Object Oriented Programming in ASP


Questions html in vb

Questions: HTML in VB

  • Are these correct (assume variables and fields exist)?

    s = s + <td> + rs.Fields("Model").value

    s = s rs.Fields("Length").value

    h = "<div>" + h + "</div>"


Questions sql in vb

Questions: SQL in VB

  • Are these correct (assume variables and fields exist)?

    id = 4

    sql = SELECT * FROM Customer

    sql = sql " WHERE [CustID] = " + id + ";"

    rs.Open(sql, cs)


Questions writing to databases

Questions: Writing to Databases

  • Write a line of VB code to add a new record to a recordset called rs.

  • Write a line of VB code to remove the current record from a recordset called rs.

  • Write a line of VB code to put "Hello" into a field called Message in the current record

rs.AddNew()

rs.Delete()

rs.Fields("Message").Value = "Hello"


Session aims objectives

Session Aims & Objectives

  • Aims

    • To highlight that the object oriented techniques covered earlier can be used in ASP

  • Objectives,by end of this week’s sessions, you should be able to:

    • create a class definition in server-side code

    • create an instance of a class

    • create a class definition from a class diagram


Object oriented paradigm

Object-Oriented Paradigm

  • A program is made up of a number of objects that communicate with each other by passing messages

  • Each object contains

    • attributes/properties that represent its state, and

    • operations/methods that represent its behaviour

  • Objects often mirror the real world

    • Customers

    • Students

    • Patients


Classes and instances

Classes and Instances

  • Object Classes

    • general descriptions of types of objects,e.g. student, product, customer, lecturer, and room.

  • Object Instances

    • specific items of a given class, e.g.

      • each of you could be an instance of the student class

      • Room 214 could be an instance of the room class

      • I could be an instance of the lecturer class

      • Bolt could be an instance of the part class


Object concepts implementation

Object Concepts - Implementation

  • Properties – implemented as

    • data structures (variables, arrays, and types).

  • Methods – implemented as either

    • a procedure (to perform some processing), or

    • a function (to return a value).

  • Object oriented paradigm builds on (rather than replaces) the structured paradigm


Class diagrams

Class Diagrams

  • Used to describe structure of object classes:

Class Name

Module

Code: string

Title: string

Class Attributes/Properties

GetTitle(): string

SetTitle(t: string)

Count(): integer

Class Operations/Methods


Implementing class diagrams

Implementing Class Diagrams

Module

Code: String

Title: String

GetTitle(): string

SetTitle(t: string)

Count(): integer

Class Module

Public Code As String

Public Title As String

Public Function GetTitle() As String

Public Sub SetTitle(t As String)

Public Function Count() As Integer

End Class


Example animals

Example: Animals


Example student

Example: Student


Public and private

Public and Private

  • Control access to properties and methodsClass a Public x As Single Private y As Single Public Sub ResetY() y = 0 End SubEnd ClassDim b As New a b.x = 5 b.ResetY() b.y = 10

 this works (x is public) this works (ResetY is public) this will fail (y is private)


Benefits of oop in code

Benefits of OOP in code

  • Procedures and Functions are part of object

    • encapsulation

  • RelatedData and Operationstogether

  • Private keyword – restrict access to data

  • Clearer code

  • Less prone to error


Example counter html

Example: Counter (html)

<html>

<head><title>Counter</title></head>

<body>

<form runat="server">

<input id="btnReset" type="submit" value="Reset" runat="server" />

<input id="btnUp" type="submit" value="Up" runat="server" />

<input id="btnDown" type="submit" value="Down" runat="server" />

<p id="parMsg" runat="server"></p>

</form>

</body>

</html>


Example counter code

Example: Counter (code)

<script language="VB" runat="server" src="Counter.vb"></script>

<script language="VB" runat="server">

Dim c As Object

Sub Page_Load()

If Session("c") Is Nothing Then

Session("c") = New Counter

Else

c = Session("c")

If Request.Form("btnReset") > "" Then

c.Reset()

ElseIf Request.Form("btnUp") > "" Then

c.Up()

ElseIf Request.Form("btnDown") > "" Then

c.Down()

End If

parMsg.innerText = c.GetCount()

End If

End Sub

</script>

Counter.vb

Class Counter

Private mCount As Long

Public Function GetCount() As Long

GetCount = mCount

End Function

Public Sub Reset()

mCount = 0

End Sub

Public Sub Up()

mCount = mCount + 1

End Sub

Public Sub Down()

mCount = mCount - 1

End Sub

End Class


Questions oop

Questions: OOP

Class Counter

Private mCount As Long

Public Function GetCount() As Long

GetCount = mCount

End Function

Public Sub Reset()

mCount = 0

End Sub

Public Sub Up()

mCount = mCount + 1

End Sub

Public Sub Down()

mCount = mCount - 1

End Sub

End Class

Function Twice(x As Long) As Long

Return x * 2

End Function

  • How many

    • classes

    • properties

    • methods

    • functions

    • procedures

1

1

4

2

3


Tutorial exercise counter

Tutorial Exercise: Counter

  • Task 1: Get the Counter example from the lecture working.

  • Task 2: Modify your code – so that the value cannot go below 0 or above 10.


  • Login