重新组织课程结构 [英] Reorganize classes structure

查看:118
本文介绍了重新组织课程结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

引用到我的<一个href="http://stackoverflow.com/questions/10329750/specify-interface-member-not-by-name-but-type">$p$pvious问题,故事开始于这一事实,我有一堆SvcUtil工具生成的类。他们自外部的WSDL产生。在这里你去:

Referencing to my previous question, the story begins in that fact that I have a bunch of svcutil-generated classes. They are generated from external WSDL. Here you go:

首先请求类:

public partial class getcarsRequest
{

    [System.ServiceModel.MessageHeaderAttribute(Namespace = "http://svc.datadomains.com/revision123_2/")]
    public CarsServiceApp.RequestHeader Header;

    [System.ServiceModel.MessageBodyMemberAttribute(Name = "getcarsRequest", Namespace = "carinfo", Order = 0)]
    public CarsServiceApp.getcars MessageWrap;

    public getcarsRequest()
    {
    }

    public getcarsRequest(CarsServiceApp.RequestHeader Header, CarsServiceApp.getcars getcarsRequest1)
    {
        this.Header = Header;
        this.MessageWrap = getcarsRequest1;
    }
}

public partial class getcars
{

    private MessageType messageField;

    private MessageDataGetcarsRequest messageDataField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order = 0)]
    public MessageType Message
    {
        get
        {
            return this.messageField;
        }
        set
        {
            this.messageField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order = 1)]
    public MessageDataGetcarsRequest MessageData
    {
        get
        {
            return this.messageDataField;
        }
        set
        {
            this.messageDataField = value;
        }
    }
}

public partial class MessageDataGetcarsRequest
{

    private AppDataGetcarsRequest appDataField;

    private AppDocumentType appDocumentField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order = 0)]
    public AppDataGetcarsRequest AppData
    {
        get
        {
            return this.appDataField;
        }
        set
        {
            this.appDataField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order = 1)]
    public AppDocumentType AppDocument
    {
        get
        {
            return this.appDocumentField;
        }
        set
        {
            this.appDocumentField = value;
        }
    }
}

public partial class AppDataGetcarsRequest
{
    private string addressField;

    private int codeField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order = 0)]
    public address address
    {
        get
        {
            return this.addressField;
        }
        set
        {
            this.addressField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order = 1)]
    public int code
    {
        get
        {
            return this.codeField;
        }
        set
        {
            this.codeField = value;
        }
    }

}

二:

public partial class getdriversRequest
{

    [System.ServiceModel.MessageHeaderAttribute(Namespace = "http://svc.datadomains.com/revision123_2/")]
    public carsServiceApp.RequestHeader Header;

    [System.ServiceModel.MessageBodyMemberAttribute(Name = "getdriversRequest", Namespace = "driverinfo", Order = 0)]
    public carsServiceApp.getdrivers MessageWrap;

    public getdriversRequest()
    {
    }

    public getdriversRequest(carsServiceApp.RequestHeader Header, carsServiceApp.getdrivers getdriversRequest1)
    {
        this.Header = Header;
        this.MessageWrap = getdriversRequest1;
    }
}

public partial class getdrivers
{

    private MessageType messageField;

    private MessageDataGetdriversRequest messageDataField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order = 0)]
    public MessageType Message
    {
        get
        {
            return this.messageField;
        }
        set
        {
            this.messageField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order = 1)]
    public MessageDataGetdriversRequest MessageData
    {
        get
        {
            return this.messageDataField;
        }
        set
        {
            this.messageDataField = value;
        }
    }
}

public partial class MessageDataGetdriversRequest
{

    private AppDataGetdriversRequest appDataField;

    private AppDocumentType appDocumentField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order = 0)]
    public AppDataGetdriversRequest AppData
    {
        get
        {
            return this.appDataField;
        }
        set
        {
            this.appDataField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order = 1)]
    public AppDocumentType AppDocument
    {
        get
        {
            return this.appDocumentField;
        }
        set
        {
            this.appDocumentField = value;
        }
    }
}

public partial class AppDataGetdriversRequest
{
    private string nameField;

    private int customerCodeField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order = 0)]
    public name name
    {
        get
        {
            return this.nameField;
        }
        set
        {
            this.nameField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order = 1)]
    public int customerCode
    {
        get
        {
            return this.customerCodeField;
        }
        set
        {
            this.customerCodeField = value;
        }
    }

}

这是由SvcUtil工具产生的只是两个实体。有迹象表明,喜欢这两不同只能由最底层的 AppData的属性另一个实体。我写了一个电源外壳脚本,preparing原始生成的文件重命名某些领域,但这还不足以让所有的工作完成。

This is just two entity generated by svcutil. There are another entities that like this two differs only by most underlying AppData property. I wrote a power shell script that preparing raw generated file renaming some fields but this is not enough to get all work done.

我怎样才能创作班的团结?好像我应该使用参数化界面... 我需要团结班级结构,制定共同的实用功能,如检查的要求是正确的还是从头开始创建的请求。

How can I compose classes unity? It seems like I should use parametrized interface... I need united classes structure to devise common useful functions like checking that request is correct or create request from scratch.

在此先感谢,伙计们!我的大脑煮有关的东西。

Thanks in advance, guys! My brains are boiled about that stuff.

问题编辑#1

好了,伙计们,这里就是我想有。让我们说,我们要检查的正确性任何服务方法的要求。如果一定要求的 AppData的属性不为null,我们应该考虑这一要求是正确的。实际上这将是更好的,我们有一些共同的类的方法,这样的检查。但是,我们如何才能使这种方法,如果任何请求类有不同的 AppData的属性类型?

Ok, guys, here is that I would like to have. Let say we want to check any service method's request for correctness. If some request's AppData property isn't null we should consider that request as correct. Actually it would be better for us to have some common class' method for such checking. But how can we make that method if any request class has different AppData property types?

让来看看两个生成的类并得出一些虚路径,每个应用程序数据的属性。

Let take a look at two generated classes and draw some imaginary path to each AppData properties.

有关头等舱,getcarsRequest我们(在括号中,我们有相应的类类型):

For first class, getcarsRequest we have (in parentheses we has appropriate class type):

请求(getcarsRequest) - > MessageWrap(getcars) - > MessageData   (MessageDataGetcarsRequest) - >应用程序数据(AppDataGetcarsRequest)

request (getcarsRequest) -> MessageWrap (getcars) -> MessageData (MessageDataGetcarsRequest) -> AppData (AppDataGetcarsRequest)

对于第二个我们有一个路径:

For the second we have next path:

请求(getdriversRequest) - > MessageWrap(getdrivers) - > MessageData   (MessageDataGetdriversRequest) - >应用程序数据(AppDataGetdriversRequest)

request (getdriversRequest) -> MessageWrap (getdrivers) -> MessageData (MessageDataGetdriversRequest) -> AppData (AppDataGetdriversRequest)

那么怎样才能redevise,并减少他们的一些通用接口?如果我们有合适的,通用的接口为两个类,我们可以写一些 CheckRequest(IRequest&LT; T&GT;的要求)。

So how can we redevise and reduce them to some generic interface? If we have an appropriate, common interface for that two classes we could write some CheckRequest(IRequest<T> request).

我希望我在这里得到一些清晰度。任何建议/判决将是非常美联社preciated。如果你对我有什么问题,请随时拿过来给我。

I hope I get some clarity here. Any advices/sentences will be very appreciated. If you have any questions for me please feel free to bring them to me.

推荐答案

据我了解,你有两个类结构被有效地重复:汽车和司机。而不是修改生成的类,你应该专注于结构调整您的输入WSDL(我们还没有见过的)。

As I understand it, you have two class structures that are effectively duplicated: car and driver. Instead of modifying the generated classes, you should focus on restructuring your input wsdl (which we havent seen yet).

为了消除这种重复,可以考虑做两个对象:汽车,司机和重组WSDL操作以这样的方式,他们可以在任何一种类型的对象进行操作。在面向对象的计算,两轿厢和司机应该继承将具有抽象方法,可以通过将wsdl操作被称为相同的基类。这些抽象方法,然后将需要在派生/具体类的汽车和司机实施。

In order to remove this duplication, consider making two Objects: car and driver and restructuring the wsdl operations in such a way that they can operate on either type of Object. In Object Oriented terms, both car and driver should inherit from the same base class that will have abstract methods that can be called by the wsdl operations. These abstract methods would then need to be implemented in the car and driver derived/concrete classes.

这篇关于重新组织课程结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆