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.

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

6 comments:

Anonymous said...

wonderful ..................................................

Anonymous said...

In inheritance, what you said is correct.But,We need parent class futures into subclass, with out creating of parent class Object in sub class. It is not possible in VbScript.

DataDiary.com said...

it just awesome and really interesting...

rohit barde said...

whatevery you have mentioned in example is not inheritance, it is composition.

Anonymous said...

How can you inherit in a different scrpt?

QTP training said...

Your information about qtp is really interesting. Also I want to know the latest new techniques which are implemented in qtp. Can you update it in your website?

About Me

My photo
Hi all,I am Arun Singh Rajaputra. I am working as a Project Lead in a reputed organization in Hyderabad, AP, India. I have little bit knowledge on Quick Test Professional and like to share my knowledge to all through this blog.

Subscribe to get updates on this blog

Enter your email address:

NOTE

Some of the posts posted in this blog are collected and most of them have been prepared by me. If any one have objections regarding any copied posts. Please mail me so that I can take a necessary action on that post.