Sunday, November 22, 2009

Is VB Script Supports OOPS Concept . . .

My answer for this is No but Yes.
To supports the OOPs concept, the script needs to be satisfy the OOPs principles.

OOPS Principles -
1.Encapsulation
2.Inheritance
3.Polymorphism

Lets write a script to satisfy each principle -

Encapsulation - The wrapping of data and function into a single unit (Called class) is known as Encapsulation.

Example -

Class Maths

Function add(a,b)
MsgBox "Sum = "&a+b
End Function
End Class

Set Mat=New Maths
res=Mat.add (2,3)

'************************************************************************************

Inheritance - It is the process by which object of one class acquire the properties of object of another class.

'Example -

Class Outer
Function test()
Set inn= New Inner
inn.display
End Function

End Class

Class Inner
Function display()
MsgBox "This is inner class"
End Function
End Class

Set out=New Outer
out.test()

'************************************************************************************

'Polymorphism - Polymorphism means the ability to take more than one form/methods

Example -

Dim idno, name, marks
Class Student

Function SetData()
idno="10"
name="arun"
marks="300"
End Function

Function getData()
MsgBox "Idno "&idno
MsgBox "Name "&name
MsgBox "Marks "&marks
End Function

End Class

Class Student2

Function SetData(a,s,m)
idno=a
name=s
marks=m
End Function

End Class

Set Std1=New Student
std1.SetData()
std1.getData()
Set std2=New Student2
std2.SetData "12","Singh","400"
std1.getData()


I am trying to say Yes, it supports OOPS concept. But if any body is having any questions or my assumption is wrong then please post here as a comments.

*************************************************************************************