Browse DevX
Sign up for e-mail newsletters from DevX


Manage VB6 Code Complexity with the State Behavior Pattern : Page 3

VB6 can be prone to disorganization and the State behavior pattern is a consummate organizer. Use it proactively to prevent spaghetti code or reactively to manage code complexity.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Manage Code Complexity
Patterns are architectural strategies that describe solutions for known kinds of problems. This article discussed the State pattern, which is a behavior pattern. The State behavior pattern supports dynamic reclassification, which is changing the behavior of a context (like a form) at runtime.

To implement the State pattern in VB6, define an interface that defines all of the properties and behaviors of your context. Then implement a specific instance of the state interface for each behavior that the context—a form in this example—supports. Add more state classes to support additional states. Each state's code is independent of the others.

Using state objects is referred to as behavior delegation. Behavior delegation can be used proactively to prevent spaghetti code or reactively if code grows beyond a manageable level of complexity.

Paul Kimmel is a software architect and author who has written several books on .NET programming. Contact him if you need assistance developing software or are interested in joining the Greater Lansing Area Users Group for .NET (glugnet.org).
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date