本文介绍了我怎样才能创建工厂?客户端可以为接口中未定义的方法设置数据吗?(设计问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


你好,

Hello,

我的设计问题很少:我有一个工厂会创建一种类型或另一种类型的对象。但我的客户要求是将来自外部世界的数据(通过setter方法)提供给(输入)类型为1的具体类而不是类型2。

I am having little design problem: I have one factory which will create object of with one type or another type. But my client requirement is to give(feed) the data(via setter methods) from outside world to the concrete class of type-1 not for type-2.

If我将这些setter方法放在接口中,需要强制实现这两个具体类。这不是我的要求。我想为第一种类型(一些setter)提供1种数据,并希望为其他
类型提供另一种数据(可能是不同于前一种类型所包含的不同的设置者。)

If I place these setter methods in interface, those need to be implemented forcefully both of concrete classes. This is NOT my requirement. I want to feed 1 kind of data for 1st type(some setters) and want to give another kind of data for other type(probably different setters other than which's contained by previous type.)

例如

     class ISubjectExecutor
     
{
         
public:
       
virtual void ISUBJECTEXECUTOR_EXPORTS_API Execute()=0;  
     
};

     
class COMExecutor: public ISubjectExecutor
     
{
     
public:
     
virtual void Execute()=0;
           
void setCLSID();
           
void setGuids();

     
};
     
class Win32Executor : public IWin32Executor
     
{
       
public:              
     
virtual void Execute();
           
void setFilePath();

     
};


现在我不能使用ISubjectExecutor(* pSubjectExecutor)的指针在从工厂恢复指针(ISubjectExecutor)后随时调用我选择的Win32Executor或COMExecutor的setter方法。因为那些所有的setter都不存在于
ISubjectExecutor接口中,并且你不能访问任何从未包含在接口内并存在于具体实现中的方法。

Now here I can't use pointer of ISubjectExecutor (*pSubjectExecutor) to call setter methods of Win32Executor or COMExecutor on my choice at any time after reciving pointer(ISubjectExecutor) from factory. Because those all setters never exist inside ISubjectExecutor interface, and you can't access any method which's never contained inside interface and exist in concrete implementation.

如何解决这个设计问题需要解决。?

How to tackle this design problem to solve.?

Usman

推荐答案

请做正确的功能要求,你想要什么?什么是预期的输出然后考虑如何使用任何设计模式。

Please do put the right funcitonal requirement, what is exactly you want ? and what is expected output and then think how to use any design patterns in the first place.

 

请调查您的软件工程如何问题可以通过设计模式首先解决。请及时分析一下该地方的软件设计问题设计。深呼吸并用冷静的头脑分析问题。 

Please do investigate how your software engineering problem can be solve in the first place by a design pattern. Please do take time analyze the software design problem design at the place. Take a deep breath and analyze the problem with a cool head. 

 

然后认为需要解决软件设计问题有设计模式 如果答案是肯定的,请确定要使用的设计模式。首先,因为查询非常混乱,"请问正确的问题
,以便在功能要求方面得到正确答案"

Then think is it required to solve the software design problem with design pattern  and if the answer is yes , please do figure which design pattern to use. at the first place because the query is very confusing , " please do ask right question to get the right answer in terms of functional requirement"

问候,

Phijo Mathew Philip。

Phijo Mathew Philip.

 


这篇关于我怎样才能创建工厂?客户端可以为接口中未定义的方法设置数据吗?(设计问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 08:55