How to code an Object model

Ola,

I am trying to create an object model for a chatserver. The chatserver is the root class. any class inside the root class should not be instantiable or accessible outside of a chatserver object ( an instance of the chatserver class ).

There are 2 collections ( objects that act like a collection ) inside the ChatServer root object, Channels ( ChannelsCollection class ) and Clients ( ClientsCollection class ).
The Channels collection contains Channel objects ( instances of the Channel class ).
The Channel class should only be accessible from within the Channels colletion.

The Clients collection contains Client objects ( instances of the Client class ).
The Client class should only be accessible from within the Clients colletion.

A Channel object has a collection Clients ( same ClientsCollection class as used in the ChatServer object )

Here is a diagram:

ChatServer
      |     |
      | Channels
      |     |
      | Channel
      |  |
    Clients
      |
    Client

Can someone show me how thats done? ( Only Chatserver, Channels and Channel class is enough )
LVL 2
DaFouAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

petmagdyCommented:
class ChatServer
{
  private Channels channels = new Channels()
 
  public void addChannel(Channel channel)
  {
   // will call Channels method addChannel()
  }
 
  public Vector getChannels()
  {

  }
}

class Channels
{
 private Hashtable channels = new Hashtable();
 
 public void addChannel (Channel channel)
 {

 }

}


do u need more clarification?
0
petmagdyCommented:
offcourse u will also add method in Channels to retrieve channels, u can also replace HashTable with something like LinkedHashMap
0
petmagdyCommented:
this is a sample for JTDS, u need nothing special in Eclipse, just put in ur project library path the jTDS jar:

http://www.onjava.com/pub/a/onjava/2004/06/16/dbcancel.html?page=last&x-order=date
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

petmagdyCommented:
sorry !! 2 times in the same day the last comment is not for this thread
0
DaFouAuthor Commented:
also i would like indexers to work so that this would work

ChatServer lChatServer = new ChatServer();
lChatServer.Channels[ 0 ] // returns a channel object
and
lChatServer.Channels.Add( "ChannelName" ) // adds a channel object
0
petmagdyCommented:
in this case u must use LinkedHashMap instead of HashTable

the Channels class will look like :

import java.util.*;

class Channels
{
 private LinkedHashMap channels = new LinkedHashMap();
 
 public void addChannel (Channel channel)
 {

 }

 public Channel getChannelAt(int index)
 {
    Collection values = channels.values();
     Object[] channels = values.toArray();
    return (Channel) channels[index];
 }
}

add to ChatServer the method:

public Channel getChannelAt(int index)
{
 return channels.getChannelAt( index);

}


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DaFouAuthor Commented:
I am missing though how the Channels class is not instantiable from outside the ChatServer coz Channel class is public.
0
petmagdyCommented:
ok, in class Channels the add method will look like this

 public void addChannel (String channelName)
 {
   Channel channel = new  Channel(channelName, ..., ...);
   channels.put(channelName, channel);
   // or u decide what will be the key in ur LinkedHashMap
}

or can be:
public void addChannel (Channel channel)
 {
   channels.put(channel.getName(), channel);
}

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.