Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Object-Oriented Swift Value vs Reference Types Final Exam - Solution

"...Now you understand Object Oriented Programming..." --> objects haven't been mentioned since the introduction.

This course really needs to link the concepts that is taught to the overall theme of the course: Object Oriented Programming.

After successfully completing all the challenges i still have the following Questions:

Q1: What is an object?

Q2: Why is it called Object Oriented Programming?

Q3: Why do we use Object Oriented Programming?

2 Answers

Hey Andreas Vestergaard!

Which of the videos have you been through before this one? Are you following the track swift track?

Nathan Catania
Nathan Catania
4,140 Points

What is an object?

When we create an instance of our defined class, this is called creating an Object of that class. As we add code and functionality to a class, what we are essentially doing is defining a "Blueprint". When we create an instance of a class we are creating or building our Blueprint into existence. As long as we have our Blueprint (class definition), we can create as many Objects from it as we like. However, while our Blueprint defines the nature and functionality of our Object, each Object can have different properties; and thus be very different from every other object.

The above and this whole concept is far easier to understand with examples.

Lets say that you have defined a class called Chair that contains the length, width, height, and color of the chair. This is our Blueprint. Each time we create an instance or Object of the Chair class, we are creating a new chair with its own individual length, width, height and color properties. If I create 3 Chair Objects, I could make one a blue chair, one a red chair, and the other to be a green chair. I now have 3 physically different chairs (Objects) that I have created from my single blueprint (class).

Think of a factory with an assembly line. Assume this factory makes toys. Each time we create an Object from a class, another toy is created on the assembly line and is added to the conveyor belt. Each toy can have a different size, shape and color, however we have created the overall structure of the toy from the same Blueprint.

Another example would be if we define a class called Vehicle. In this class we can define things like the model, color, weight: All things that describe what a Vehicle is like. Let's say I create 3 objects from the Vehicle class and call them the following: "Car", "Truck", and "Bike". I can initialise each of them with the following properties:


Model == "Ford", Color == "Blue", Weight == 900


Model == "Mercedes", Color == "Red", Weight == 5000


Model == "BMW", Color == "White", Weight == 70

These properties might not be realistically accurate, nor do they correspond to a specific programming language; it is simply pseudocode to represent a point.

You can see that each of my 3 Objects has its own individual properties, however each was created from the same blueprint (class).

I hope that helps! While Objects are not always physical things, it is handy to think of them as such while learning OOP.