Re: Help in Project Model
On Nov 28, 5:27 pm, pek <kimwl...@gmail.com> wrote:
On Nov 28, 6:28 am, Jason Cavett <jason.cav...@gmail.com> wrote:
On Nov 27, 12:02 pm, pek <kimwl...@gmail.com> wrote:
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.
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.