GithubHelp home page GithubHelp logo

playlister-rb-pca-000's Introduction

Object Associations: Playlister

Objectives

  1. Implement three separate classes that relate to one another via belongs to, has many and through associations.
  2. Practice writing instance and class methods.

Overview

This is your first introduction to the "Playlister" domain model. In this first iteration, we'll be building a class for Song, Artist and Genre. A song will belong to an artist and an artist will have many songs. A song belongs to a genre and a genre belongs to a song. So, an Artist has many genres through their songs.

Instructions

For the most part, this is a test-driven lab. Follow the test output to define your classes with the appropriate attributes. The guidelines below are meant to help you build the associations. Read them through first, then proceed through the test suite by running learn --fail-fast. Refer back to these guidelines to help you pass tests related to associations.

Belongs To and Has Many Associations

  • Artists should have many songs:
    • Individual instances of the Artist class should be initialized with an empty @songs array. Create an attr_accessor for songs so that an artist can access their songs and add to them.
    • Your add_song method will take in an argument of a song instance and push that song instance into the artist's songs array.
  • Songs should belong to an artist:
    • The Song class needs an attr_accessor for artist.
    • At what point in time does a song become associated with an artist? In the real world, that happens when an artist writes a song. So, the add_song instance method on the Artist class should not only push a song into that artists songs array but set the song's artist attribute equal to the artist that you are operating on.
  • Genres should have many songs.
    • The Genre class should have an attr_accessor, songs.
    • The Genre class should initialize with an empty array, @songs.
  • An instance of Song should belong to a genre. At what point do a genre and a song get associated to one another? This decision is a little more flexible than our decision to associate artists and songs in an artist's add_song method. For the purposes of passing the tests, however, we'll say that a genre and a song become associated to one another when a song's genre is set.
    • Write out the .genre=(genre) setter method in the song class explicity. In it, set the @genre variable equal equal to the genre that will be passed in as an argument. Also in this method, push the song instance (i.e. self) into that genre's .songs array.
    • The Song class will also need an attr_reader for genre.

Through Associations

An artist has many genres through his or her songs and a genre has many artists through it's songs.

  • Write a genres instance method in the Artist class that iterates over that artist's songs and collects the genres of each song.
  • Write an artists instance method in the Genre class that iterates over that genre's songs and collects the artists of each song.
  • Make sure the .genres method returns a unique lists of genres (no duplicates!). The same goes for the .artsits method.

Note

When writing and calling the .genre=(genre) method for the Song class, keep in mind that the object being passed in is an entire Genre object, not a String representation of the Genre. For example, #<Genre:0x007fbdca31ed88 @name="rap">, not 'Rap'. Similarly, when you call the .add_song method on an instance of Artist, the argument being passed in is *an instance of the Song class.

View OO Playlister Ruby on Learn.co and start learning to code for free.

playlister-rb-pca-000's People

Contributors

scottcreynolds avatar loganhasson avatar sarogers avatar kthffmn avatar sophiedebenedetto avatar ahimmelstoss avatar fislabstest avatar changamanda avatar benjagross avatar aviflombaum avatar fs-lms-test-bot avatar pletcher avatar fhernandez173 avatar gillianwenhold avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.