A place to practice object-oriented programming (OOP) in JavaScript.
This is the base repository for the Init 2: OOP Practice with Bike Shop goal.
- Open a command line shell such as the Terminal app
- Fork & clone this repository
Fork this repository on GitHub (help) and then clone your fork locally (help) - Install Node.js and npm
Follow the instructions in this Treehouse blog to install Node.js and npm using Homebrew on your Mac. - Do your work in the subdirectories (
bike-shop/
,jsinfo/
,music-player/
)
Be sure to read theREADME.md
files in the subdiretories as well.
This goal makes use of the great exercises in http://javascript.info/ and http://exercism.io/. https://github.com/allyface/oop-practice
https://github.com/breyana/oop-practice
https://github.com/erikasf/oop-practice
Welcome to the second in the series of the initiation goals!
You know the ropes by now, but here's a quick refesher of what this goal contains and how to use it:
- Review Challenge Rating to determine if this goal is appropriately challenging given your current skill level.
- Read the Description to learn what the output of this goal will be.
- Look to the Context for useful background information on why this goal is useful.
- Use the Specifications to know what is needed to complete the goal.
- Explore the Resources such as articles, tutorials, and tools.
This goal will likely be within your ZPD if you...
- Can use fundamental programming contructs: variables, conditionals, loops, data types, functions
- Can write basic JavaScript and execute it in a browser environment
- Have completed the [first initiation goal][bossggle-word-game] (or something similar)
- Have used git and GitHub to do basic tasks like forking, cloning, making commits, and pushing to a remote repository
- Are interested in growing your JavaScript skills
- Are interested in learning to write well-structured code using the principles of object-oriented programming
Object-oriented programming (OOP) is a way of writing and organizing code. It has been around for a long time (by software standards) and is a useful and proven way to design readable, reasonable software.
In this goal, you'll work with your team on a series of JavaScript exercises in the oop-practice repo that focus on core OOP concepts, patterns, and principles.
This goal makes extensive use of the tutorials and exercises on JavaScript.info, especially those in the Objects, classes, inheritance section. It is highly recommended that you make use of this resource, even beyond what is explicitly stated in the specs.
If this is your first time working with Node.js, you will have to install it. You may also want to take some time to go through the Node.js and npm courses on Treehouse (see links in Resources > Courses).
It is recommended (but not required) that you follow along with the day-by-day pace included here. These are designed to help you break down the problem into more manageable parts so that you can pace your work appropriately.
Each day, pay attention to the terms & concepts highlighed in bold. By the end of the day, you should have a better idea of what they mean and how to use them. In other words, aim to be able to answer the question "what is X?" for yourself.
If you work thorugh a full day and have time left over:
- Solidify your learning with the resources provided or
- Start on the next day with your team or
- Attempt the stretch specs
Fork the oop-practice repo into your own GitHub account. Each team member should write code in their own fork, but you should work together and share ideas and solutions as you go.
With your team, complete the specs in Stage 1 to practice working with objects and learn about key/value pairs, object literals, and nested objects.
Complete the specs in Stage 2 to practice working with constructor functions and the "new" keyword, and to learn about object properties, instances and instantiation, and the "this" keyword.
To make sure that you are getting enough challenge, spend the morning working solo on the JavaScript.info exercises and then use the afternoon to work in team on the bike-shop
.
Complete the specs in Stage 3 to practice working with methods and the class pattern, and to learn about prototypal inheritance, getter/setter methods, and the "proto" property.
Depending on how much support you and your team need, balance solo and team time. Make sure to always review the day's work with your team and share important learnings.
Complete the specs in Stage 4 to practice working with classes and classical inheritance, and to learn about the "class", "extends" and "super" keywords in JavaScript.
Depending on how much support you and your team need, balance solo and team time. Make sure to always review the day's work with your team and share important learnings.
With your team, complete the specs in Stage 5 to challenge and practice everything that you've learned so far.
The series of initiation goals are designed for new members of Learners Guild to get oriented to the learning environment, build key foundational skills, and work on some fun projects.
- [Init 1: Bossggle Word Game][bossggle-word-game]
- [Init 2: OOP Practice with Bike Shop][bike-shop-oop]
- [Init 3: Hello Web Servers][hello-web-servers]
- [Init 4: Relational Databases][relational-databases]
- [Init 5: Web APIs][web-apis]
- [Init 6: Developer Tools][developer-tools]
By the time you are finished with these initiation goals, you should be skilled enough to complete the [Simple Book Store][simple-book-store] goal: it is a good target for you to aim for in your first 6 weeks.
This is the second goal. It is designed to introduce you to objects and object-oriented programming in JavaScript (...and also to the Node.js programming environment, indirectly).
By the time you're done with this goal, you will have:
- Modeled a bike shop using object-oriented JavaScript
- Worked through 10+ exercises to challenge your OOP knowledge
- Applied your newfound knowledge to design an object model for a music player app
These are the basic specs for OOP Practice, broken into 5 stages. If you complete these specs, try taking on some of the Stretch specs.
To get started, each team member needs to fork the oop-practice repo. Then, create a gist and add links to each fork to a file in the gist. This is your artifact
.
- [ x] Artifact is set to a gist with links to each of your teammate's forks.
- [ x] Solutions exist in the
jsinfo/
folder for the following exercises from the "Objects" tutorial on JavaScript.info: - [ x] Solutions exist in the
jsinfo/
folder for the following exercises from the "Object methods, 'this'" tutorial on JavaScript.info:- [ x] Create a calculator
- [x ] Chaining
- [x ] All stage 1 tests in the
bike-shop
are passing with source code written inbike-shop/src/stage1-literals.js
.
- [ x] Solutions exist in the
jsinfo/
folder for the following exercises from the "Constructor, operator 'new'" tutorial on JavaScript.info: - [x ] All stage 2 tests in the
bike-shop
are passing with source code written inbike-shop/src/stage2-constructors.js
.
- [ x] Solutions exist in the
jsinfo/
folder for the following exercises from the "Prototypal inheritance" tutorial on JavaScript.info: - [ x] Solutions exist in the
jsinfo/
folder for the following exercises from the "Class patterns" tutorial on JavaScript.info:- [ x]x An error in the inheritance
- [ x] Rewrite to prototypes
- [ x] All stage 3 tests in the
bike-shop
are passing with source code written inbike-shop/src/stage3-methods.js
.
- [ x] Solutions exist in the
jsinfo/
folder for the following exercises from the "Classes" tutorial on JavaScript.info:- [ x] Rewrite to class
- [ x] Solutions exist in the
jsinfo/
folder for the following exercises from the "Class inheritance, super" tutorial on JavaScript.info:- [ x] Error creating an instance
- [ x] Extended clock
- All stage 4 tests in the
bike-shop
are passing with source code written inbike-shop/src/stage4-inheritance.js
.
Design a basic object model for a music player like Spotify or iTunes.
- [x ]
Song
class is defined inmusic-player/song.js
.- [ x] Has properties and methods that you would expect a "song" object to have, at minimum:
.title
,.length
,.album
,.artist
,.track_no
,.play()
,.pause()
.
- [ x] Has properties and methods that you would expect a "song" object to have, at minimum:
- [x ]
Album
class is defined inmusic-player/album.js
.- [ x] Has properties and methods that you would expect an "album" object to have, at minimum:
.title
,.songCount
,.artist
.
- [ x] Has properties and methods that you would expect an "album" object to have, at minimum:
- [ x]
Artist
class is defined inmusic-player/artist.js
.- [x ] Has properties and methods that you would expect an "artist" object to have, at minimum:
.name
,.bandMembers
,.genre
.
- [x ] Has properties and methods that you would expect an "artist" object to have, at minimum:
- [ x]
Playlist
class is defined inmusic-player/playlist.js
.- [ x] Has properties and methods that you would expect a "playlist" object to have, at minimum:
.name
,.songs
,.addSong(<Song>)
,.removeSong(<Song>)
,.play()
,.pause()
.
- [ x] Has properties and methods that you would expect a "playlist" object to have, at minimum:
If you complete all of the specs listed above (the checkboxes), there's no reason to stop there! Keep practicing with these stretch specs.
With these specs, you'll be building an object-oriented version of the [Bossggle word game][bossggle-word-game].
- Bossggle game is copied into the artifact repo under a
bossggle
subdirectory - All JavaScript in Bossggle is rewritten to use an object-oriented style (for example, there is a
Game
class and aWord
class, with instace methods likeGame#reset()
andWord#isValid()
) - Bossggle game is still functional accordign to the core specs
Use these resources to fill in the gaps in your skills and knowledge as you find them. There is more here than you can do in a week, so focus on the areas that are in your zone of proximal development (ZPD).
- MDN: Introduction to Object Oriented JavaScript #js #oop
- MDN: Object-oriented JavaScript for Beginners #js #oop
- MDN: Inheritance in JavaScript #js #oop
- Treehouse: Node.js Basics (2h) #nodejs
- Only need to do the "Introduction to Node.js" section; the others are a bit superflous at this point
- Treehouse: npm Basics (76m) #nodejs #npm
- TreeHouse: Object-Oriented JavaScript Course (134m) #js #oop
- Frontend Masters: JavaScript: From Fundamentals to Functional JS (7h) #js
- Lynda: Foundations of Programming: Object-Oriented Design (3h 1m) #oop
- JavaScript.info #js
- Objects: the basics #js #oop
- Objects, classes, inheritance #js #oop
- Exercism.io: JavaScript Track #js
- JavaScript Koans #js
- Shereef's OO JS videos: scroll to "OO JavaScript" section #js #oop
- Object Oriented JavaScript (1h) #js #oop
- Eloquent JavaScript #js
- Especially the Chapter on Object-oriented Programming #js #oop
[simple-book-store]: {{ site.url }}{% link _goals/69-Simple_Book_Store.md %}
[bossggle-word-game]: {{ site.url }}{% link _goals/251-Init_1-Bossggle_Word_Game.md %} [bike-shop-oop]: {{ site.url }}{% link _goals/252-Init_2-OOP_Practice_with_Bike_Shop.md %} [hello-web-servers]: {{ site.url }}{% link _goals/253-Init_3-Hello_Web_Servers.md %} [relational-databases]: {{ site.url }}{% link _goals/254-Init_4-Relational_Databases.md %} [web-apis]: {{ site.url }}{% link _goals/255-Init_5-Web_APIs.md %} [developer-tools]: {{ site.url }}{% link _goals/256-Init_6-Developer_Tools.md %}