Project Stage B - Data Structures
You can "discover" data items and groups by looking
at the nouns in your user-stories. Consider the Fair Trade example:
Fair Trade is an organisation that sells products from partner organisations in
Developing Countries. It attempts to give the suppliers a price that will enable
them to live a decent, if poor, life rather than exploiting them as some
multi-national clothing companies have notoriously done.
Here is the same "story" with all the nouns highlighted:
Fair Trade is an organisation that sells products from partner organisations in
Developing Countries. It attempts to give the suppliers a price that will enable
them to live a decent, if poor, life rather than exploiting them as some
multi-national clothing companies have notoriously done.
You won't need variables for every noun, but the nouns give you some
ideas for variables:
If you were actually writing a project for this scenario, you would have
already done Stage A. But you can still reflect on some ideas:
- An organisation
might need an account
so they can log-in and search for suppliers
- A supplier
will exist in a specific country
(or countries in a global economy)
- A supplier
might have a LIST of products
that they sell
- Each product will
have a name and
a price
- A product
might have several prices depending
on the size of the order
(discounts for larger orders)
- etc
Looking at the thoughts above, we see that each item has a name
and connections/relationships to other data items.
Enter OOP
In OOP, we try to group together connected ideas. Compare an
old-fashioned program to an OOP program:
Traditional Approach
|
OOP
|
String organization = "Starbucks"; String password
= "starry night"; String supplier = "Coffee Growers
Union"; String country = "Honduras"; String
product = "coffee"; double price = 3.50;
// ******************************
// What if the supplier has a list of // various products
that they sell?
// What if we want a list of all the suppliers // who sell
coffee?
// Traditional programming methods // make it difficult to
create lists.
|
class Organization { String name; String
password; }
class Supplier { String name; String
country; Product product; }
class Product { String name; double price; }
//*** Now making lists is easy *****************
Organization[] orgs = new Organization[1000];
Supplier[] sups = new Supplier[1000];
//*** We should rewrite the Supplier class *********
class Supplier { String name; String
country; Product[] product = new Product[1000]; }
//*** Not all lists should be 1000 items, //*** but that
will probably work for most projects.
|
The OOP version requires some extra code ( the class command ), but is a
lot more flexible and saves work in the long run.
Discovering Data for Your Project
Look back at the user-stories and sample data you collected in stage A or
your project. Then
do a similar analysis to the one above. Make sure you find examples for
all the following :
- a String variable
- a numeric variable
- several data items that are connected
- some data item that needs to be stored in a list
- a variable that needs a class to store several related items
- sample data for each item, including at least 3 samples
for any lists and a complete sample for any class