Help in Project Model

P

pek

Hello everyone and thnx for any help..

I have a little structure problem. I don't quite know how to model my
objects. Any help is appreciated.

So, the problem is this. I have a class named Motherboard. Now, I know
motherboards support modules such as CPU, Memory etc. So I have to
create a spec for each module. Then I want to create some, let's say
for now, CPU Modules that have name, the specs etc. I want to select a
CPU and find out if the motherboard supports this CPU module.

My current model is the following.
I have a class (probably an Interface) ModuleSpec. For each separate
module (CPU, Memory etc.) you implements this and have it's
specifications that a motherboard needs to know (CPU Socket etc.).
Then I have a Module class (also probably an Interface) that each
separate module implements (CPUModule, MemoryModule) etc. And finally
a Motherboard class that has a list of ModuleSpec.

Now, ModuleSpec has a method isCompatible(Module module) which is
called to each module by the Motherboard class every time you try to
add a module (Motherboard.addModuleSpec(ModuleSpec spec)). This
returns a boolean.

What I don't like about my current model is that ModuleSpec and Module
is different interfaces while i KNOW that almost anything a ModuleSpec
has a Module MUST have. So it's kinda useless to define the same
things in both classes.
On the other hand, let's take CPUModuleSpec for example. It has a list
of compatible sockets. CPUModule has only one Socket (the one it has).
Also, a motherboard can have more than one Memory module, so I put as
many memory specs as needed by the motherboard and don't have a number
that tells how many (which could also be the case).

Any comments/ideas etc. welcome.

Thank you.
 
J

Jason Cavett

Hello everyone and thnx for any help..

I have a little structure problem. I don't quite know how to model my
objects. Any help is appreciated.

So, the problem is this. I have a class named Motherboard. Now, I know
motherboards support modules such as CPU, Memory etc. So I have to
create a spec for each module. Then I want to create some, let's say
for now, CPU Modules that have name, the specs etc. I want to select a
CPU and find out if the motherboard supports this CPU module.

My current model is the following.
I have a class (probably an Interface) ModuleSpec. For each separate
module (CPU, Memory etc.) you implements this and have it's
specifications that a motherboard needs to know (CPU Socket etc.).
Then I have a Module class (also probably an Interface) that each
separate module implements (CPUModule, MemoryModule) etc. And finally
a Motherboard class that has a list of ModuleSpec.

I'm going to stop reading here because I have some questions. First,
for clarification, are you saying:

public class CPUModule implements ModuleSpec, Module

Is that right? If so, why do you have a ModuleSpec AND a Module.
What does that give you? In fact, you kind of say it yourself...
So it's kinda useless to define the same things in both classes.

BTW - I think you mean "both interfaces," but that's a minor point.

The rest gets confusing and, at this point, I don't think it matters.
 
P

pek

I'm going to stop reading here because I have some questions. First,
for clarification, are you saying:

public class CPUModule implements ModuleSpec, Module

Is that right? If so, why do you have a ModuleSpec AND a Module.
What does that give you? In fact, you kind of say it yourself...


BTW - I think you mean "both interfaces," but that's a minor point.

The rest gets confusing and, at this point, I don't think it matters.

Yes, I didn't exactly explained it correctly.

No, CPUModule implements Module (which currently does nothing other
than defining it's a Module).
CPUModuleSpec on the other hand implements ModuleSpec (which
implements the method isCompatible(Module module)).

CPUModuleSpec has a list of CPUSockets (to define what type of sockets
it can support)
CPUModule on the other hand has only one CPUSocket.

These two have in common a CPUSocket, but the Spec has it multiple
times and the Module only once.
I just try to figure out what is the best practice for this.

Thank you.
 
J

Jason Cavett

Yes, I didn't exactly explained it correctly.

No, CPUModule implements Module (which currently does nothing other
than defining it's a Module).
CPUModuleSpec on the other hand implements ModuleSpec (which
implements the method isCompatible(Module module)).

CPUModuleSpec has a list of CPUSockets (to define what type of sockets
it can support)
CPUModule on the other hand has only one CPUSocket.

These two have in common a CPUSocket, but the Spec has it multiple
times and the Module only once.
I just try to figure out what is the best practice for this.

Thank you.

Okay, so the way you currently have it is...

class CPUModule implements Module {
CPUSocket socket;

// other stuff done here
}


class CPUModuleSpec implements ModuleSpec {
List<CPUSocket> sockets;

public boolean isCompatible(Module module) {
// implementation to check of module is part of the sockets list
// return true if the CPUModule can support the socket, false
otherwise
}
}

Assuming I got all that right from your description...well...

From the looks of things, everything *seems* to be fine (without know
more about your problem, of course). It seems as though CPUModule
should have a CPUModuleSpec (AKA - there is a CPUModuleSpec variable
within CPUModule).

The isCompatible(Module) method makes sense because you want to check
your spec before you set a socket on the CPUModuleSpec by looking at
the list of sockets. SO...I would do something like this...


class CPUModule implements Module {
CPUModuleSpec specification;
CPUSocket socket;

public void setSocket(CPUSocket socket) {
if(specification.isCompatible(socket)) {
this.socket = socket;
}
}
}

CPUModuleSpec would stay the same. Basically, you want CPUModule to
have its spec so it can use the spec to enforce certain rules. Does
that make sense?


Hope that helps.
 
P

pek

Okay, so the way you currently have it is...

class CPUModule implements Module {
CPUSocket socket;

// other stuff done here

}

class CPUModuleSpec implements ModuleSpec {
List<CPUSocket> sockets;

public boolean isCompatible(Module module) {
// implementation to check of module is part of the sockets list
// return true if the CPUModule can support the socket, false
otherwise
}

}

Assuming I got all that right from your description...well...

From the looks of things, everything *seems* to be fine (without know
more about your problem, of course). It seems as though CPUModule
should have a CPUModuleSpec (AKA - there is a CPUModuleSpec variable
within CPUModule).

The isCompatible(Module) method makes sense because you want to check
your spec before you set a socket on the CPUModuleSpec by looking at
the list of sockets. SO...I would do something like this...

class CPUModule implements Module {
CPUModuleSpec specification;
CPUSocket socket;

public void setSocket(CPUSocket socket) {
if(specification.isCompatible(socket)) {
this.socket = socket;
}
}

}

CPUModuleSpec would stay the same. Basically, you want CPUModule to
have its spec so it can use the spec to enforce certain rules. Does
that make sense?

Hope that helps.

Well, you got the idea. Yes. But this is what I am trying to do.

I want to have a Motherboard class that has a list of ModuleSpecs
(CPUSpec, MemorySpec etc.). These specs basically tells what modules
the motherboard can add to itself (so there is no meaning to put the
spec to the CPUModule).

Each Motherboard class is saved in a database with it's spec. Then,
each Module is saved in the database with it's attributes (CPUModule
with it's Socket etc.).
While I don't really find anything wrong in this model, I don't really
like when I know that both CPUModule and CPUModuleSpec will have
socket's (the spec has a list and the module just one). I think there
is an easier way, but I just figure it out.

SO, here will an example code of what am I thinking it should look
like.

(creating a Motherboard and saving it to the database method)
Motherboard mother = new Motherboard();
CPUModuleSpec cpuSpec = new CPUModuleSpec();
cpuSpec.addCompatibleSocket(CPUModuleSpec.Sockets.Socket446);
cpuSpec.addCompatibleSocket(CPUModuleSpec.Sockets.Socket447);
mother.addModuleSpec(cpuSpec);
....
add more module specs
and save it to the database
....

(creating a CPU and saving it to the database method)
CPUModule cpu = new CPUModule();
cpu.setSocket(CPUModuleSpec.Sockets.Socket446);
cpu.setClockSpeed(3000);
....
add more attributes
and save it to the database
....

(Trying to find out if a motherboard can attach a specific cpu method)
....
get a motherboard and a cpu from the database
....
if (mother.isCompatible(cpu))
System.out.println("OK");
else
System.out.println("Not Compatible");


I hope this was even more helpful.
Thank you very much for your time. ;)

regards
pek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top