Ship Object ;TLDR
A user story outlines one piece of functionality an application should have, from the perspective of the person using that functionality. Applications are typically made up of many user stories that will be outlined before development starts. As developers, it's our job to translate these user stories into objects, methods and properties. We call this domain modelling.
Let's have a look at a user story:
The first and second lines of the user story give us some context about who is using the functionality and why. The third line is what we'll translate:
Firstly we look for nouns. These are usually our objects. However, if a noun is possessive (it has ownership of another noun) then the noun possessed could be a property. Lets see how the above line might translate into an object:
Object | Methods | Properties |
---|---|---|
Animal | name |
If we come across verbs then these often indicate methods. Lets have a look at another example:
The line we look at here is:
This could be translated to:
Object | Methods | Properties |
---|---|---|
Basket | add | products |
An add
method is assumed here because of the verb add
. products
is assumed as a property, as Basket
possesses products
.
Challenge
Your challenge is to use domain modelling to translate the following user story into an object with properties and/or methods, to write any tests necessary for the user story, and to write the code that makes the test(s) pass. The user story is:
To complete this challenge, you will need to:
- Discuss with your classmates what the domain model would look like for the above user story. Would recommend a pen and paper for this step.
- Create a new test file, which should
describe
your constructor. - Create a new test spec (
it
) for ensuring an instance of your object can be created. - Write the code that makes this test pass.
- Create another test spec for each property and/or method you identify.
- Write the code that makes this test pass.
- Add, commit with a meaningful message, and push to GitHub.