Week 9 Reflections

Classes and Inheritence
Due: 11:59 PM on Sunday, April 4

Weekly Recap

Congratulations! We have finished the ninth week of class. This week, we finished discussing how we can design our own data types using Classes and Object-Oriented Programming, which allow us to represent real-world entities related to the problem we want to solve as actual entities in our programs that have their own unique information and interact with one another. To recap this week:

  • On Monday, we introduced how we can create instances of a class and interact with those instances, after we have written the definition of a class's instance variables and methods. Here, a class defines a type of entity in the world (e.g., Students), whereas instances of the class represent specific entities of that type (e.g., Alice and Bill as two different students). We also discussed the importance of defining a constructor in a class (using the __init__ method), which insures that all of the instance variables of a class are created when a new instance is made in our code, and it also provides an easy to find place to look to help us remember what instance variables are available in a class. We explored these ideas with a class that represents Students for an online educational tool.

  • On Wednesday, we began by finishing up our discussion of constructors, highlighting that it is possible to provide default values for some parameters passed into the constructor (or any other function) so that when we create a new instance and call the constructor, we only need to pass in the information that is unique to that particular instance. For example, most new Students in an educational tool will probably have their accounts created when they are first year students, so we can use a default value of 1 for the year of a student (and not have to pass that in to the constructor unless it is different for a particular student, e.g., a transfer student).

    We spent the rest of the day thinking about how to design classes for a music app (e.g., iTunes or Spotify). We focused on three classes in particular -- Song, Playlist, and Album -- and considered different instance variables we might want to include for each, representing important information about songs, playlists, and albums we need to know in our app. Next, we focused more closely on the Song and Playlist classes and developed a list of possible methods for each, representing different actions we might want to take with songs and playlists in our program. Finally, we implemented these two classes and demonstrated how they might interact in a music app.

  • On Friday, we discussed our final topic related to Object-Oriented Programming -- inheritence. In the real-world, many types of entities are specific versions of some other type. For example, mammals are one type of animal, and people are one type of mammal. Everything that is important about animals is also important about mammals (e.g., the ability to breathe and eat), and everything that is important about mammals is important about people (e.g., being warm-blooded). However, there are properties of mammals that are unique from other animals (e.g., not laying eggs), and there are properties of people that are unique from other mammals (e.g., higher-order reasoning). In Object-Oriented Programming, we can represent the fact that specific types (e.g., people) inherit instance variables and methods from more general types (e.g., mammals) using inheritence, which shortens the amount of code we need to write for more specific types, allowing us to focus only on what is unique to the specific type.

  • In lab, we have been practicing developing our own classes and creating instances of those classes in the Game of Life simulation, where we can also see how relatively simple rules for local interactions can lead to really elaborate emergent behaviors (a concept that is important in biology, economics, artificial intelligence, and many other disciplines).

Your Reflections

In this activity, you have the opportunity to reflect on your own experiences and connections with computer science. In particular, you should answer the following three questions:

  1. What did you learn this week?
  2. What would you now like to know more about?
  3. What connections can you make between something from class this week and your life (e.g., your personal interests, your future goals, your other classes, or society at large)?

You should type up your answers to the above questions in a single document using your favorite word processing software (e.g., Microsoft Word, Apple Pages, Google Docs), save the file as a PDF, and upload it to Gradescope under the assignment "Week 9 Reflections". Each answer should be at least one paragraph of 3-5 sentences (instead of 3-5 sentences total across all answers).

At the end of your document, please indicate that you have followed the honor code on this assignment by writing:

I have adhered to the Honor Code in this assignment.