Object Oriented Programming (Notes)
Object Oriented Programming (Notes)
• Object: The instances of a class which are used in real functionality – its variables
and operations
• Methods: Methods define the behavior of objects, allowing them to perform specific
actions or operations.
• Attribute: Attributes represent the properties or characteristics of objects, defining
their state.
• Events: Events can be user interactions, such as clicking a button, typing on a
keyboard, or moving a mouse.
• Message: Messages are used for communication and interaction between different
components, modules, or systems within a software application or across a network.
• Receivers: refers to a component, device, or entity that is responsible for receiving
and processing messages, signals, or data from a sender or transmitter.
• Recursive Design: Every object has its own memory, which stores other objects.
• Classes: Classes are blueprints or templates for creating objects. They define the
structure and behaviour of objects by encapsulating data and methods.
SB CREATIVE
2
• Single Responsibility Principle (SRP)- A class should have only one reason to change
• Open Closed Responsibility (OCP)- It should be able to extend any classes without
modifying it
• Liskov Substitution Responsibility (LSR)- Derived classes must be substitutable for their
base classes
• Dependency Inversion Principle (DIP)- Depend on abstraction and not on concretion
• Interface Segregation Principle (ISP)- Prepare fine grained interfaces that are client
specific.
Lecture # 02
SB CREATIVE
3
SB CREATIVE
4
Lecture # 03
a) Public Access:
when a class member is declared as public, it means that it is visible and accessible
to all other parts of the program.
Public Class MyClass
Public publicField As Integer ' Public field
b) Private Access:
when a class member is declared as private, it means that it is hidden from outside
the class.
Public Class MyClass
Private privateField As Integer ' Private field
SB CREATIVE
5
c) Private Access:
When you declare a member of a class as Protected, it means that the member is
accessible within the class where it is declared and within any class derived from
that class (i.e., subclasses or child classes), but it is not accessible from outside the
class hierarchy.
Public Class MyBaseClass
Protected protectedField As Integer ' Protected field
SB CREATIVE
6
a) Single Inheritance:
In single inheritance, a subclass inherits from only one superclass.
b) Multiple Inheritance:
In multiple inheritance, a subclass inherits from multiple super classes.
c) Multilevel Inheritance:
In multilevel inheritance, a subclass inherits from another subclass, creating a
hierarchical chain of classes.
d) Multilevel Inheritance:
In hierarchical inheritance, multiple subclasses inherit from a single superclass.
SB CREATIVE
7
e) Hybrid Inheritance:
Hybrid inheritance is a combination of two or more types of inheritance. It often
involves multiple and multilevel inheritance, leading to a complex class hierarchy.
SB CREATIVE
8
Lecture # 4
SB CREATIVE
9
Lecture***Debugger
SB CREATIVE
10
Lecture***(OOSE)
SB CREATIVE
11
SB CREATIVE
12
SB CREATIVE
13
SB CREATIVE
14
Lecture***(OOSE)
SB CREATIVE
15
SB CREATIVE
16
Lecture***Objects in VB
Q1: -Define the Object? Also Describe to create object from a class.
Ans: Each object in Visual Basic is defined by a class. A class describes the variables,
properties, procedures, and events of an object. An object is a combination of code and data
that can be treated as a unit. An object can be a piece of an application, like a control or a
form.
Create an object from a class:
1. Determine from which class you want to create an object.
2. Write a Dim Statement to create a variable to which you can assign a class instance.
The variable should be of the type of the desired class.
3. Dim nextCustomer As customer
4. Add the New Operator keyword to initialize the variable to a new instance of the class.
5. Dim nextCustomer As New customer
6. You can now access the members of the class through the object variable.
7. nextCustomer.accountNumber = lastAccountNumber + 1
SB CREATIVE
17
Methods:
A method is an action that an object can perform. For example, Add is a method of
the ComboBox object that adds a new entry to a combo box.
The following example demonstrates the Start method of a Timer object.
Events:
Events represent occurrences or happenings within an object. They allow other parts of the
program to respond to actions or changes in the object's state. Events are declared using
the “Event” keyword. For example:
Public Event PropertyChanged As EventHandler
Instance Members:
When you create an object from a class, the result is an instance of that class. Members that
are not declared with the Shared keyword are instance members An instance member
variable can have different values in different instances.
Shared Members:
A shared member exists only once, no matter how many instances of its class you create, or
even if you create no instances. A shared member variable, for example, has only one value,
which is available to all code that can access the class. Members declared with
the Shared keyword are shared members.
SB CREATIVE
18
• OLE Embedding:
Embedding means if one window application document contains a copy of other
window application document. This enables compound documents where different
types of data, such as text, images, charts, spreadsheets, or even entire documents,
can be combined into a single container.
• OLE Linking:
Linking means that the container application that contains a pointer to the original file.
his enables compound documents where different types of data, such as text, images,
charts, spreadsheets, or entire documents, can be dynamically linked together.
SB CREATIVE
19
Lecture***Modular Programming
SB CREATIVE
20
SB CREATIVE
21
The following are the requirements when naming the variables in Visual Basic:
Ans: In Visual Basic (VB), variables are declared, using name of variables (Dim, public,
private, etc.) and optionally its data type. The syntax to declare a variable in Visual Basic is
as follows:
SB CREATIVE
22
Ans: Encapsulation is the process of wrapping data and related functions into a single
unit (object). Encapsulation limits access to object data and methods, preventing their
misuse and ensuring their proper functioning. Let's take an example of mobile device. With
the help of mobile devices, you can perform various functions like taking a picture, sending
a message, recording video/ audio, access the web and much more.
The features mentioned above are functionalities of most of the smartphone. However, you
don't need to understand the internal functioning details of those features before using this
program.
Ans: Polymorphism, in the simplest terms, means "many forms." In the context of Object-
Oriented Programming (OOP), polymorphism allows objects of different classes to be treated
as instances of a common superclass. polymorphism enables code to be written in a way
that is more flexible and adaptable to different types of objects, promoting code reusability,
extensibility, and ease of maintenance.
For example, you have a smartphone for communication. The communication mode you
choose could be anything. It can be a call, a text message, a picture message, mail, etc. So,
the goal is common that is communication, but their approach is different. This is
called Polymorphism.
SB CREATIVE
23
SB CREATIVE
24
Lecture***Built in Functions
Ans: In Visual Basic (VB), MsgBox() is a built-in function used to display a message box
(dialog box) to the user. It is commonly used for showing informational messages, warnings,
errors, or asking for user input in VB applications. It provides various options for customizing
the appearance and behaviour of the message box based on the requirements of the
application.
returnVal = MsgBox (prompt, styleVal, title)
Ans: The prompt parameter is a string value (either a string literal or a string variable) that
supplies the message to be displayed.
Ans: The styleVal parameter is either an integer style value from 0 to 5, or a named constant
that can be used instead of the corresponding integer value, that determines which command
buttons will appear on the message box
Ans: The returnVal value returned by the MsgBox() function is an integer value that
indicates which button the user has clicked in response to the message box being displayed.
Ans: The InputBox() function in Visual Basic (VB) is a built-in function that displays a dialog
box to prompt the user for input. It allows developers to obtain input from the user, such as
text or numeric values, in a convenient and user-friendly manner. The user's input can then
be captured and used in the VB application.
SB CREATIVE
25
Ans:
Function Description
Microsoft.VisualBasic.left Returns the n left-most characters from the text string referred
(str, n) to by str.
Microsoft.VisualBasic.right Returns the n right-most characters from the text string referred
(str, n) to by str.
Removes the white space (if any) at either end of the text string
Trim (str)
referred to by str, and returns the result.
Removes the white space (if any) at the left-hand end of the text
LTrim (str)
string referred to by str, and returns the result.
Removes the white space (if any) at the right-hand end of the
RTrim (str)
text string referred to by str, and returns the result.
SB CREATIVE
26
"General Date" Displays the date and time in the format: dd/mm/yyyy hh:mm:ss
SB CREATIVE
27
Lecture***Data Control
Q1: -What is Data Control? And how they connect with Database?
Ans: Data Controls" are components or objects that allow you to interact with data from a
database within your application's user interface. These controls provide a visual
representation of data and enable users to view, manipulate, and update it without directly
interacting with the database.
To connect the data control to this database, double-click the DatabaseName property in
the Properties window and then click on the button with three dots on the right to open a
file selection dialog. From the dialog, search the folders of your hard drive to locate the
database file NWIND.MDB.
Lecture***Data Control
Q1: -Define Operator? Also Describe the Arithmetic, Conditional & Logical
Operators.
Ans: An operator is a symbol or keyword that performs an operation on one or more
operands, producing a result. Operators are fundamental building blocks in programming
languages, enabling you to perform various computations, comparisons, and logical
operations.
Ans: If statement is used to conditionally execute a block of code based on the evaluation
of a Boolean expression. Here's an overview of the If statement syntax in VB:
1. Simple If Statement:
If condition Then
End If
if the condition evaluates to True, the statements within the If block are executed. If the
condition is False, the statements are skipped.
Example:
Dim x As Integer = 5
If x = 5 Then
End If
SB CREATIVE
29
2. If...Else Statement:
If condition Then
Else
End If
if the condition is True, the statements within the first block are executed; otherwise, the
statements within the Else block are executed.
Example:
Dim x As Integer = 3
If x > 5 Then
Else
End If
3. If...ElseIf...Else Statement:
If condition1 Then
End If
SB CREATIVE
30
Lecture***Data Control
Case value1
Case value2
Case Else
End Select
Example:
Case 1 Case 7
Console.WriteLine("Sunday") Console.WriteLine("Saturday")
Case 4
Console.WriteLine("Wednesday")
Case 5
Console.WriteLine("Thursday")
SB CREATIVE
31
1. For...Next Loop:
The For...Next loop executes a block of code a specified number of times. It's commonly
used when you know the number of iterations in advance.
For index As Integer = 1 To 5
Console.WriteLine("Iteration {0}", index)
Next
2. Do...Loop:
The Do...Loop statements execute a block of code repeatedly until a specified condition is
met. There are different variations of Do...Loop, such as Do While...Loop, Do Until...Loop,
and Do...Loop While and Do...Loop Until.
Dim count As Integer = 0
Do While count < 5
Console.WriteLine("Count: {0}", count)
count += 1
Loop
3. While...End While
The While...End While statements execute a block of code as long as a specified condition
is True.
Dim x As Integer = 0
While x < 5
Console.WriteLine("Value of x: {0}", x)
x += 1
End While
SB CREATIVE
32
Lecture***Programs
SB CREATIVE