Wednesday, September 30, 2009

Week 4 - Delegates and Design Patterns

Delegates:

To implement the M-V-C architecture, we need some means by which updates to the Model can be reflected to the View.  The Model, however, must direct the View, not vice-versa.  Additionally, a polling type of mechanism by the View is not correct, therefore events from the Model must direct the View.

A delegate is a sort of event listener (IObservable in Java, for example).  Created within a namespace, but outside of a class, they are, in essence, subscriptions that objects can subscribe to.

In the Model (the observable class), a queue is created of all the subscribers.  In the View (the observer class), they can subscribe to the event by indicating the method they desire to have called when the event happens. 


Factory Methods:

Factory Methods are: "simple decision making [method] that returns one of several possible subclasses of an abstract (emphasis added) base class, depending on the data provided."
- C# Design Patterns, Cooper, pg. 97, Addison-Wesley 2003

Examples from the HW include...  How do you create the Board class, or the BoardWithClear class?

Other reference for this include:
http://www.dofactory.com/patterns/patternfactory.aspx
http://www.c-sharpcorner.com/UploadFile/rmcochran/instantiationFactory06232007153242PM/instantiationFactory.aspx

Template Classes:

To compliment Factory Methods, there are also Template Methods... 

"The Template pattern formalizes the ides of defining an algorithm in a class but leaving some of the details to be implemented in subclasses." 

- C# Design Patterns, Cooper, pg. 345, Addison-Wesley 2003

To tie the two patterns (factory patten and template pattern) together, an algorithm is completed when the Factory Method selects the proper subclass of a template class, and instantiates it.

See also:
http://www.dofactory.com/patterns/patterntemplate.aspx
http://en.wikipedia.org/wiki/Template_method_pattern
http://www.c-sharpcorner.com/UploadFile/rmcochran/elegant_dal05212006130957PM/elegant_dal.aspx?ArticleID=b9f94d24-6933-48e7-9c16-879ba906d28b

Week 3 - IEnumerable and IEnumerators

Busy week...  We learned a lot this week!

IEnumerators, IEnumerators, IEnumerators!  The "yield" command is magical!

Microsoft has done a wonderful job with their "syntactic sugar" associated with the foreach loop...  There is no need to  worry about initialization, termination, indexing, etc., as all this happens behind the scenes.  It accounts for one of the best means by which we can loop through a collection.

Hand in hand, the IEnumerable interface, coupled with the yield return (T); commands make accessing the desired collection extremely simple...  Utilizing the yield return (T); sequence returns an object of type T to the caller, but does not terminate the loop.  Rather, it simply pauses (yields) the loop execution until the next call.  See the following examples:

http://www.codeproject.com/KB/cs/IEnumerableAndYield.aspx
http://www.yoda.arachsys.com/csharp/csharp2/iterators.html

See also pg. 100 of C# Precisely for a great definition...









Tuesday, September 15, 2009

Week 2 - Basic OOP Fundamentals


C# Precisely: Lots of time in pg. 34 - 49, 106 - 107.

Reviewed items such as:
1. Member Access Modifiers: Private / Internal / Protected / Public
2. Method Modifiers: static, new, virtual, override, abstract
3. Abstract method vs. Interfaces
4. Properties / Indexers

Also referenced some blogs to further research the differences between when we would apply abstract classes instead of interfaces.




C# Design Patters:

MVC (pg. 3-4):
Model: The data model contains the computational parts of the program
View: The view presents the user interface
Control: Supplies the interaction between the user and the view


For a good MVC analysis, see: http://www.c-sharpcorner.com/UploadFile/rmcochran/MVC_intro12122005162329PM/MVC_intro.aspx

Closely coupled with the MVC model are the programmers addages:
1. Keep your classes loosely coupled
2. Program to the Interface!

Thursday, September 10, 2009

Week 1 Reading Lists - v1

Reading/Research on C# began with the following works:

Sharp, John; Microsoft Visual C# 2005 Step by Step, Microsoft Press, 2006
Various sections/Chapters/Pages referencing:
1. Property Accessibility (private, protected, internal, etc.)
2. Exceptions
3. Virtual Modifier
4. IComparable


http://msdn.microsoft.com/en-us/library/default.aspx