Tuesday, March 23, 2010

Assessment Item 2.

"A hermit lives in a cave. The cave's location within the world is determined by x, y & z coordinates. The hermit's name is Freeda and she is 100 years old. Many animals also live in the cave and they can talk. All of the animals have a first name & age. There are bats which fly & screech & there are lizards that run, hide & sing."

Below is my diagram for the above scenario, Basically my print screen is broken so this is a tad bit outdated, namely the return types aren't listed for the 'getters' but its pretty obvious anyway.

Monday, March 15, 2010

Objects with the new operator aka "a Constructor"



The constructor of the class allows for each object of 'Super Mario' to have a different amount of health and lives. Otherwise other details are the same.

Tuesday, March 2, 2010

Composition and Relationships



Here is a basic example of composition and relationships. The player can wield the object known as "Shotgun". The "Shotgun" is also a child object or to be put more clearly, inherits the properties of the object "Weapon".

Object Encapsulation



Here is an example of a Super Mario class, he has health, lives, a variable to see if he is currently suspended in air or not (isJumping) and score. These are encapsulated and can only be accessed outside the object via the functions such as SetScore(),GetScore(),SetLives(),GetLives() and more. These are called Accessors and Mutators. Accessors are the functions with the prefix "Get" and they do exactly that. They obtain the value safely to prevent errors. Mutators are the functions with the prefix "Set" and they set the value safely and everything related to that value.

Functions, Subroutines and Parameters

Function: A function is basically a process which takes input and provides an output, for example, Printing a page from a printer. The parameters are the text, images, and anything else on the page to send to the printer. The printer then uses this information accordingly to process the data and returns the output, which in this case, is paper.

Subroutine: A subroutine is a process that can take input but does not provide an output. An example of this is doing a task for someone without reaping any benefits or rewards, the task still gets done but nothing is given to you (except maybe the tools to do the job, aka the parameters). So you could be cleaning up the garden, and a parameter might be the tool you use, one day you might use the lawn mower, whilst another day you might use cutting tools to clean up bushes. This is probably a bad example but it is quite hard to explain subroutines in 'real world' terms.

In programming subroutines are usually used to keep code easy to read and repeat code with slightly different scenarios (this is where parameters come in)