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
- Post
- Like
- Retweet
- Follow
- increaseLikes
- Show
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!