Attributes - RJAE5/2143-OOP GitHub Wiki
Attributes
One of the main points of encapsulation is bundling different types of items together into one container. These different types of items are known as attributes (AKA Member Variables) when using a class to accomplish encapsulation. Attributes can range from primitive types to other abstract data types (ADT). Each object has their own set of attributes which they manage known as instance variables, unless the attribute was declared using the static keyword, in which case the attribute is a single value shared and managed by all instances, known as a class variable.
Example
class A
{
private:
// Attributes go here
int w;
float x;
double y;
char z;
public:
// Methods go here
};
Important Notes
- Attributes are typically located in the
privateaccess area of a class so they cannot be used/manipulated outside of the class.- This is contrary to methods which are generally how a user will interact with an object, so they should be in the
publicportion.
- This is contrary to methods which are generally how a user will interact with an object, so they should be in the
- Typically, each object has its own copy of attributes, known as instance variables, which the object will manage and manipulate for only itself.