help.axcms.netAxinom Logo
Save Save Chapter Send Feedback

Inter-Pattern Usage

Generally speaking you can combine any patterns in your code: Adapter, Generic Adapter, DbObject. This article discuss the particular choices.

As described in the Overview the three patterns have their own advantages or disadvantages. It can happen that you use different patterns for your different BL objects. In this case you probably want to know if and how it is possible to integrate several patterns. What if you implement your Article object using one pattern and your Order object (referencing an article object) using another pattern?

Generally speaking you can combine any patterns in your code.

The following table summarizes all six inter-pattern possibilities. The rows in the table represent the patterns of the Article object and the columns represent patterns of the Order object.

Adapter pattern Generic Adapter pattern DbObject pattern
Adapter pattern no additional measures required

Use an additional attribute in the Order class specifying the adapter class to use.

Use an additional attribute in the Order class specifying the adapter class to use.

Generic Adapter pattern

Use generic adapter for Article in the Mappings property of the OrderAdapter.

no additional measures required no additional measures required
DbObject pattern

Use class Article in the Mappings property of the OrderAdapter and everywhere when an article adapter is needed.

no additional measures required no additional measures required

Article implemented with Adapter pattern, and Order with Generic Adapter pattern.
Use an additional attribute in the Order class specifying the adapter class to use:

[AxDbUseAdapter(typeof(ArticleAdapter))]
[AxDbMapToField("ArticleID")]
public Article Article
{
    get { return _article; }
    set
    {
        if (value != _article) SetDirty();
        _article = value;
    }
}

Article implemented with Adapter pattern and Order with DbObject pattern. 
Use an additional attribute in the Order class specifying the adapter class to use:

[AxDbUseAdapter(typeof(ArticleAdapter))]
[AxDbMapToField("ArticleID")]
public Article Article
{
    get { return _article; }
    set
    {
        if (value != _article) SetDirty();
        _article = value;
    }
}

Article is implemented with Generic Adapter pattern and Order with Adapter pattern.
Use generic adapter for Article in the Mappings property of the OrderAdapter:

public override AxDbFieldMapping[] Mappings
{
    get
        {
            return new AxDbFieldMapping[]
                 {
                     new AxDbFieldMapping("ID", "ID", true),
                     new AxDbFieldMapping("OrderDate"),
                     new AxDbAdapter(typeof(Article),
                                    
this.ConnectionManager,
                                    
"ArticleID",
                                     "Article")
                 };
        }
}

Article is implemented with DbObject pattern and Order with Adapter pattern. 
Use class Article in the Mappings property of the OrderAdapter and everywhere when an article adapter is needed.

public override AxDbFieldMapping[] Mappings
{
    get
    {
        Article articleAdapter = new Article();
        articleAdapter.ConnectionManager = this.ConnectionManager;
        articleAdapter.PropertyName = "Article";
        articleAdapter.FieldName = "ArticleID";

        return new AxDbFieldMapping[]
            {
                new AxDbFieldMapping("ID", "ID", true),
                new AxDbFieldMapping("OrderDate"),
                articleAdapter                               
            };
    }
}