What are Classes, Structs, and Enumerations?

Josh KuehnIndie, iOS, SwiftLeave a Comment

The aim of this post will be to broadly cover topic of WHAT are classes, structs, and enumerations. I won’t be going into how or when to use them but simply how they fit into programming. I’ll be explaining why they’re used and what purpose they serve when creating a program.

Why are classes, structs, or enumerations used?

Think of them like blue prints you might create to tell someone about a goldfish. A goldfish is indeed an object because it can be seen and touched. How do we define goldfish? They’re usually yellow, small, and can swim.

If you were writing a program about goldfish this is exactly where you’d start! You might create a class or structure and inside of it put the different details about them that we listed above. What can be inside of a class, structure or enumeration can vary and is greatly determined by what language you’re writing with (I’m using Swift).

Classes, structs, and enumerations are used to represent an object inside of your program. When I started programming I visualized a new program as an empty white room. The only way to start filling it with objects is to create classes, structs, or enumerations that describe what I want to make and use.

What are their purpose when creating a program?

Classes, structs, and enumerations serve many purposes but one of the most important is to organize your program. Organization is key to maintaining a program. When you look at your classes they’ll contain variables and functions that your class uses.

To sum it up classes, structs, and enumerations can all be boiled down to the building blocks of your program. The program you’re making is a house and the bricks are the classes, structs, and/or enumerations. If we go a little deeper we could say that each type of room (living room, bed room, bathroom, etc…) in your house is a class, structure, and or enumeration. Seems pretty ambiguous huh? That’s why it’s called Object Oriented Programming and not Class, Structures, and Enumerations Oriented Programming. You use these building blocks to represent anything in your program.

Thanks for reading! If you found this helpful be sure to share so that others can also gain from this post.