Documente Academic
Documente Profesional
Documente Cultură
In Visual Basic.NET
Pre-Assessment Questions
1. Consider the following statements:
• Statement A: There are two types of user interfaces, character user
interface and (CUI) and graphical user interface (GUI).
• Statement B: In CUI, you can interact with an application by entering
commands.
Which of the following is correct with respect to the above statements?
a. Both, Statement A and Statement B, are False.
b. Both, Statement A and Statement B, are True.
c. Statement A is True and Statement B is False.
d. Statement A is False and Statement B is True.
Solutions to Pre-Assessment
Questions
1. b.
2. b.
3. c. Char
4. a.
5. b. System data type
Objectives
In this lesson, you will learn to:
• Identify classes and objects
• List the advantages of using classes and objects
• Declare and import namespaces
• Implement abstract classes in Visual Basic .NET
• Declare structures and interfaces
• Create and instantiate a class
• Create an inherited form in Visual Basic .NET
• Implement inheritance in VB .NET
Understanding Object-Orientation
Concepts
• Visual Basic.Net is an object-oriented programming language.
• Visual Basic .NET supports all the four features of object-oriented
programming.
• The features of object-oriented programming are
• Encapsulation
• Abstraction
• Inheritance
• Polymorphism.
Understanding Classes
• A class is a conceptual representation of all the entities that share
common attributes and behaviors.
Object
• An object is an instance of a class
• All the objects of a class have individual copies of the attributes and share a
common set of behaviors
Constructors
• Constructors are special methods that allow control over the initialization of
objects.
• A shared constructor will not run more than once during a single execution of a
program.
• When an instance of a class is created, the run-time environment executes the
instance constructors.
Destructors
• Destructors are special methods that are used to release the instance of a
class from memory.
• There are two types of destructors in Visual Basic .NET, Finalize() and
Dispose().
• The sequences in which the constructors and destructors are invoked are:
• Shared constructor of the inherited class
• Shared constructor of the base class
• Instance constructor of the base class
• Instance constructor of the inherited class
Namespaces
• Namespaces enable you to avoid name collisions.
• Every project in Visual Basic .NET has a root namespace, which is set in the
Property page of the project Using Namespaces.
• You can also organize classes using the Namespace keyword as shown below.
Namespace CustNameSpace
Class CustClass
End Class
End Namespace
• You can use namespaces explicitly through direct addressing or implicitly
through the Imports statement.
Understanding Structures
• A structure is used to create user-defined data types.
• You can declare a structure when you want a single variable to hold multiple
types of related data.
• Data can be stored in and retrieved from a structure.
Inheritance
• The inheritance feature allows you to define a new class by extending an
existing class.
Polymorphism
• The concept of using operators or functions in different ways depending on
what they are operating on is called polymorphism.
Demo for
Creating a Class in Visual Basic.Net
Problem Statement
• A company called Protec Inc. needs to maintain customer information. The
details of the customer need to be accepted through a graphical interface. The
user interface can be either Windows Forms, Web Forms, or Console. The
customer information also needs to be stored in relevant memory variables of
a class. The information should also be retrieved and displayed to the user.
The details of the customer will include CustomerID, First Name, Last
Name, Address, Telephone number and E-mail Id.
Solution
• A user interface screen is used to accept data from the user and displaying
data to the user. A class can be used to store and retrieve data from the
database. Perform the following steps to create a class:
• Create a user interface.
• Adding a class to the project
• Write the code to store and retrieve data from the class
• Save and run the application
Demo for
Implementing Inheritance
Problem Statement
• The company Protec Inc needs data entry forms to store information in the
Customers, Orders, and Query Handling databases. The data entry forms
should have a similar user interface with the Reset and Exit buttons.
Incorporate the interface for the Order details form.
Solution
• To create the user interface form you need to perform the following steps:
• Create the user interface screen
• Add code for the controls
• Create an inherited form based on the base form
• Add an inherited form to the project
• Add the additional user interface control
• Display a similar user interface
• Add code for the inherited controls
• Save and Execute the application
Summary
In this lesson, you learned that:
• Visual Basic .NET is an object-oriented programming language
• Classes can be added to a Visual Basic .NET project
• An object is an instance of a class
• Advantages of Using Classes and Objects
• Maintenance of code
• Encapsulation
• Reusabilty
• Support for a single interface to implement multiple methods
• Constructors are special methods that allow control over the initialization of
objects.
• Destructors are special methods that are used to release the instance of a
class from memory.
Summary (Contd.)
• An important advantage of using a namespace is the prevention of a name
collision
• Abstract classes are used to define the skeleton of the methods that the
derived class can implement.
• A structure is used to create user-defined data types.
• An interface enables you to separate the definition of objects from their
implementation so that the objects can evolve without the risk of introducing
incompatibility in existing applications.
• The inheritance feature allows you to define a new class by extending an
existing class
• The concept of using operators or functions in different ways depending on
what they are operating on is called polymorphism.
• Interfaces and classes are inheritable in Visual Basic .NET