Showing posts with label 70-536. Show all posts
Showing posts with label 70-536. Show all posts

Thursday, December 11, 2008

Interfaces in System.Collections

pencil icon, that"s clickable to start editing the post

In preparing for 70-536 I've been looking at the Interfaces in System.Collections (that's quite dated since the generic variants been here for a while). Looking at the Exam objective:

Developing applications that use system types and collections (15 percent)

  • Manage a group of associated data in a .NET Framework application by using collections. May include but is not limited to: ArrayList class; Collection interfaces; Iterators; Hashtable class; CollectionBase class and ReadOnlyCollectionBase class; DictionaryBase class and DictionaryEntry class; Comparer class; Queue class; SortedList class; BitArray class; Stack class

I've bought Tony Northup's Self-Paced Training Kit and it doesn't even mention the Interfaces! If it's for a god reason I guess it's since in practical use the Collection Classes are used and not the Interfaces. I don't really think it's a god idea, since hopefully there's a reason for the Interfaces and one of these should be implementing own collection and Classes with collection functionality.

The MSDN Library on System.Collections has god coverage but I'm missing two things - the Interfaces as code and a class diagram. I've looked and searched but not found none, not even at the Mono Project. Here I'll present my own Class Diagram and reconstruct the 8 Interfaces in System.Collections from the available information. One last hiccup is that the MSDN Library declares Interfaces that are extended redundantly, fx. IList implements ICollection but IEnumerable is also shown in the snip like:

public interface IList : ICollection, IEnumerable

This reduandancy confuses me in trying to understand the hierarchy, it sort of disrespects the hierarchy and suggest some form of composite pattern instead (or I just missing a point). It seems like most of the documentation for C# is used this way, but I'm not totally alone with this view, at least pdavila on the Manning maillist has raised the same concern.

A Class Diagram for System.Collections

With the help of Argouml and my missing skills with I was able to create something that resembles a correct Class Diagram for System.Collections:

Class Diagram for System.Collections

The one thing that strikes me the most is that the two Base Classes CollectionBase and DictionaryBase isn't used by the framework itself so why should I use it? Perhaps there is a god reason for it and maybe I'll even find it as i read thorugh Krzysztof Cwalina's blog.

The Interfaces as C# code

IEnumerable

The root interface carries the following description:

Exposes the enumerator, which supports a simple iteration over a non-generic collection.

    1 namespace System.Collections
    2 {
    3     [ComVisibleAttribute(true)]
    4     [GuidAttribute("496B0ABE-CDEE-11d3-88E8-00902754C43A")]
    5     public interface IEnumerable
    6     {
    7         /* Methods */
    8 
    9         // Returns an enumerator that iterates through a collection.
   10         IEnumerator GetEnumerator();
   11     }
   12 }

ICollection

Next in the Hierarchy has:

Defines size, enumerators, and synchronization methods for all nongeneric collections.

    1 namespace System.Collections
    2 {
    3     public interface ICollection : IEnumerable
    4     {
    5         /* Properties */
    6 
    7         // Gets the number of elements contained in the ICollection.
    8         int Count { get; }
    9 
   10         // Gets a value indicating whether access to the ICollection is synchronized (thread safe).
   11         bool IsSynchronized { get; }
   12 
   13         // Gets an object that can be used to synchronize access to the ICollection.
   14         Object SyncRoot { get; }
   15 
   16 
   17         /* Methods */
   18 
   19         // Copies the elements of the ICollection to an Array, starting at a particular Array index.
   20         void CopyTo(Array array, int index);
   21     }
   22 }

IList

Here the class diagram splits in IList that:

Represents a non-generic collection of objects that can be individually accessed by index.

    1 namespace System.Collections
    2 {
    3     [ComVisibleAttribute(true)]
    4     public interface IList : ICollection
    5     {
    6         /* Properties */
    7 
    8         // Gets a value indicating whether the IList has a fixed size.
    9         bool IsFixedSize { get; }
   10 
   11         // Gets a value indicating whether the IList is read-only.
   12         bool IsReadOnly { get; }
   13 
   14         //   Gets or sets the element at the specified index.
   15         Object Item[int index] { get; set; }
   16 
   17 
   18         /* Methods */
   19 
   20         // Adds an item to the IList.
   21         int Add(Object value);
   22 
   23         // Removes all items from the IList.
   24         void Clear();
   25 
   26         // Determines whether the IList contains a specific value.
   27         bool Contains(Object value);
   28 
   29         // Determines the index of a specific item in the IList.
   30         int IndexOf(Object value);
   31 
   32         // Inserts an item to the IList at the specified index.
   33         void Insert(int index, Object value);
   34 
   35         // Removes the first occurrence of a specific object from the IList.
   36         void Remove(Object value);
   37 
   38         // Removes the IList item at the specified index.
   39         void RemoveAt(int index);
   40     }
   41 }

IDictionary

The other branch is IDictionary that:

Represents a nongeneric collection of key/value pairs.

    1 namespace System.Collections
    2 {
    3     [ComVisibleAttribute(true)]
    4     public interface IDictionary : ICollection
    5     {
    6         /* Properties */
    7 
    8         //Gets a value indicating whether the IDictionary object has a fixed size.
    9         bool IsFixedSize { get; }
   10 
   11         // Gets a value indicating whether the IDictionary object is read-only.
   12         bool IsReadOnly { get; }
   13 
   14         // Gets or sets the element with the specified key.
   15         Object Item[Object key] { get; set; }
   16 
   17         // Gets an ICollection object containing the keys of the IDictionary object.
   18         ICollection Keys { get; }
   19 
   20         // Gets an ICollection object containing the values in the IDictionary object.
   21         ICollection Values { get; }
   22 
   23 
   24         /* Methods */
   25 
   26         // Adds an element with the provided key and value to the IDictionary object.
   27         void Add(Object key, Object value);
   28 
   29         //   Removes all elements from the IDictionary object.
   30         void Clear();
   31 
   32         // Determines whether the IDictionary object contains an element with the specified key.
   33         bool Contains(Object key);
   34 
   35         // Overloaded. Returns an IDictionaryEnumerator object for the IDictionary object.
   36         IDictionaryEnumerator GetEnumerator();
   37 
   38         // Removes the element with the specified key from the IDictionary object.
   39         void Remove(Object key);
   40     }
   41 }

IEnumerator

To iterate through a Collection there's an IEnumerator similar to the Java Iterator

Supports a simple iteration over a nongeneric collection.

    1 namespace System.Collections
    2 {
    3     [ComVisibleAttribute(true)]
    4     [GuidAttribute("496B0ABF-CDEE-11d3-88E8-00902754C43A")]
    5     public interface IEnumerator
    6     {
    7         /* Properties */
    8 
    9         //Gets the current element in the collection.
   10         Object Current { get; }
   11 
   12 
   13         /* Methods */
   14 
   15         //   Advances the enumerator to the next element of the collection.
   16         bool MoveNext();
   17 
   18         // Sets the enumerator to its initial position, which is before the first element in the collection.
   19         void Reset();
   20     }
   21 }

IDictionaryEnumerator

The pendant for Dictionaries (Java Map) are an IDictionaryEnumerator:

Enumerates the elements of a nongeneric dictionary.

    1 namespace System.Collections
    2 {
    3     [ComVisibleAttribute(true)]
    4     public interface IDictionaryEnumerator : IEnumerator
    5     {
    6         /* Properties */
    7 
    8         // Gets both the key and the value of the current dictionary entry.
    9         DictionaryEntry Entry { get; }
   10 
   11         // Gets the key of the current dictionary entry.
   12         Object Key { get; }
   13 
   14         // Gets the value of the current dictionary entry.
   15         Object Value { get; }
   16     }
   17 }

IComparer

There's two utility Interface where the first is for sorting:

Exposes a method that compares two objects.

    1 namespace System.Collections
    2 {
    3     // Exposes a method that compares two objects.
    4     [ComVisibleAttribute(true)]
    5     public interface IComparer
    6     {
    7         /* Methods */
    8 
    9         // Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
   10         int Compare(Object x, Object y);
   11     }
   12 }

IEqualityComparer

And lastly the IEqualityComparer for searching:

Defines methods to support the comparison of objects for equality.

    1 namespace System.Collections
    2 {
    3     //Defines methods to support the comparison of objects for equality.
    4     [ComVisibleAttribute(true)]
    5     public interface IEqualityComparer
    6     {
    7         /* Methods */
    8 
    9         // Determines whether the specified objects are equal.
   10         bool Equals(Object x, Object y);
   11 
   12         // Returns a hash code for the specified object.
   13         int GetHashCode(Object obj);
   14     }
   15 }

Read more

Sunday, November 23, 2008

Collection Classes in .NET 3.5

pencil icon, that"s clickable to start editing the post

Being able to easily handle collections both in terms of functionality and performance is central to any computer language. Going from plain arrays with memory handling i C++ to the STL collection classes was a hurge lap forward. I practice I've used very few variants since much functionality is often handled in the persistens layer. C# and .NET has plenty of built-in collection classes, and it's practical to know and needed for the 70-536 Exam:

Developing applications that use system types and collections (15 percent)

  • Manage a group of associated data in a .NET Framework application by using collections.
    May include but is not limited to: ArrayList class; Collection interfaces; Iterators; Hashtable class; CollectionBase class and ReadOnlyCollectionBase class; DictionaryBase class and DictionaryEntry class; Comparer class; Queue class; SortedList class; BitArray class; Stack class
  • Improve type safety and application performance in a .NET Framework application by using generic collections.
    May include but is not limited to: Collection.Generic interfaces; Generic Dictionary; Generic Comparer class and Generic EqualityComparer class; Generic KeyValuePair structure; Generic List class, Generic List.Enumerator structure, and Generic SortedList class; Generic Queue class and Generic Queue.Enumerator structure; Generic SortedDictionary class; Generic LinkedList; Generic Stack class and Generic Stack.Enumerator structure
  • Manage data in a .NET Framework application by using specialized collections.
    May include but is not limited to: Specialized String classes; Specialized Dictionary; Named collections; CollectionsUtil; BitVector32 structure and BitVector32.Section structure

In this post I'll run through the classes (and save the Interfaces, Base classes and further functionality for another post). First the four relevant namespaces:

System.Collections
The System.Collections namespace contains interfaces and classes that define various collections of objects, such as lists, queues, bit arrays, hash tables and dictionaries.
System.Collections.Generic
The System.Collections.Generic namespace contains interfaces and classes that define generic collections, which allow users to create strongly typed collections that provide better type safety and performance than non-generic strongly typed collections.
System.Collections.ObjectModel
The System.Collections.ObjectModel namespace contains classes that can be used as collections in the object model of a reusable library. Use these classes when properties or methods return collections.
System.Collections.Specialized
The System.Collections.Specialized namespace contains specialized and strongly-typed collections; for example, a linked list dictionary, a bit vector, and collections that contain only strings.

Collection Classes

System.Collections

ArrayList
Implements the IList interface using an array whose size is dynamically increased as required.
BitArray
Manages a compact array of bit values, which are represented as Booleans, where true indicates that the bit is on (1) and false indicates the bit is off (0).
Hashtable
Represents a collection of key/value pairs that are organized based on the hash code of the key.
Queue
Represents a first-in, first-out collection of objects.
SortedList
Represents a collection of key/value pairs that are sorted by the keys and are accessible by key and by index.
Stack
Represents a simple last-in-first-out (LIFO) non-generic collection of objects.

System.Collections.Specialized

HybridDictionary
Implements IDictionary by using a ListDictionary while the collection is small, and then switching to a Hashtable when the collection gets large.
ListDictionary
Implements IDictionary using a singly linked list. Recommended for collections that typically contain 10 items or less.
NameValueCollection
Represents a collection of associated String keys and String values that can be accessed either with the key or with the index.
OrderedDictionary
Represents a collection of key/value pairs that are accessible by the key or index.
StringCollection
Represents a collection of strings.
StringDictionary
Implements a hash table with the key and the value strongly typed to be strings rather than objects.

System.Collections.ObjectModel

ObservableCollection(T)
Represents a dynamic data collection that provides notifications when items get added, removed, or when the whole list is refreshed.
ReadOnlyObservableCollection(T)
Represents a read-only ObservableCollection(T).

System.Collections.Generic

Dictionary(TKey, TValue)
Represents a collection of keys and values.
HashSet(T)
Represents a set of values.
KeyedByTypeCollection(TItem)
Provides a collection whose items are types that serve as keys.
LinkedList(T)
Represents a doubly linked list.
List(T)
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.
Queue(T)
Represents a first-in, first-out collection of objects.
SortedDictionary(TKey, TValue)
epresents a collection of key/value pairs that are sorted on the key.
SortedList(TKey, TValue)
Represents a collection of key/value pairs that are sorted by key based on the associated IComparer(T) implementation.
Stack(T)
Represents a variable size last-in-first-out (LIFO) collection of instances of the same arbitrary type.
SynchronizedCollection(T)
Provides a thread-safe collection that contains objects of a type specified by the generic parameter as elements
SynchronizedKeyedCollection(K, T)
Provides a thread-safe collection that contains objects of a type specified by a generic parameter and that are grouped by keys.
SynchronizedReadOnlyCollection(T)
Provides a thread-safe, read-only collection that contains objects of a type specified by the generic parameter as elements.

What should I choose and when?

I am no expert, but I would use on of the generic variants if possible, since I like strong types (type-safe) and I even more hate those pesky casts from Object into a magical and sometimes unknown class. Infact I can't see no reason not to, since if it's bumped together in a collection I expect them to be related at least by an Interface.

In C++ I got away with something like 92% Vectors, 6% Maps and a minority of other collections from STL. In practical C# I'll probably do more or less the same, but for the Exam I'll probably have to learn the more odd ones, not that I mind using a Queue or Stack where it fits. My aversion for linked Lists has probably something to do with it being a little harder to iterate in C++ and this is most definitely much easier in the newer C#/.NET.

I've later found a good resource on Collection Classes (C# Programming Guide) that among other has a reference to the guide: Selecting a Collection Class.

Read more

Monday, November 17, 2008

Considering becomming a Microsoft Certified Technology Specialist - first up 70-536

pencil icon, that"s clickable to start editing the post

Daddy's got a brand new car with the acronym VS2008 and it runs on C# 2008 and .NET 3.5. I haven't really done any development i .NET since the good ol' days of platform breaking .NET 1.0. Java's fine for me but I would like to widen my knowledge since I both found it easy to use and productive and at the same time adoption seems to rise (judging from the number of vacancies with .NET in the job description). Running for a certification might lead the way into the inner workings of .NET and give me something for my CV since I currently do to less coding (In my own eyes).

Nowadays the first step is MCTS: Microsoft Visual Studio 2008 and any matter which of tracks I'll go for (probably WCF og ASP.NET) I'll need to pass Exam 70-536: TS: Microsoft .NET Framework – Application Development Foundation. There's a little confusion about this one since it used to be for .NET 2.0 but has be updated for 3.5 (both still in play for VS2005/VS2008) and reading about the 70-536 exam on the Microsoft Learning site doesn't make this much clearer but according to Gerry O'Brien's Get Ready for the ASP.NET 3.5 MCTS Exam and not the least his own comment:

The exams for 3.5 were recreated from scratch. We invite subject matter experts from the industry into a focus group and create the exam structure and coverage based on how the product or technology is used in the industry.

We do not base our exams solely on product features. The features come into play as a result of the tasks that are performed based on our SME input and as a result, the exam may or may not include content that is similar in nature to what was on an exam for 2.0.

To prepare for an exam, never assume anything about the content but rather use the prep guides found online to understand the areas that will be covered on the exam and prepare accordingly.

So it's new but might be close to being the same - fair enough the basics are still the same.

The exam costs 1600 kr. in Denmark which isn't exactly cheap but as I recall the SCJP costed somewhere similar.

What's the exam about

The material covered in the exam spans seven areas:

  • Developing applications that use system types and collections (15 percent)
  • Implementing service processes, threading, and application domains in a .NET Framework application (11 percent)
  • Embedding configuration, diagnostic, management, and installation features into a .NET Framework application (14 percent)
  • Implementing serialization and input/output functionality in a .NET Framework application (18 percent)
  • Improving the security of .NET Framework applications by using the .NET Framework security features (20 percent)
  • Implementing interoperability, reflection, and mailing functionality in a .NET Framework application (11 percent)
  • Implementing globalization, drawing, and text manipulation functionality in a .NET Framework application (11 percent)

and I'm afraid that I'm pretty blank on many of them.

Study material

Considering that presently I can just find one book to directly support this exam: MCTS Self-Paced Training Kit (Exam 70-536): Microsoft® .NET Framework Application Development Foundation, Second Edition (Paperback) (just out November 12, 2008) and that the former version MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework 2.0 Application Development Foundation (Hardcover) according to Derik Whittaker - "Taking the MCTS Test 70-536 -- That Sucked...." and the commenter's on his blog isn't that great.

The book Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition seems like the best book in general and is in fact a newer incarnation on the now seven years old C# and the .NET Platform (Paperback) that I keep in a box somewhere.

Many of the comments found strongly recommends taking/rehearsing text exams so I'll probably also have to get testking or measureup.

Read more