简体   繁体   中英

WCF static method in a class

I'm designing a WCF webservice that will potentially get called by 10,000+ plus separate clients at any given time. When the service gets called the service creates "Object1" class.

public List<string> AnswerClient() {
   Object1 _hello = new Object1();
   return _hello.AnswerClient();
}

Because the Object1 class needs to create other Object1 classes inside of it. It needs to create other subset Object1 classes. I was thinking of using static method in the Object1 class to create the other Object1 methods like

Object1.AnswerClient() 

because I don't think I need to create a specific Object1() in the first place. If multiple clients call the service, will this Object1.AnswerClient() mess up the code because it is static? Because statics are specific to the class, all the clients seem to be affected?

How should I design this class. Client calls service, service creates object based on client data. That object inside of it creates like 20 more similar objects (splits the user data depending on the data).

Any help and insight would help. How should I design this generally speaking?

Thanks.

If the AnswerClient method doesn't, in and of itself, require any state other than state it creates, there should be no issue with making it static.

That being said, I would think about this differently. Is AnswerClient really something that is a function of Object1 (which also could get a better name)? Or is it a general purpose utility method? If it's logically tied to a specific "Object1" instance, then I'd leave it as an instance method. If it's more of a general utility, and has no directly relation to whatever "Object1" represents, make it static.

我建议你看看工厂设计模式 ,做你上面描述的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM