6 Design

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View 6 Design as PDF for free.

More details

  • Words: 1,052
  • Pages: 8
DESIGN APPROACH

Design Approach System is designed using Object Oriented Approach. Keeping in mind the facilities of reusability, easy future enhancement and data security issues this approach is being used. Another reason is its rising popularity. So far you have known to the system architecture in detail in previous chapters. All following section in this chapter describes the software design of the system in detail.

Process Model The process model followed during the development of the system is an evolutionary software process model because it enables software engineers to develop increasingly more complex versions of the software. For the development of the Our System We l used Spiral model, because 

It is more iterative.



It enables software engineer to develop increasing more complex versions of the software.



The Spiral model provides a platform for the evaluation by the user.



It handles risks at each stage of the software.

Design Strategy Basically it’s an application package, how the various operations/tasks are being done is totally dependent upon the user who is initiator of all the operations. Thus all the operations of the system, even interaction of the major modules, designed keeping in mind, the interaction of the user. The classes are described first, then use cases, sequence diagram and collaboration diagrams are designed to describe the design of whole system. How the mechanism of parsing

LAN CHAT MANIA

30

DESIGN APPROACH

Description of Classes Our system is consisting of nine classes that perform the whole operations of the system in collaboration. Some MFC classes are also used.

Communication between two applications running on different (or same) systems in a Local Area Network is not a luxury, but a necessity. The .NET framework provides various solutions for solving this - Remoting, Socket Programming (TCP/UDP), Web Services etc. I will be using Remoting in my application because I believe it is the most powerful tool. I have developed an Instant Messaging system. The system consists of a server application, a client application, and a library which is used by both the server and the client. Class library The class library consists of the interface IServer and some other classes. The interface

IServer dictates the functionality of the server. This information is used by the client to call the methods of the remote object. public interface IServer { bool SignUp(string username,string password); bool ChangePassword(string username,string curPassword,string newPassword); bool SignIn(string username,string password,bool visible); bool SignOut(string username); bool IsVisible(string username); bool AddContact(string username,string contact); bool RemoveContact(string username,string contact); ArrayList GetContacts(string username); bool Send(string from,string to,string message); LetterReceive Receive(string to); ArrayList ReceiveOffline(string to); }

LAN CHAT MANIA

31

DESIGN APPROACH

LetterReceive is a class containing two string variables, from and message, and a few properties. It is very straightforward, hence I choose not to give its code. Server I will first explain the server class code, and once we are finished with it, I will explain the Remoting part. We will first take a look at the class hierarchy. At the top of the pyramid, is the class Server. The Server uses the class Letter to store messages. The Server uses an object of class Database to store information which needs to persist between machine shutdowns. This includes account information and offline messages. The class Database uses the class AccountField to store information like password and contacts for a particular user. The class Database uses the class Letter to store offline messages. We will start with the class AccountField, at the bottom of the hierarchy. Here is the code for it: [Serializable] class AccountField { internal string password; internal bool isLoggedIn; internal bool visible; internal ArrayList contacts; public AccountField(string password,bool isLoggedIn) { this.password=password; this.isLoggedIn=isLoggedIn; contacts=new ArrayList(); } }

The class Letter has three string variables, from, to, message.

LAN CHAT MANIA

32

DESIGN APPROACH The class Database is quite simple. I will show here part of its code. The rest would be easy to guess. The Hashtable and database are used to store account information as can be seen in the method Add. It also has methods, Load and Save to load and save its instance to disk. The technique used is serialization. [Serializable] class Database { //Fields private Hashtable database; internal ArrayList offlineMessages; //Constructor public Database() { database = new Hashtable(); offlineMessages=new ArrayList(); Load(); } //Methods internal bool Add(string username,string password) { if(database.Contains(username)) return false; database.Add(username,new AccountField(password,false)); return Save(); } . . . }

Let us come to the class Server. As can be seen, Server has inherited from the interfaces

IServer and MarshalByRefObject (to enable Remoting). Once again, I will be show only the more important parts of the class declaration. Collapse

public class Server : MarshalByRefObject, ChatMasalaLib.IServer

LAN CHAT MANIA

33

DESIGN APPROACH { Database database = new Database(); ArrayList letters = new ArrayList(); //Constructor public Server() { database.Load(); } public bool Send(string from,string to,string message) { if(database.ContactExists(to)==false) return false; if(database.IsLoggedIn(to)) letters.Add(new Letter(from,to,message)); else { database.offlineMessages.Add(new Letter(from,to,message)); if(database.offlineMessages.Count>maxOfflineMessages) { database.offlineMessages.RemoveAt(0); } Console.WriteLine(database.Save()); } return true; } public LetterReceive Receive(string to) { int length = letters.Count; for(int i =0;i < length;i++) { if(((Letter)letters[i]).To==to) { LetterReceive lr = new LetterReceive( ((Letter)letters[i]).Message,((Letter)letters[i]).From); letters.RemoveAt(i); return lr; } } return new LetterReceive("",""); }

LAN CHAT MANIA

34

DESIGN APPROACH public bool SignUp(string username,string password) { return database.Add(username,password); } . . . }

Now, we come to the Remoting part. This actually enables the communication between the server and the client. HttpChannel channel = new HttpChannel(8080); ChannelServices.RegisterChannel(channel); RemotingConfiguration.RegisterWellKnownServiceType(Type.GetType("Temporary_Server.Server"), "Server",WellKnownObjectMode.Singleton);

Client Enough coding, let's get into action. Here is the client explained. I would first describe the Remoting initialization code. HttpChannel channel = new HttpChannel(); ChannelServices.RegisterChannel(channel); string hostIP = "127.0.0.1"; MarshalByRefObject obj = (MarshalByRefObject)RemotingServices.Connect( typeof(IServer),"http://"+hostIP+":8080/Server"); server=obj as IServer; (obj as RemotingClientProxy).Timeout=5000;

The tough part is over, now we only have to call the methods of the variable server to work. Here, I have given a few examples: server.SignIn("AmitDey","Password",true); server.IsVisible("Boss"); server.Send("AmitDey","Boss","Work complete. Can I go home ?"); //Will receive 1 message if a message exists for user AmitDey server.Receive("AmitDey");

LAN CHAT MANIA

35

DESIGN APPROACH The client code is huge, distributed into many forms. But, it's all so easy that I am not sharing it with you here. You can check it out in the source code files available at the top of this page.

CLASS DIAGRAM:

LAN CHAT MANIA

36

DESIGN APPROACH

CLASS INTERACTION DIAGRAM:

LAN CHAT MANIA

37

Related Documents

6 Design
June 2020 5
Wk 6: Scenario Design
June 2020 4
Exp Design Ch 6
May 2020 11
Neuroscience Poster Design 6
September 2019 15