Welcome

Welcome to my blog.


I will be updating this blog with lecture notes and miscellaneous information for:

CSE 1030 : Winter Term
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.

Monday, March 10, 2008

CSE Lecture 3/Mar/2008





Please click on the desired image to view on a larger scale.

CSE Lecture 29/Feb/2008



Please click on the desired image to view on a larger scale.

CSE Lecture 25/ Feb/2008 (Alternative)


Please click on the desired image to view on a larger scale.

Sunday, March 9, 2008

CSE Lectures 22/Feb/2008 to 27/Feb/2008 Part 2




Please click on the desired image to view on a larger scale.

CSE Lectures 22/Feb/2008 to 27/Feb/2008 Part 1







Please click on the desired image to view on a larger scale.

CSE Lecture 8/Feb/2008





Please click on the desired image to view on a larger scale.

CSE Lecture 6/Feb/2008

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};

Monday, February 4, 2008

CSE Lecture 4/FEB/08

Note: See the previous lectures notes for the majority of this lectures contents.

Defensive Copying and Privacy Leaks

Composition: external interference with the inner workings of the class are undersirable.

Aggregates: external changes are OK.

The method of Copy Constructors (previous lectures) is called defensive copying.

CSE Lecture 1/FEB/08

Collections

-A collection is an aggregate(or composition) in which more than one of each type is allowed.
-The number required is not known in advance.
e.g. Portfolio --> collection of Investments

-We have already seen HashMap from SingletonPerState

Collection Constructors

-Best way: create an empty collection object in the constructor.
-Also, provide a public add() method for loading objects into the collection. This method generally returns a boolean: false if it fails, true otherwise.

Collection Objects - 3 Types

Lists - objects in order, duplicates are OK
Sets - order does not matter, duplicates are not allowed.
Maps - objects are associated with keys.

See code for Portfolio

Iterators and Iterable

-Iterator and Iterable are interfaces.
-A class implementing an interface must implement all the methods specified in the interface exactly. This means the same return type, same name (case-sensitive), same number, order, and types of paramters.


--> MyClass implements MyInterface

public class MyClass implements MyInterface
{
.
.
.
}

The Iterator interface allows a method to take some action on each element in a collection. It contains a method that returns the collection's Iterator --> repackaging the collection for iterator operations.

See Rest of Portfolio code including getValue() method.


Thursday, January 31, 2008

CSE Lecture 30/JAN/2008

Aggregation

-An aggregate is a class where some of the attributes are themselves objects.
-If all attributes are primitive, the class is not an aggregate.

e.g. public class BankProducts
{
private BankAccount savings;
private BankAccount chequing;
private Loan homeMortgage;
private Loan lineOfCredit;

}

- a composition is an aggregation in which the objects inside the class "live and die" with the object. In effect, it is created when the object is created and destroyed when the object is destroyed.

Aggregate: only holds references to external objects. These objects exist apart from the aggregate.

Composition: locally creates its own objects. Objects are only relevant to the object holding them.

External forces can generally change the value of an object in an aggregate. This is good for an aggregate, bad for a composition.

We don't want external forces messing with the internal structure of a composition.

Aggregate Constructors

-Aggregates keep references to external objects. They don't generally make local copies.

e.g. public class Investment
{

public class Investment(Stock s, int num)
{
this.s = s;
this.num = num;
}

}

Composition Constructor

-Objects in a composition reflect the internal workings of an object.

-Local versions, not accessible from the outside, should be kept.
-Extends the concept of private access type.

public class CompositionWithStock
{

private Stock s;
Public ComparisonWithStock(Stock s, int num)
{ //create a local copy of s and store it
this.s = new Stock(s);
this.num = num
}

CSE Lecture 28/JAN/2008

Singleton-per-state

--> state attribute for a class(int)
---> only one object is allowed for each state. e.g. process information for each process in a UNIX environment.


Aside

HashMap

-A way of storing objects with respect to a key (i.e. an integer)

Objects: a,b,c
HashMap: h

h.put(a, 100) places the object a with the key 100.

-Say I want to store objects of type MyObject with respect to integers.

-HashMap h = new HashMap();

Singleton-per-state design pattern.

-constructor is private
-private static HashMap stores the instances with respect to status.
-getInstance(int state) is a public static method which checks the HashMap for an instance corresponding to state. If it exists, it is returned, if not, store it in HashMap, return it.

You cannot access non-static attributes from a static method.

Sunday, January 27, 2008

CSE Lecture 25/Jan/2008

Singleton Class

Before, we had utility classes, no instances were allowed.

Singleton class -> only one object is allowed to be instantiated.

Good for:

- Things that need to be globally constant, e.g. configuration and system status details.
- The key is the access specifier of the constructor: it must be private.

Object creation will take place within the class ---> created instances will be returned using a method other than the constructor...e.g getInstance()

Attempt 1
- Use static features to count # of instances created -> instanceCount variable.
- getInstance() checks instanceCount.
- If 0, create an instance and return it, set instance to 1
- If 1, return null.

Better way
- get Instance returns the single instance whenever it is called.
- class has to keep track of the object reference - via a private static variable.

Attempt 2a
- getInstance() checks instanceCount
-If 0, creates a new instance and saves it to a private static attribute and increments instanceCount
-returns the reference to the object.

Attempt 2b
-Don't need an instance counter
-Initialize instance when declared.

-This attempt is a design pattern for singleton classes.

Singleton Design Pattern

-private static instance holder --> creates and holds the only instance
-public static getInstance() -> returns instance
-private constructor -> prevents instances from being created by the client.
-no mutator for the instance holder, instance is final.

CSE Lecture 23/Jan/2008

Immutable classes are in effect "constant" objects. There is no reason to have more than one instance of an immutable object.

If I declare an object to be final, does that make the object immutable?

No. Final applies to the value in memory of the object.

An object is immutable if:

1) All the attributes are primitives, and private, and
2) None of the methods are mutators.

Mixed features of classes

-features that combine static and non-static features.
-static --> class
-non static --> features in the class.

Examples:

-Instance counter: how many instances of a class have been created.
-Serial number creator: every object is stamped with a unique serial number.