قُلْ إِنَّ صَلَاتِي وَنُسُكِي وَمَحْيَايَ وَمَمَاتِي لِلَّـهِ رَبِّ الْعَالَمِينَ - الأنعام: ١٦٢

Wednesday, September 2, 2009

Emulator wiz Design

السلام عليكم و رحمة الله و بركاته


I had a nice experience last term wiz the Architecture project that I wanted to share here. We were supposed to make an emulator (for those who don't know the project, it's a simulation to what happens inside the processor).
The normal way to make this project is to use some IFs & ELSEs. My friend (who was a senior then) told me that it was so easy and that they called it "donkey work" :(
Since the emulator was my task in the Architecture, I got so frustrated to know this information and decided to think of a better way to do it.
My friend and I asked dr.Ahmed salah & he told us we could make it with components like what we did in VHDL and he left it open for us to know how this would be implemented in C#

First Milestone:

How to make a good design?

That was solved using design patterns. Here we used the observer pattern.

“ IObserver” was implemented by all the components & “ISubject” was implemented by the Clock.

interface IObserver

{

void Updateobject(ISubject subject);

}

interface ISubject

{

List ObserversList { get;}

void AttachObserver(IObserver observer);

void DeAttachObserver(IObserver observer);

void NotifyObservers();

}

Second Milestone:

How to connect all of these components?

We made a dummy class called processor, where all the wirings took place.

Third Milestone:

Same wire, 2 endpoints!

The same wire connected 2 components, and it doesn’t make sense to change the value on one endpoint without changing it on the other end.

We needed here a simple referencing to the values of the 2 endpoints of the wire. This wasn’t supported by the simple ref keyword in C#. I really can't remember why it had a problem. But I Do remember spending 2 sleepless nights trying to solve it, so it had a problem :D. Anyway we had to search for another way to do it.

We learned that when making an object of a class, we are given a pointer to this object & not just the value. We used this tip to implement our own passing by reference.

We made a MyString class, that didn’t contain anything but a string. And whenever we wanted to pass a string by reference we made an object of MyString & used it.

class MyString

{

public string str;

public MyString(string Str)

{

str = Str;

}

}

Here is a snap shot with all the classes we used in our project.

At last I wanna thank all the people who helped us.

Dr.Ahmed Salah & Dr.Karim Emarah for their support all the time.

Alaa Shaker for introducing us to design patterns.

And of course my team members: Sara (partner in this project), Menna & Mona for your help and ultimate trust :)

And for my team members, plz correct me if I said any wrong information and kindly add any missing ones.




3 comments:

  1. great ya Noran (Y)
    This will help a lot!

    I read it zamaaaaan when u first posted it and bookmarked it (in my mind :D). Now i remembered that it'll help :D

    Rabbena ygaziki el 5er be koll 7arf katabteeh :)

    ReplyDelete
  2. forgot to say..
    The observer pattern thing is nice awiii (Y).. mgatshi fe baali :D

    ReplyDelete
  3. Thank you ya Neimo =)
    I hope it helps u :)

    as for the pattern: I just tried to remember the patterns Alaa told us, w kont bafakar el processor momken yob2a which one in them :D
    May be there is a better way that can do the job :D

    Rabena Ma3akom isA =)

    ReplyDelete