Thursday, April 26, 2007

UML Class Diagram Review

Association (straight line sometimes with an arrow)

The association link indicates that two classes have a relationship. The arrow indicates which class has the responsibility for maintaining the relationship. For example a Car class would maintain the relationship of knowing about the driver. An association is implemented as an instance in one class. The Car object would contain an instance of a driver.

public class Car
{
    private Driver _driver;
 
    public Driver Driver
    {
        get { return _driver; }
        set { _driver = value; }
    }
 
    public Car(Driver driver) 
    {
        Driver = _driver;
    }
}

Associations can often be recognized by using "Uses" or "has" in a sentence. For example, a car has a driver.

Composition (solid black diamond)

Indicates that one class belongs to the other. For example a Hand is made up of fingers. If the Hand is destroyed, so are the fingers. A composition is usually implemented as a collection on one class.

public class Hand
{
    private IList<Finger> _fingerList;
 
    public IList<Finger> FingerList
    {
        get { return _fingerList; }
        set { _fingerList = value; }
    }
 
    public Hand() { }
}



Aggregation (white diamond)

Aggregation is similar to composition. Aggregation is less rigorous than composition. For example, an order is made up of several products. If an order is deleted the products will continue to exist. An aggregation is usually implemented as a collection on one class.

public class Order
{
    private IList<Product> _productList;
 
    public IList<Product> ProductList
    {
        get { return _productList; }
        set { _productList = value; }
    }
 
    public Order() { }
}



Composition And Aggregation

Composition and aggregation relationships can be recognized by using "part of" or "has" in a sentence. The relationships determined above could be placed in the following sentences.
  • A Finger is part of a Hand.
  • A Hand has fingers.

  • A Product is part of a Order.
  • A Order has Products.

Generalization
(Open white Arrow)

Generalization refers to an inheritance relationship. Inheritance allows for a class to receive the characteristics of the inherited class. In .Net a class can only inherit from one class. For example, the SportsCar class would inherit from the Car class. The Car class would contain the general characteristics of a car. The SportsCar class would inherit the properties for color, engine and max speed. Additionally the SportsCar class would inherit methods to drive and add fuel to the car.



Interface
(Dotted line with arrow pointing at interface)

An Interface is a contract. The contract dictates which methods and properties a class must implement. An interface guarantees that certain members will be implemented by a class. Interfaces are a great resource when creating unit tests. Interfaces allow you to create unit tests without having to worrying about the implementation. In .net a class can implement as many interfaces as desired. Typical naming conventions for Interfaces prefix the name of the interface with the letter "I".



The interface
public interface ICar
{
    //Properties
    int Fuel { get; set; }
    string Color { get; set; }
    string MaxSpeed { get; set;}
 
    //Methods
    void Drive(int distance);
    void AddFuel(int fuel);
    void RemoveFuel(int fuel);
}

Implementing the interface
public class SportsCar : ICar
{
    #region Private Fields
 
    private string _color;
    private string _maxSpeed;
    private int _fuel;
 
    #endregion
 
    #region Public Fields
 
    public int Fuel
    {
        get { return _fuel; }
        set { _fuel = value; }
    }
 
    public string Color
    {
        get { return _color; }
        set { _color = value; }
    }
 
    public string MaxSpeed
    {
        get { return _maxSpeed; }
        set { _maxSpeed = value; }
    }
 
    #endregion
 
    #region Public Methods
 
    public void Drive(int distance)
    {
        //Ok this is not a real
        //calculation. However it gives
        //you the general idea.
        RemoveFuel(distance);
    }
 
    public void AddFuel(int fuel)
    {
        Fuel += fuel;    
    }
 
    public void RemoveFuel(int fuel)
    {
        Fuel -= fuel;    
    }
 
    #endregion
}

Further Resources

The following articles might be of use:
Uml Tutorial
Another explanation

If you would like to take an even deeper look at UML diagrams I suggest you purchase Martin Fowler’s UML Distilled. I often use this book as a quick reference. Fowler's writing style is very down to earth and should appeal to most audiences.

Thursday, April 12, 2007

Web Operating System "YouOS"

What the heck is a web operating system?

YouOS is a web operating system. Your immediate reaction should be to ask what is an web operating system? First let us define what an operating system is. According to various definitions an operating system is two folded. One an operating system manages the hardware and basic system operations of a computer. This creates a layer between the software applications and the hardware. Two an operating system provides the foundation from which software applications can run. A Web operating system meets the second criteria by providing the foundation from which software applications can be run.

It Looks like an operating system

YouOS contains many features that give it the appearance of being a real operating system. Like most operating systems YouOS has a desktop. From this desktop you can move icons, click icons and even change the wallpaper.

Even more impressive is the YouShell. The YouShell is like the command prompt in windows. Using the YouShell you can view all running processes, kill processes, run programs, create directories, delete directories and perform various other tasks.

Additionally YouOS like most operating systems have windows(dialogs) that can be resized, maximized, minimized and closed. When minimized these windows are placed on task bar that resides at the top of the screen. The stuff button is similar to the start button in windows. From the stuff button you can access additional programs and features.

The purpose of YouOS

YouOS essentially is an operating system that you can be accessed from any location that has an internet connection. The real value of this product lies in the fact that users are now able to access a suite of applications from one central point at any location. For example, a student could log into YouOS and use the GoogleDocs application to take notes during a class. upon arriving home the student could log into YouOS to review their notes.

Developing applications

YouOS provides an online integrated development environment(IDE). Software development for YouOS takes place from within YouOS itself. Software developers are only required to know Javascript and HTML to develope for YouOS. YouOS even provides an API for server side data storage and communication. YouOS has made data persistence simpler by providing an API that allows software developers to persist data without having to know or use any SQL.

My Thoughts

Like most software developers I am very curios as to how YouOS has been created. As I continue to test and play with each new feature I always ask myself how is this implemented? By asking this simple question it allows for mind to wonder and theorize on the various ways that this solution has been created. Furthermore this has allowed me to realize that YouOS is no small web application. I'm sure that the YouOS team has encountered many interesting design decisions along the way. As a software developer the prospect of working on such a ground breaking project would be extremely exciting. A more exciting prospect is the thought of being one of the individuals who first had this brilliant idea.

For more information please take a look at the YouOS manifesto and sign up for an account.

Tuesday, April 3, 2007

Visual Studio 2005 Keyboard Shortcuts

This is for the shortcut key junkie. Print it and post it on your cubicle or office wall.

Visual C# 2005 Keyboard Shortcut Reference Poster

Visual Basic 2005 Keyboard Shortcut Reference Poster

For a more in depth list of shortcuts checkout the following link; its not a poster but it should do. Visual Studio Shortcuts

One of my colleagues is the stereotypical shortcut key junkie. Recently Mo introduced me to a handful of keyboard shortcuts. The following is a list of my favorite Visual Studio 2005 shortcuts.

ShortcutDescription
CTRL + TABDisplays all active tabs.
CTRL + K, CTRL + CComments the highlighted text.
CTRL + K, CTRL + UUncomments the highlighted text.
CTRL + M, CTRL + MExpands or collapses a region. When a region is open you can place your cursor on either the start or end of the region/method to close it.
CTRL + M, CTRL + OCollapse all.
CTRL + M, CTRL + PExpand all.
CTRL + Shift + BBuild.
CTRL + Shift + F9Clear all break points.
CTRL + F5Runs the code without invoking the debugger.
CTRL + SHIFT + F5Runs the application in debug mode. If you are already in debug the application will be rebuilt and run in debug mode.
CTRL + D, CTRL + ADisplay the Auto window to view values of variables in the current scope.
F10Step over.
F11Step into.
SHIFT + F11Step out.
CTRL + F10Run to cursor. Useful for conditional loops.