Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using Visual Basic.NET in Web Pages ASP.NET. Object-Oriented Programming (Page 1) Classes and Objects – Create objects based upon a class An object is.

Similar presentations


Presentation on theme: "Using Visual Basic.NET in Web Pages ASP.NET. Object-Oriented Programming (Page 1) Classes and Objects – Create objects based upon a class An object is."— Presentation transcript:

1 Using Visual Basic.NET in Web Pages ASP.NET

2 Object-Oriented Programming (Page 1) Classes and Objects – Create objects based upon a class An object is a set of related code that is compartmentalized and built upon these classes Access the object across multiple Web pages – Create an object The object definition, called the class Creating an instance of the class – Use the class as the template ("blueprint") for creating the new object Open ClassVariables.aspx

3 Object-Oriented Programming (Page 2) Multiple objects can be created (instantiated) from the same class definition Example of a class definition: Public Class TaraStoreClass Private StoreName As String = "Tara Store" End Class

4 Object-Oriented Programming (Page 3) Restrict applications access to the class – Public—interact with other objects outside of the base class – Private—called only from within the base class – Protected—called from within the base class, and within subclasses Subclass—a class that inherits from a base class – Friend—called anywhere from within the same application

5 Object-Oriented Programming (Page 4) Instantiate an object based on the class definition – Declare a variable The keyword Dim to store the object The keyword New to identify that this is an object based on a class definition – Example: Dim objCh5 As New TaraStoreClass()

6 Object-Oriented Programming (Page 5) Properties – Sets (updates) or gets (retrieves) the value of a variable defined within an object – Identified by the object name, a dot (.), and the property name, i.e. objCh5.StoreName – May be assigned a default value within the class definition, or the value is set as "undefined" – All new objects inherit the same properties as the original object definition

7 Object-Oriented Programming (Page 6) Inheritance – Derives the interface and behaviors from another class – The Inherits keyword allows one class to inherit features from another.NET class – All objects in every VB.NET application are inherited from the System.Object class – Methods from System.Object such as ToString () apply to most objects Encapsulation – Inner workings of object are maintained within object

8 ClassVariables.aspx

9 Programmer-Defined Properties (Page 1) Object variables store the programmer-defined property values In Visual Basic programming, they are managed within special Property procedures – Used to keep object variables Private Property procedures are VB.NET's tools for providing update and retrieve capabilities (indirectly) for Private variables using Public methods … – One of the values of such methods it that they can provide validating techniques within the statements Open SampleUsingVB.aspx

10 Programmer-Defined Properties (Page 2) Each of Property procedures may have two methods: – Set methods update the value of an instance variable – Get methods retrieve an instance variable value A Property procedure that only may "set" a value must have the declaration WriteOnly, i.e. Public WriteOnly Property NewStoreEmail() As String A Property procedure that only may "get" a value must have the declaration ReadOnly, i.e. Public ReadOnly Property NewStoreName() As String

11 Programmer-Defined Properties (Page 3) Format: Public Property propertyName() As dataType Get statements End Get Set(ByVal varName As dataType) statements End Set End Property Must match

12 Programmer-Defined Properties (Page 4) Example: Public Property NewStoreName() As String Get Return strStoreName End Get Set(ByVal Value As String) strStoreName = Value End Set End Property

13 The Set Method (Page 1) Updates the value of an instance variable Its always assigns either: – The Value which it gets from the variable in the parameter list in procedure heading – A default value May only exist in a Property procedure Set method for a object is called when a value is assigned to the property of that object, i.e. objTS2.NewStoreName = "Tara Store Chicago"

14 The Set Method (Page 2) Format: Set(ByVal varName As dataType) [statements_including] instanceVariable = varName/defaultValue End Set Example: Set(ByVal Value As String) strStoreName = Value End Set

15 The Get Method (Page 1) Retrieves the value of an instance variable Its always uses keyword Return along with the name of the instance variable (usually a single statement) Also may only exist in a Property procedure Get method for a object is called when the object's property is assigned to another variable, i.e. lblTitle.Text = objTS2.NewStoreName

16 The Get Method (Page 2) Format: Get [statements_including] ' not likely Return instanceVariable End Get Example: Get Return strStoreImage End Get

17 SampleUsingVB.aspx


Download ppt "Using Visual Basic.NET in Web Pages ASP.NET. Object-Oriented Programming (Page 1) Classes and Objects – Create objects based upon a class An object is."

Similar presentations


Ads by Google