Pergunta

I'm trying to build a model of the servers and applications at my workplace. A server can host many applications. An application can be hosted across many servers.

Normally I would just have the host class contain a List, and the application class a List. However, there are a few fields that are specific to the particular host-application relationship. For example, UsedMb represents the amount of disk-space used by an application on a host.

I could, of course have a HostedApplicationclass representing an intermediate object which would hold the UsedMb field. Both Host and Application classes would then contain a List.

The problem is, however, that an application needs also to know about some aspects of its Host that would be included in the Host class (for example, the hosts are geographically distrubuted; an application needs to know how many data centres it is hosted in, so it needs to be able to check the DC names of all its hosts.

So instead I could have the HostedApplication class hold references to both the Host object and Application object it refers to. But then in some cases I will need to loop through all applications (and in other cases, all hosts). Therefore I would need 3 separate lists, a List, and List, and a List, to be able to loop through all three as needed.

My basic question is, what is the standard way of dealing with this sort of configuration? All options have advantages and disadvantages. The last option I mentioned seems most correct, but is having three lists overkill? Is there a more elegant solution?

Foi útil?

Solução

Ideally i would be able to talk to you about the problem, but here is a potential solution based on my rough understanding of the requirements ( c++ style with a lot of implementation left out)

class Host {
public:

  string GeographicLocation() const;
  string DCName() const;
};

class HostAsAppearsToClient : public Host {

  HostAsAppearsToClient(const Host&);
  // Allows Host -> HostAsAppears... conversion

  size UsedMB() const;
  void UseMoreMB(size) const;
};

class Client {
  HostAsAppearsToClient* hosts;

  void AddHost(const Host& host) {
    // Reallocate enough size or move a pointer or whatever
    hosts[new_index] = HostAsAppearsToClient(host);
    hosts[new_index].UseMoreMB(56);
  }

  void DoSomething() {
    hosts[index].UsedMB();
    // Gets the MB that that host is using, and all other normal host data if
    // we decide we need it ...
    print(hosts[index].DCName());
  }
};

int Main() {
  Host* hosts = new Host[40];
  Client* clients = new Client[30];

  // hosts[2].UsedMB() // Doesn't allow
}

I fully expect that this does not meet your requirements, but please let me know in what way so that I can better understand your problem.

EDIT:

VBA .... unlucky :-P

It is possible to load dll's in VBA, which would allow you to write and compile your code in any other language, and just forward the inputs and outputs through VBA from the UI to the DLL, but i guess its up to you if thats worth it. Documentation on how to use a dll in VBA Excel: link

Good Luck!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top