Skip to content

Instantly share code, notes, and snippets.

@LeilaniL
Created September 2, 2020 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeilaniL/324ddd5fd0359fdb528aac1f2862cee4 to your computer and use it in GitHub Desktop.
Save LeilaniL/324ddd5fd0359fdb528aac1f2862cee4 to your computer and use it in GitHub Desktop.
Steps-for-Planning-OOP-Project

1) Look at your specs and/or user stories

2) Highlight nouns in specs--those are likely candidates for objects

3) Highlight verbs in specs--those are likely candidates for methods

Note: Figuring out what objects should hold those methods can be a challenge, but generally an object should track its own info/be responsible for itself.

Nouns = objects

  • User
  • Tweet
  • Newsfeed

Verbs = methods that go along with an object

User

  • Post
  • Like
  • Retweet
  • Follow

Tweet

  • increaseLikes

Newsfeed

  • Show

4) Code!

function User(name) {
  this.userName = name;
  this.tweets = [];
  this.followers = []
  this.follows = [];
}
User.prototype.post = function (message) {
  var newTweet = new Tweet(message);
  this.tweets.push(newTweet);
}
User.prototype.like = function (tweet) {
  tweet.likes += 1;
}

function Tweet(text) {
  this.text = text;
  this.likes = 0;
  this.retweets = 0;
}

function Newsfeed() {
  this.posts = []
}

Newsfeed.prototype.show(userId) {
// will get list of posts by all that user is following
}

And so on and so forth! 😄

More resources: The Lynda/LinkedIn Learning* course Programming Foundations: Object-Oriented Design is helpful and very approachable but it's better if you've already learned about classes and some basics of OOP.

*Seattle (and Portland?) library card holders already have subscriptions to Lynda!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment