General Info: Class Visibility SpecifiersIn OOP languages, members of a class have a specific scope that indicates visibility. Standard visibility includes private, protected, and public. Private members are usable by the defining class only (fully encapsulated). They are invisible outside of the class except by friendly classes. Protected members are usable by the defining class and descendant classes only (plus friendly classes). Public members are usable wherever its class can be referenced.Languages Focus: Member VisibilityTraditional member visibility specifiers for fully OOP languages are private, protected, and public. Many modern OOP languages implement additional member visibilities. Additional member modifiers are documented under the Member Modifiers topic. ASP Classic Member VisibilityThe member visibility modifiers are Private and Public. If not specified, the default is Public. Private and Public have the usual meaning. Private members are visible only within the class block. Public members are visible within the class and outside of the class. Syntax Example:
Class Cyborg Private FSerialNumber Public FCyborgName Public Function IntroduceYourself() End Class
Note: ASP Classic does not have nor need protected visibility because ASP does not support inheritance.
Public Properties Use a Private Member FieldA common technique for implementing a class property in ASP is to use a public property with a private member field to store the value. Class Cyborg Public Property Let CyborgName(pCyborgName) End Class Working ExampleHere is a working example using the class above. This example demonstrates implementing a public property, a public method, and a private member field. In addition, it demonstrates creating an object instance, using the members, and finally cleaning up by setting our object instance variable to nothing. <%@LANGUAGE=VBScript%> <body> <h1>Introduce Yourself</h1> 'Declare object instance variable. 'Create object instance from class. 'Use members. Cameron.CyborgName = "Cameron" 'Cleanup object instance so we don't have memory leaks. Set Cameron = Nothing </body> </html> 'Class code block. 'Class member field. 'Class property - get value. 'Class property - set value. Public Property Let CyborgName(pCyborgName) 'Class method. Public Function IntroduceYourself() Business ObjectsA business object in this case means a class that represents a problem domain element that has attributes and methods. Examples might include a member, customer, vendor, employee, invoice, item, newsletter, etc. Suggested implementation details:
|
|