What is the difference between type and class in

Source: Internet
Author: User
A
Detailed description of both types and classes is
Below.


Problem:
What is the difference between a type and a class in
LotusScript?

Solution:
A detailed description of both types and
Classes is below.

I. Types

In Lotus script, data types can be
Defined with data members (variables) that
Can be manipulated as
Single
Unit. types can be used to build a record structure to store database
Records
Within LotusScript.

A type is defined with the type... end
Type statement. Within this statement,
The type members are
Declared
(Without the dim Statement ).

For example, to declare a type named
Orderinfo, with the Members ID (
Fixed-length string ),
Customername (
Variable Length string) and totalprice (a currency value);
Following
Statements cocould be
Used:

Type orderinfo
ID as string *
6
Customername as string
Totalprice as currency
End type

After
Declaring a type, a variable can be declared of this type, just as

Variable cocould be declared of a built-in
Data Type. For example,
Declare a variable to contain a single order:

Dim ordervariable
Orderinfo

A fixed array of 10 orders can also be declared:

Dim
Orderarray (10) as orderinfo

Each of the ten elements of this array is
Instance of the orderinfo type.
Each of these instances des
One
Each type member:

ID
Customername
Totalprice

Members of
Type can have any built-in data type to another user-defined type;
However,
A type member
Cannot contain an instance of itself.

Use dot notation
To refer to a member of a type variable. For example, in
Type defined
Above,
Members of the Instance ordervariable can be accessed
Follows:

Dim ordervariable as orderinfo
Ordervariable. ID =
"001"
Ordervariable. customername = "Joe Jones"
Ordervariable. totalprice =
35.00

Ii. Classes

Classes are similar to types But classes go one
Step further. Like types,
Classes can declare aggregates of data
Which
Can be manipulated as a single unit. Classes also allow subprograms to be

Declared which manipulate
The class data. The data and the subprograms
Together form a class; A single
Unit. A Programming Language
Such
Lotus script which allows programs based on classes to be created is
Called
An object-oriented
Programming language.

A class is defined similar
A type. variables are defined which are
Aggregated in the class.
Subprograms
Or methods can also be defined that manipulate the class
Variables or data
Members. methods can take
Form of subs, functions
Or properties.

Once a class is defined, the instances of the class are
Created. These
Instances are called objects.
Class... end class
Statement is used to create a class definition. classes can
Only be defined
At
Module level.

For example, in the following script, a customer
Class is declared with data
Members called custname,
Address and balance.
This class also includes a subprogram Member, called

Checkoverdue.

Class Customer
Public custname as string
Public
Address as string
Balance as currency

Sub checkoverdue 'this
Subprogram takes no arguments
If balance> 0 then
Print "Overdue
Balance"
End if
End sub
End Class

Private
Public:

Class Members can be public or private. By default, class data
Members are
Private and class Subprogram
Members (methods) are public.
Public class members can be referred to outside
Of the class definition;
Private
Members cannot. Private Data members are hidden from subprograms
Defined
Outside of the class. Data Hiding
Helps programmers Structure
Their programs to limit access to member data. In
The above example,
Only
Subprograms which can refer to balance data are the member subprograms

(Methods) defined in the class
Customer; for example, the member
Subprogram checkoverdue defined above.
Data members
Custname and
Address are declared public, so these data members can be referred
To
Subprograms
Defined outside of the Class Customer.

After defining
Class, the dim statement may be used to declare Variables
Which refer
Objects of that class.
When an object reference variable is declared,
Object itself is not created.
The object reference variable
Is
Initialized to contain the special value nothing.

For
Example:

Dim X as customer
'This statement declares an object
Reference variable

X can hold either references to customer objects or
The value nothing. X is
Initialized to nothing.

Once an object
Reference variable has been created, an object can be created in
One of two
Ways. The first is
To use the keyword new in the declaration statement
The object reference
Variable. Using the keyword
New declares an object
Reference variable, creates an object and assigns
Reference to
Newly-created
Object to the variable.

For example:

Dim X as new
Customer

The second way to create an instance of a class is to use a set
Statement which
Provided des the New Keyword
And a variable which has been
Previusly declared as an object reference
Variable for that
Class.

For example:

Dim X as customer
Set x = new
Customer

Once an object has been created, dot notation may be used
Refer to the data
Members and Methods
Associated with the object of
Given class; similar to using dot notation
With a type. dot notation is used
To
Refer to an individual member of an object. dot notation is also used

Reference member subprograms
(Methods) in a class.

For objects
Declared outside the class, dot notation can only be used to access
Data
Members that are
Public. For example, if X is a public object reference
Variable of the class
Customer, the public data member
Balance in
Class Customer is referred to as X. Balance outside the class
Definition. If
The data member
Balance was not declared using the public keyword, it wowould
Be accessible only
From within the class
Definition; not outside
It.

For example:

Class Customer
Public custname
String
Public Address as string
Public balance as currency

Sub
Checkoverdue 'this subprogram takes no arguments
If balance> 0
Then
Print "Overdue balance"
End if
End sub
End Class

Dim X
As new customer
'This statement declares an object reference variable X
The Class Customer
And also creates an object
That class and assign x
A reference to the new customer object.

X. custname = "Acme
Corp ."
'This statement is legal because custname is public.

X. Balance
= 35.00
'This statement is legal because balance is
Public.

X. checkoverdue
'This statement invokes the member Subprogram
Checkoverdue. Since this sub
Takes no arguments, no
Arguments are passed
When the sub is called. In this instance, the text
"Overdue balance" wowould
Print since
X. Balance is greater than zero.

Members of the current
Object within a class subprogram (method) can be
Declared by using
Me
Keyword. The me keyword is not valid outside of a Class Method
(Subprogram ).

For example:

Class Customer
Public custname
String
Public Address as string
Public balance as currency

Sub
Checkoverdue 'this subprogram takes no arguments
If me. Balance> 0
Then
Print me. Balance
Else
Print "no overdue balance"
End if
End
Sub
End Class

Dim X as new customer
'This statement declares
Object reference variable X of the Class Customer.
It also creates an object
Of that
Class and assign x a reference to the new customer
Object

X. custname = "Acme Corp ."
'This statement is legal because
Custname is public.

X. Balance = 35.00
'This statement is legal because
Balance is public.

X. checkoverdue
'This statement invokes the Member
Subprogram checkoverdue. Since this sub
Takes no arguments, no
Arguments
Are passed when the sub is called. In this instance, the value
X. Balance
Wocould print since
X. Balance is greater than zero.

For additional
Information about types and classes, refer to the LotusScript
Reference
Guide, Chapters 3
And 5, respectively.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.