9.4: FgfsDataObject


#region Usings

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using FgfsSharp;

#endregion

namespace FgfsSharp
{
//TODO: Documentation
public class FgfsDataObject : IObservable
{
#region Privates

//the obeserver list
private List _observer;
private int _speed;
private int _altitude;
private int _roll;
private int _pitch;
private int _headingMagneticNorth;

#endregion

#region Properties

public int Speed
{
get {return _speed;}
set { _speed = value; }
}

public int Altitude
{
get { return _altitude; }
set { _altitude = value; }
}

public int Roll
{
get { return _roll; }
set { _roll = value; }
}

public int Pitch
{
get { return _pitch; }
set { _pitch = value; }
}

public int HeadingMagN
{
get { return _headingMagneticNorth; }
set { _headingMagneticNorth = value; }
}

#endregion

#region Constructor

public FgfsDataObject()
{
Console.WriteLine("Constructor: DataObject");
_observer = new List();
}

#endregion

#region Interface Methods

public void RemoveObserver(IObserver observer)
{
int i = _observer.IndexOf(observer);
if (i >= 0)
_observer.Remove(observer);
}

public void RegisterObserver(IObserver observer)
{
this._observer.Add(observer);
Console.WriteLine("Observer {0} added", observer.ToString());
}

public void NotifyObservers()
{
//update every observer here!
foreach (IObserver observer in this._observer)
{
//Console.WriteLine("Notifying...");
observer.UpdateObserver(this);
}
}

#endregion
}
}

5 Responses to “9.4: FgfsDataObject”

  1. Brent Says:

    This software does not compile due to the use of “List”, according to the compiler, “Using the generic type ‘System.Collections.Generic.List’ requires ‘1’ type arguments”

  2. Dustin Says:

    I am not familiar with C# and I’m having difficulty with this particular code. Specifically, with the private List _observer declaration. Should that be of some form List? I really do not know what to do with it and can’t seem to find the answer anywhere.

  3. Dustin Says:

    such as List ?

Leave a comment