.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> Windows Application >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Program for State Pattern in Vb.net

Posted By:Narayanan       Posted Date: April 16, 2013    Points: 200    Category: Windows Application    URL: http://www.dotnetspark.com  

Today we will discuss about the State Pattern in Vb.net
 

Description:
    State pattern allows an object to change its behavior depending on the current values of the object. Consider the figure 'State pattern example'. It's an example of a

BoxStatusoperation. If the state of the BoxStatusis off and you press the switch the BoxStatus will turn off. If the state of BoxStatus is on and you press the switch the BoxStatus will be off. So

in short depending on the state the behavior changes.
Create a Class file in the Vb.net Project


  Enum BoxStatus
        BoxOn = 1
        BoxOff = 2
    End Enum
Public Shared defaultBoxstatus As BoxStatus = BoxStatus.BoxOff
Public Function displayMessage() As String
        If BoxStatus.BoxOn = defaultBoxstatus Then
            Return "Box is on"
        Else
            Return "Box is off"
        End If
End Function
Public Sub Pressswitch()
        If defaultBoxstatus = BoxStatus.BoxOn Then
            defaultBoxstatus = BoxStatus.BoxOff
        Else
            defaultBoxstatus = BoxStatus.BoxOn
End If
End Sub
Form Code

Paste this Code on your Button click Event:
Dim Clas As New Class1()
  Clas.Pressswitch()
  MessageBox.Show(Clas.displayMessage())

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend