Example of three-layer architecture and generics using activerecord

Source: Internet
Author: User
It's just a framework. For more information about activerecord development, see terrylee's castle development article. During the development framework encapsulation, we encountered the problem of ignoring the calling of different business objects for simplified consideration. Therefore, we have added uibase with a generic parameter, however, this makes it much more complicated. I want to hear your opinions!

Using system;
Using system. Collections. Generic;
Using system. text;

Namespace consoleapplication2
{
Database access layer # region database access layer
/** // <Summary>
/// Database layer base class.
/// </Summary>
/// <Typeparam name = "T"> </typeparam>
Abstract class modelbase <t>
{
Public modelbase ()
{
}


Public abstract string current
{
Get;
}
}

/** // <Summary>
/// Database and entity layer.
/// </Summary>
Class model: modelbase <model>
{
Public Model ()
{
}


Public override string current
{
Get {return "model ";}
}
}
# Endregion

Business Layer # Region Business Layer
/** // <Summary>
/// Business layer.
/// </Summary>
/// <Typeparam name = "model"> </typeparam>
Class controller <model> where model: modelbase <model>, new ()
{
Public controller ()
{
}

Model _ model;
Public String getcurrent ()
{
_ Model = new model ();
Return _ model. Current;
}
}
# Endregion

Interface Layer # region Interface Layer
/** // <Summary>
/// Interface layer. You can call different business objects and database objects through generic parameters.
/// </Summary>
/// <Typeparam name = "M"> </typeparam>
/// <Typeparam name = "C"> </typeparam>
Class uibase <m, C> where C: controller <m>, new () where M: modelbase <m>, new ()
{
C _ c = new C ();

Public uibase ()
{
}

Public String getcurrent ()
{
Return _ c. getcurrent ();
}
}
# Endregion

/** // <Summary>
/// Test.
/// </Summary>
Class Program
{
Static void main (string [] ARGs)
{
Uibase <model, controller <model> _ base = new uibase <model, controller <model> ();

Console. writeline (_ base. getcurrent ());
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.