Created
March 10, 2016 22:43
-
-
Save kidap/b4736030089ad4382e4f to your computer and use it in GitHub Desktop.
W1D4 Readings & Questions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q1: What is an instance variable? | |
- instance variable is a variable that is owned by an instantiated object. | |
Q2: The 4 Pillars of Object Oriented Programming are Abstraction, Encapsulation, Inheritance and Polymorphism. Describe each one. | |
Abstraction - to "hide" the logic and control what can be accessed or called by other objects | |
Encapsulation - to combine related objects, data and operations into a single unit | |
Inheritance - enable objects to receive/inherit the properties/attributes and methods without requiring it to re-declare or re-implement it | |
Polymorphism - allows the properties and methods of subclasses to have a different behavoir. | |
Q3: | |
a) As my next business venture, I want to open a bicycle rental shop, and I want an app to help me organize it. The app will need to keep a list of all bicycles in inventory. At any given time, a bicycle may be in one of 3 states: waiting for maintenance, ready to rent, or rented. | |
I have a few mechanics, each of whom can only fix 1 bike at a time. Each time the mechanic finishes with one bike, it becomes ready to rent, and each time a customer returns a bike, it needs to be checked for maintenance. When a mechanic is done fixing a bike, he must be assigned another one waiting for maintenance. | |
If you were to write an app for my shop, how would you design your object model? | |
Clas Shop | |
- properties: bikeBeingFixed (Bike class), bikesForRent(Array of Bike), bikesToBeChecked(Array of Bike), mechanics(Array of Mechanic) | |
- methods: getNextBikeForRent, getNextBikeToBeCheck, addBikeForRent, addBikeToBeCheck | |
Class Bike | |
- properties: states | |
Class Mechanic | |
- properties: bikeCurrentlyFixing | |
- method: startFixingBike, justFinishedFixingBike | |
b) Now, assume my mechanics take 1 hour to fix each bike. But to keep business moving, I also want to hire junior mechanics, each of whom can fix a bike every two hours. How does this change your object model? | |
Class Mechanic | |
- properties: bikeCurrentlyFixing **ADD seniority and timeToFinishFixing | |
- method: startFixingBike, justFinishedFixingBike |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment