[Architecture Pattern] entity Profile

Source: Internet
Author: User

Motivation:

The previous article [application architecture]: entity expansion mode describes a mode for extending object attribute data. This article continues the motivation of the previous article and introduces an entity profile model.

 

Entity profile mode defines a group of Data Objects (entity) and repository generation, structure, and behavior patterns, which are used to extend the attribute data of objects. In this mode, you can add additional program code accumulation capabilities to the system.

 

Basic Platform:

Structure

 

Participants

Page Shell
-The page shell layer allows you to dynamically mount the system on the system page by setting data.

 

Sample program

Page shell has different options depending on the development platform. For example. NET platform, you can directly apply ASP.. NET page mechanism, and then create an index page. Modify the index page to dynamically mount the system page.

 

Basic Project:

Structure

 

Participants

Usermanagepage
-The user management page provides the functions of adding, modifying, deleting, and querying users.
-Use spring. NET and provider pattern to reflect and generate iuserprofilerepository.
-Use the generated iuserprofilerepository to generate the userrepository.
-Use userrepository to add, modify, delete, and query users.

 

USERPROFILE
-Data Objects entering and exiting the system boundary.

 

Iuserprofilerepository
-Interface for entering and exiting the system boundary of the Data Object USERPROFILE.
-Added, modified, deleted, and queried functions.

 

User
-Data Objects used for system operation.
-Attribute data is stored in USERPROFILE.

 

Userrepository
-Interface for the user of the data object to access the system boundary.
-Use iuserprofilerepository to process the USERPROFILE obtained by the user of the data object.
-Added, modified, deleted, and queried functions.

 

Sample program

Namespace CLK. entityprofile {public class usermanagepage {public void showuser () {// getdata iuserprofilerepository userprofilerepository = NULL; // use spring. NET and provider pattern for reflection generation. (Base project generation and ex project generation generate the same iuserprofilerepository) userrepository = new userrepository (userprofilerepository); ienumerable <user> usercollection = userrepository. getall (); // show this. showuser (usercollection);} private void showuser (ienumerable <user> usercollection ){//.....}} public class USERPROFILE: dictionary <string, string> {public guid userid {Get; Set ;}} public interface iuserprofilerepository {// Methods void add (USERPROFILE item ); void modify (USERPROFILE item); void remove (guid ID); USERPROFILE getbyid (guid ID); ienumerable <USERPROFILE> getall ();} public class user {// properties protected internal USERPROFILE profile {Get; private set;} public guid userid {get {return this. profile. userid;} set {This. profile. userid = value ;}} public string name {get {return convert. tostring (this. profile ["name"]);} set {This. profile ["name"] = value ;}} Public String description {get {return convert. tostring (this. profile ["Description"]);} set {This. profile ["Description"] = value ;}// constructor public user () {This. profile = new USERPROFILE (); this. userid = guid. empty; this. name = string. empty; this. description = string. empty ;}} public class userrepository {// properties private readonly role _ userprofilerepository = NULL; // constructor public userrepository (role userprofilerepository) {# region require if (role = NULL) throw new argumentnullexception (); # endregion _ userprofilerepository = userprofilerepository;} // Methods private user createuser (USERPROFILE) {# region require if (USERPROFILE = NULL) throw new argumentnullexception (); # endregion user = new user (); User. userid = USERPROFILE. userid; foreach (string key in USERPROFILE. keys) {user. profile. add (Key, USERPROFILE [Key]);} return user;} private USERPROFILE createuserprofile (User user) {# region require if (user = NULL) throw new argumentnullexception (); # endregion return user. profile;} public void add (User item) {# region require if (item = NULL) throw new argumentnullexception (); # endregion _ userprofilerepository. add (this. createuserprofile (item);} public void modify (User item) {# region require if (item = NULL) throw new argumentnullexception (); # endregion _ userprofilerepository. modify (this. createuserprofile (item);} public void remove (guid ID) {# region require if (ID = guid. empty) throw new argumentnullexception (); # endregion _ userprofilerepository. remove (ID);} public user getbyid (guid ID) {# region require if (ID = guid. empty) throw new argumentnullexception (); # endregion return this. createuser (_ userprofilerepository. getbyid (ID);} public ienumerable <user> getall () {list <user> itemcollection = new list <user> (); foreach (USERPROFILE in _ userprofilerepository. getall () {itemcollection. add (this. createuser (USERPROFILE) ;}return itemcollection ;}}}

 

Extended project:

Structure

 

Participants

Exusermanagepage
-The exuser Management page provides the functions of adding, modifying, deleting, and querying users.
-Use spring. NET and provider pattern to reflect and generate iuserprofilerepository.
-Use the generated iuserprofilerepository to generate exuserrepository.
-Use exuserrepository to add, modify, delete, and query exusers.

 

Exuser
-Data Objects used for system operation.
-Attribute data is stored in USERPROFILE.

 

Exuserrepository
-Interface for the Data Object exuser to access the system boundary.
-Use iuserprofilerepository to process the USERPROFILE obtained from the data object exuser.
-Added, modified, deleted, and queried functions.

 

Sample program

Namespace CLK. entityprofile. Expanded {public class exusermanagepage {public void showexuser () {// getdata iuserprofilerepository userprofilerepository = NULL; // use spring. NET and provider pattern for reflection generation. (Base project generation, ex project generation, all generate the same region) exuserrepository = new exuserrepository (userprofilerepository); ienumerable <exuser> exusercollection = exuserrepository. getall (); // show this. showexuser (exusercollection);} private void showexuser (ienumerable <exuser> exusercollection ){//.....}} public class exuser: User {// properties Public String address {get {return convert. tostring (this. profile ["Address"]);} set {This. profile ["Address"] = value ;}// constructor public exuser (): Base () {This. address = string. empty ;}} public class exuserrepository {// properties private readonly role _ userprofilerepository = NULL; // constructor public exuserrepository (role userprofilerepository) {# region require (role = NULL) throw new argumentnullexception (); # endregion _ userprofilerepository = userprofilerepository;} // Methods private exuser createexuser (USERPROFILE) {# region require if (USERPROFILE = NULL) throw new argumentnullexception (); # endregion exuser = new exuser (); exuser. userid = USERPROFILE. userid; foreach (string key in USERPROFILE. keys) {exuser. profile. add (Key, USERPROFILE [Key]);} return exuser;} private USERPROFILE createuserprofile (exuser) {# region require if (exuser = NULL) throw new argumentnullexception (); # endregion return exuser. profile;} public void add (exuser item) {# region require if (item = NULL) throw new argumentnullexception (); # endregion _ userprofilerepository. add (this. createuserprofile (item);} public void modify (exuser item) {# region require if (item = NULL) throw new argumentnullexception (); # endregion _ userprofilerepository. modify (this. createuserprofile (item);} public void remove (guid ID) {# region require if (ID = guid. empty) throw new argumentnullexception (); # endregion _ userprofilerepository. remove (ID);} public exuser getbyid (guid ID) {# region require if (ID = guid. empty) throw new argumentnullexception (); # endregion return this. createexuser (_ userprofilerepository. getbyid (ID);} public ienumerable <exuser> getall () {list <exuser> itemcollection = new list <exuser> (); foreach (USERPROFILE in _ userprofilerepository. getall () {itemcollection. add (this. createexuser (USERPROFILE);} return itemcollection ;}}}

 

Conclusion:

In this example, the user of the basic project and the exuser of the Extension Project are converted into a unified USERPROFILE, and a common iuserprofilerepository entry and exit system boundary is used. (* There are various implementation methods for USERPROFILE)

 

The entity profile model introduced in this article extends the attribute data of an object, but it can be viewed as a responsibility to forcibly extend the object's access to system boundaries. Based on this model, we can theoretically design an application system architecture that can infinitely expand attribute data.

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.