14-09-2017, 10:13 AM
Shared members are properties, procedures, and fields that are shared by all instances of a class or structure. Some programming languages refer to elements such as static members.
Shared fields and properties
Shared fields and properties are useful when you have information that is part of a class but is not specific to any instances of a class. When you change the value of a shared field and property, the value associated with the class and all instances of the class changes.
On the other hand, changing the value of a non-shared field or property associated with an instance does not affect the value of that field or property in other instances of the class. Unshared fields and properties exist independently for each instance of a class.
Shared fields and properties behave as global variables that can only be accessed from instances of a class, or with class name qualification. Without fields and shared properties, you would need to use module-level variables to achieve the same effect. However, module-level variables can make your classes difficult to understand and maintain. In addition, using module-level variables in this way violates the encapsulation concept that classes represent.
Shared fields and properties
Shared fields and properties are useful when you have information that is part of a class but is not specific to any instances of a class. When you change the value of a shared field and property, the value associated with the class and all instances of the class changes.
On the other hand, changing the value of a non-shared field or property associated with an instance does not affect the value of that field or property in other instances of the class. Unshared fields and properties exist independently for each instance of a class.
Shared fields and properties behave as global variables that can only be accessed from instances of a class, or with class name qualification. Without fields and shared properties, you would need to use module-level variables to achieve the same effect. However, module-level variables can make your classes difficult to understand and maintain. In addition, using module-level variables in this way violates the encapsulation concept that classes represent.