A lot of native data types of date/time, numeric, and string fields don’t work when you try to model a lot of real world situations. They are good for a portion of the information, but not all. For example, if I wanted to store information about a player in a computer game, no one of those data types would work. This would mean I would need to create several variables to store all of the information. This can make creating and passing the information to functions time consuming and difficult to manage..
Instead, we need to create our own types of data that stores the data we need.
Most programming languages allow you to create your own data types. Sometimes referred to as a User Defined Data Type, or Programmer Defined Data Type.
User Defined Types May Have User Defined Types Within Them
You may also find that your custom data type has other custom data types in it. Think about that HR application, each employee would be of a user defined type. With the employee they would have an address. An address isn’t a data type…unless you custom make one for it, which would store things like the street address, city, state/providence, country, etc.
How Data is Stored
Just the Data (Structs)
Some languages (C for example) allow you to define a custom data type. In C, this is called a struct, and it only holds data. Other languages also have data only user defined types.
struct gamerInfo {
int accountNumber;
char *gamerName;
int coinCount;
int level;
};
While you can store and use the data here, the data is accessible to any/every one. There are no methods to help with error checking, or ways to protect the data.
gamerInfo playerOne; // created, but no values exist for the data
gamerInfo playerTwo = { 1234, “Robbie”, 12, 16 }; // initialized with values
Object Oriented Data
Object Oriented Programming is about more than just storing custom data types. It is a whole methodology about storing data in a manner that is protected from other similar collections of data. It does this by providing a set of functions, called methods in object oriented parlance, that allow, and restrict access to the data contained within.
You can think of a class as a recipe on how to make this custom data type. It can be used to build an object later. As a recipe, the class doesn’t do anything, but it does define what it will look like when it is created. When a class is created, an object is made. An object is an instance of the class, and is used in the actual program.
User Defined Data Types was originally found on Access 2 Learn