prototyping for hci
DESCRIPTION
Prototyping for HCI. Spring 2004 (Week 8) Jorge A. Toro. The Language. Custom Classes. Custom classes. VB.NET is Object-Oriented So far, you have handled pre-defined classes (Form, Button, Integer, String, etc…) -but- - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/1.jpg)
1
Prototyping for HCI
Spring 2004 (Week 8)Jorge A. Toro
![Page 2: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/2.jpg)
2
The Language
Custom Classes
![Page 3: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/3.jpg)
HCI430 – J.Toro 3
Custom classes
VB.NET is Object-Oriented So far, you have handled pre-defined classes
(Form, Button, Integer, String, etc…)
-but- You can also create your own classes that
can ease the coding and fit the needs of your prototype
![Page 4: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/4.jpg)
HCI430 – J.Toro 4
Custom classes
How do you know when you need a custom class? You need to do some design decisions on what
kind of classes you will need. There is no golden rule in this, many different
classes can be created and used, it all depends how you want to architect your code.
![Page 5: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/5.jpg)
HCI430 – J.Toro 5
Custom classes
When you are writing the code inside a form, you are actually writing the code for the Form’s class…
![Page 6: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/6.jpg)
HCI430 – J.Toro 6
Your form Your form is defined as a
class
![Page 7: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/7.jpg)
HCI430 – J.Toro 7
Custom classes
Creating a custom class Custom classes are created in separate files Same as different forms are in separate files To add a custom class file
1. File -> Add New Item…
2. Select Class, give a name to it
3. Done.
![Page 8: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/8.jpg)
HCI430 – J.Toro 8
1
![Page 9: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/9.jpg)
HCI430 – J.Toro 9
21 Select Class
2 Name the Class
![Page 10: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/10.jpg)
HCI430 – J.Toro 10
3The class file appears in your Solution Explorer window
This code is automatically generated. Here is where you write the code to define the properties and methods of your class.
![Page 11: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/11.jpg)
HCI430 – J.Toro 11
Custom classes
Defining properties for the class One way: Declare global variables as Public.
Public Class Member Public p_id As String Public p_lname As String Public p_fname As String Public p_address As String Public p_city As String Public p_state As String Public p_zip As StringEnd Class
Properties
![Page 12: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/12.jpg)
HCI430 – J.Toro 12
Member class
![Page 13: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/13.jpg)
HCI430 – J.Toro 13
Custom classes
Using your custom class You create instances (objects) of the class
Use the New keyword, the same way you use it to create forms.
![Page 14: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/14.jpg)
HCI430 – J.Toro 14
Form1 class
You now can declare Member objects
![Page 15: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/15.jpg)
HCI430 – J.Toro 15
Custom classes
Everything declared with either Dim or Private will not be accessible from outside the class.
![Page 16: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/16.jpg)
HCI430 – J.Toro 16
p_ssn is not declared Public. It will be accessible only inside this class.
Member Class
![Page 17: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/17.jpg)
HCI430 – J.Toro 17
p_ssn is not accessible outside the class, it was not declared Public.
x is an instance of Member class
Form1 Class
![Page 18: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/18.jpg)
HCI430 – J.Toro 18
Custom classes
Defining methods All the subs and Functions declared Public are
considered methods and are accessible outside the class.
![Page 19: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/19.jpg)
HCI430 – J.Toro 19
ResetNames is a Sub declared Public. It will be accessible outside.
Member Class
![Page 20: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/20.jpg)
HCI430 – J.Toro 20
ResetNames is accessible.
Form1 Class
![Page 21: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/21.jpg)
HCI430 – J.Toro 21
Custom classes
Sometimes, you want your object to start with some preset values in some of its properties. Constructor
Used to provide values to the properties when an instance is created
You can have different constructors for different situations
A constructor is always declared as Public and it is always named New
![Page 22: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/22.jpg)
HCI430 – J.Toro 22
Constructor1 (default)
Constructor2(custom)
![Page 23: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/23.jpg)
HCI430 – J.Toro 23
constructor1 is used here
constructor2 is used here
![Page 24: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/24.jpg)
24
The Language
Modules
![Page 25: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/25.jpg)
HCI430 – J.Toro 25
Modules
Modules are files where you can write code that does not belong to any particular form. Global functions Global Subs Global variables
Global variables declared in a Module are global to all the project.
![Page 26: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/26.jpg)
HCI430 – J.Toro 26
![Page 27: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/27.jpg)
HCI430 – J.Toro 27
1 Select Module
2 Name the Module
![Page 28: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/28.jpg)
HCI430 – J.Toro 28
The module file appears in your Solution Explorer window
This code is automatically generated. Here is where you write the code.
![Page 29: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/29.jpg)
HCI430 – J.Toro 29
Modules
Sub Main You can set the Startup Object of your project to
a special sub named Main You create the Sub Main inside a Module file.
![Page 30: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/30.jpg)
HCI430 – J.Toro 30
mainForm is a global variable
mainForm is created
mainForm is shown
![Page 31: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/31.jpg)
HCI430 – J.Toro 31
Modules
In the previous example, if you set your startup object of your project to be the Sub Main, you have to create the instance of Form1 and show it.
This is useful when you have a prototype with many form files.
![Page 32: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/32.jpg)
32
The Language
Class Libraries
![Page 33: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/33.jpg)
HCI430 – J.Toro 33
Class libraries
A separate project for creating classes for use in other applications
This is what you will get from me A project with some classes inside
![Page 34: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/34.jpg)
HCI430 – J.Toro 34
Class libraries
Using the library in your prototype (1/2) Add the library into your prototype’s project
![Page 35: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/35.jpg)
HCI430 – J.Toro 35
![Page 36: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/36.jpg)
HCI430 – J.Toro 36
Select the project name
![Page 37: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/37.jpg)
HCI430 – J.Toro 37
The project appears into the Solution explorer
![Page 38: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/38.jpg)
HCI430 – J.Toro 38
Class libraries
Using the library in your prototype (2/2) Reference the class library in your project so
you can start using the classes Why do you have to do this?
Because the classes I wrote are inside a separate project, they are not part of yours.
![Page 39: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/39.jpg)
HCI430 – J.Toro 39
1 Select your project
2 Select “Add Reference”
![Page 40: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/40.jpg)
HCI430 – J.Toro 40
1 Click over the Projects tab
2 Select the Utils Project
3 Click Select
![Page 41: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/41.jpg)
HCI430 – J.Toro 41
The library will appear here
Click Ok
![Page 42: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/42.jpg)
HCI430 – J.Toro 42
The Utils library will appear listed under the References folder in your project
![Page 43: Prototyping for HCI](https://reader035.vdocument.in/reader035/viewer/2022062308/568139d5550346895da18914/html5/thumbnails/43.jpg)
HCI430 – J.Toro 43
Questions?