Apply Today to our Software Engineering Program & check out our scholarships!

Back to Setup Page

How to CODE these concepts

We’ve talked at a high level about classes, instances and attributes, and you may be starting to wonder what this will look like in code. That’s what we’ll do next!

Explore Class Syntax

While this may feel uncomfortable at first, research shows this is one of the most effective ways to learn. Instead of your instructor typing code and explaining every character, you are going to read some Ruby code that's already been written. You will likely have some questions about what X or Y is doing, and you'll also likely be able to make some deductions about what other pieces are doing. We will talk through it all after you've had a chance to use your brain and make some connections on your own.

Look at the code in this and think through the guiding questions:

  • What is the name of the class?
  • How many instances are being made?
  • What is the attribute?
  • Can you make another instance?

As a group, let’s discuss what you probably found and maybe had questions about.

Write a New Class

In the previous section, you identified an object in your home and wrote a list of instances and attributes.

In a file, write the Ruby code that would represent that class and instances. Don't forget to print out the instances!

Connection to Apps we Use

Now that you’ve seen how this “factory” concept can be used in code, you may be wondering about how this code concept is used within apps we use every day.

We won’t get all the way there in illustrating it today, but, we can look at Instagram for a moment to talk through where we see some use of classes and instances.

Instagram screenshot with annotations for user profile class and post class.

Next: Build Your Own Class