Mutators and Accessors in Compositions
-avoid privacy leaks
-make defensive copies whenever mutable objects are passed into or out of the composition. No changes are needed for immutable objects.
Mutator
-create a copy of the external object and start that in our object's attribute.
Accessor
-create a copy of the objects attribute and return that copy.
Constructor
-just like the mutator.
Copy Constructors of Compositions and Aggregates
-"deep copy" --> respect the semantics of the internal objects.
-composition: copy constructor also creates new copies of all internal mutable objects.
-aggregate: only copy references, do not create new copies of internal objects.
Arrays
-Array is similar to ArrayList
- a list of objects stores by index
- all objects of the same type
Array Syntax (starting with primitives)
e.g. a list of 5 integers: int[] x = new int[5]; //creates an empty array of 5 integers.
x.length gives you the length of the array (5 in this case)
e.g. I want to store the int 1024 in the first element of the array.
x[0] = 1024; //note that array indices, like ArrayList, start at zero.
Say you want to get the third element in the array and store it in a separate int.
int y;
y = x[2];
Arrays can be initialized at declaration.
int[] x = {1024,345,-2,123,81};
Welcome
Welcome to my blog.
I will be updating this blog with lecture notes and miscellaneous information for:
Prof. A. Eckford, Section-Z: MWF at 10:30 in R S137
Feel free to leave me a message or send me an e-mail at producap@yorku.ca.
Here is a link for MyMail, Hotmail, G-mail, and PRISM login.
On that note, you must have a PRISM account in order to write the lab tests.
If you have not created a PRISM account yet (e.g., if you received transfer credit for 1020), see the lab monitor in CSEB 1006 as soon as possible.
I will also leave the blog open to comments, etc. much like the CSE forums.
Thanks for visiting.
Phil.
Sunday, March 9, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment