- Home /
Question is off-topic or not relevant
Why do we create instances of classes in OOP?
I'm learning C# and I want to know WHY we create instances of classes.
Customer myCustomer = new Customer();
myCustomer.name = "harry";
When I search online I always get "How to make instances" but that's not my question. I know how to make them. Why is my question. Is it because we use them like datatypes. Like complex datatypes.
I just want to get my head around it so I can improve my coding. Thanks very much! :)
Answer by Bunny83 · Feb 10, 2014 at 11:22 AM
We use them like datatypes because they are datatypes, complex datatypes ;)
A class itself is just some kind of blueprint of an object. If you're familiar with databases you could say a class is a table definition (which defines what the columns of the table looks like) and an "instance" would be a single row in that table.
If you have a class "Human" the class just describes how an instance of a human looks like, but the class itself is not an instance.