Turn: how to design business entities

Source: Internet
Author: User
Tags net serialization
Applies
    • Business Entity design in the business layer of an application.
Summary

Business entities are used to contain and manage business data used by an application. they shocould not contain any data access or business processing logic. business entities shoshould provide validation of the data contained within the entity. in addition, business entities provide properties and Operations used to access and initialize data contained within the entity.
Contents

    • Objectives
    • Overview
    • Summary of steps
    • Step 1-identify common data formats.
    • Step 2-choose the data format.
    • Step 3-Choose your design for custom objects (optional ).
    • Step 4-determine serialization support (optional ).
    • Additional resources
Objectives
    • Understand data formats and how the data will be used in the Application
    • Understand how rules affect the design of business entities
    • Choose an appropriate design if using objecm objects for business entities.
    • Determine how serialization is supported by different data formats.
Overview

This how to guide starts with a look at different data formats and how data will be used in your application. next, you will learn how the data format you choose determines how business rules can be implemented in your design. finally, you will learn about design options for custom objects and how to support serialization with different data formats.
Summary of steps

    • Step 1-identify common data formats.
    • Step 2-choose the data format.
    • Step 3-Choose your design for custom objects (optional ).
    • Step 4-determine serialization support (optional ).
Step 1-identify common data formats for business entities

In this step understand the data format's used business entities, understand the benefits and liabilities of each, which will help in choosing the correct data format for your scenario.
The common formats used to represent business data are datasets, XML, and custom objects.

  • Custom objects-Best suited for applications that have moderate to complex business rules associated with the data, but they can be used with any application type. there are two main design patterns associated with custom objects, domain model and table module. however, custom objects can also be used to represent XML structures, list items in a Sharepoint list, or any other structure used to hold data.
  • Dataset-Good for small amounts of data that have limited rules associated with the data. there are two types of datasets, standard and strongly typed. A Standard dataset uses string based names to access the data while a stronugly typed dataset provides a property based interface to the data.
  • Datatable-This is a component of datasets that can be used independently from a dataset. a datatable can be initialized and loaded with data independent of datasets. because they do not maintain schema data and changed data they have much less overhead than using a dataset. datatables can also be stronugly typed similar to datasets.
  • XML-A standards based format that contains structured data. this format wocould be used when interoperability with other platforms is desired. in addition, XML is often used for file based data used by the business layer. however, it is normally loaded into a Document Object Model or deserialized into objects for use within the business layer.

Each format has benefits and liabilities, which are listed below.

Data format
Benefits
Liabilities

Custom objects
Can support both connected and disconnected scenarios.
Entity design can be complex, especially when using a domain model design, which requires Domain Modeling experience.

Performs much better than other formats due to a smaller footprint, and binary serialization support.
May not map directly to relational structures in a database, which wowould require a mapping layer.

Can be used to represent complex relationships, and support complex rules.
Serialization support is not automatic, you must declare objects as serializable or implement serialization support.

Can be passed into SS appdomain, process, and physical boundaries.

Can be bound to controls in the user interface.

Wide range of options for entity design.

ADO. NET Entity Framework and ADO. Net LINQ provide extensive support for mapping objecm objects to data sources.

Dataset
Good For Disconnected scenarios where you open a connection to the data source, load the dataset, and close the connection immediately.
Datasets contain both the data and the data schema, which means they have a larger footprint than any other data format.

Can be passed into SS appdomain, process, and physical boundaries.
Although based on XML, the complexity of the dataset schema is not easy to read, parse, and understand, which limits their interoperability.

Changes to data in a dataset can be tracked while maintaining both the original and changed data.
Access errors with standard datasets are not discovered until runtime because string based names are used to access the data.

Can be reconnected to a data source in order to persist changes made to the dataset.

Supports filtered views of the data.

Can be bound to controls in the user interface.

Datatable
Much less overhead than using a dataset.
Access to fields in a standard datatable uses string based accessors, which can lead to defects that are not discovered until runtime.

Supported by ADO. Net dataadapters for fill operations.
Must be encoded in a dataset to generate xml.

You can define stronugly typed datatables that provide property based access to fields within the table.
They cannot be reconnected to a data source for updates. In other words, they do not provide the same level of disconnected behavior that a dataset does.

Supports filtered views of the data.

Can be bound to controls in the user interface.

XML
Supports interoperability with different platforms.
Requires extra code to consume the XML data for use within the business layer.

In its raw format, XML data can be manipulated with simple text editors.
Has a larger footprint than custom objects because XML data contains both the data and structure.

Can be passed into SS appdomain, process, and physical boundaries.

The. NET Framework provides extensive support for working with and managing XML data.

Step 2-Choose your data format

Now that you have an understanding of the data formats that can be used for business entities the next step is to choose one. there are several different factors that shoshould be considered. for example, complex rules are better handled with custom objects while a small document based application wowould benefit from the use of XML documents ENTs.
Consider using custom objects:

    • If you have complex business rules that need to be implemented
    • If you are using ADO. NET Entity Framework or ADO. Net LINQ
    • If you are working with large amounts of data.
    • If you want to maximize performance when passing data processing SS appdomain, process, and physical boundaries. Custom objects can be serialized using a binary format, which is much faster than XML formats.

Consider using Datasets:

    • If the business rules are limited or managed by an external business rules engine.
    • If you are designing a small web application or service, and you want to take advantage of the disconnected behavior provided by datasets.
    • If your application does not use a large amount of data that wocould need to be loaded into the dataset.
    • If you already have datasets defined, but are refactoring the application to take advantage of new features in ADO. Net LINQ. In this case you can use the LINQ to dataset provider.

Consider using datatables:

    • If the business rules are limited or managed by an external business rules engine.
    • If you are designing an application that uses ADO. net providers and want to take advantage of ADO. Net adapters to fill the datatable.
    • If you do not need the disconnected behavior provided by a dataset.

Consider using XML:

    • If you are designing a content based application with limited or no business rules.
    • If you are loading data from XML files that will be consumed by the application.
    • If you are designing a service that returns XML data to the consumer.

With the introduction of ADO. net EF and ADO. net LINQ, custom objects are the recommended choice for new applications that take advantage of these new features. however, you can also use LINQ to SQL for an existing application that already has datasets defined. XML data can also be de-serialized into custom objects, which can then be serialized back into XML as needed. with most new designs you shoshould always consider objecm objects as a first choice, which are now supported by ADO. net and generally perform much better than other formats in a distributed environment.
Step 3-Choose your design for custom objects (optional)

If you have determined that custom objects provide the best data format for business entities the next step is to design those objects. the design approach used for custom objects is based on the type of object that you plan to use. for instance, domain model entities require in-depth analysis of a business domain while Table module entities require an understanding of the database schema.
The following is a list of common design approaches when using custom objects:

  • Custom XML objects-Represent de-serialized XML data that can be manipulated within your application code. the objects are instantiated from classes defined with attributes used to map properties within the class to elements and attributes within the XML structure. the Microsoft. net Framework provides components that can be used to de-serialize XML data into objects and serialize objects into XML.
  • Domain Model -is based on an object oriented design pattern named domain model (Fowler ). the goal with a domain model design is to define objecm objects that are based on an analysis of the business domain. when using a domain model design the business, or domain, Entities contain both behavior and structure. in other words, business rules are encapsulated within the domain model. the domain model design requires in-depth analysis of the business domain and typically does not map to relational models used by most databases
  • Domain value objects -are lightweight objects that represent domain entities, but do not contain business rules. these objects are sometimes referred to data transfer objects (DTO), which is a design pattern used to package multiple data structures into a single structure for transfer processing SS appdomain, process, and physical boundaries. with a Domain value object the main goal is to define business entities that represent entities in the business domain while maintaining the relationship between those entities.
  • Table Module-Is based on an object oriented design pattern named table module (Fowler ). the objective of a table module design is to define entities that represent tables or views within a database. operations used to access the database and populate the table module entities are normally encapsulated within the entity. however, you can also use Data Access Components to perform database operations and populate table module entities.

Consider using custom XML objects:

    • If the data you are consuming is already in an XML format. For example, XML files or database operations that return XML as the result set.
    • If you need to generate XML data from non XML data sources.
    • If you are working with read-only document based data.

Consider using domain model:

    • If you have complex business rules related to the business domain.
    • If you are designing a rich client where the domain model can be initialized and kept in memory.
    • If you are not working with a stateless business layer that requires initialization of the domain model with every request.

Consider using Domain value objects:

    • If you have business rules that can be handled by external processing components.
    • If you are working with a stateless business layer where you are required to initialize business entities with each request.
    • If you want to use business entities that represent the business domain without encapsulating rules within the entities.

Consider using Table module:

    • If tables or views in the database represent business entities used by your application.
    • If you are working with either a stateless or stateful business layer.

When using objecm objects it is also not a requirement that all business entities follow the same design. for instance, you may have one aspect of the application with complex rules that may require a domain model design. however, the remainder of the application may use XML objects, a table module design, or Domain value objects that do not contain business rules.
Step 4-determine serialization support (optional)

If your application design is distributed into SS appdomain, process, and physical boundaries you will need to determine how serialization support is provided by different data formats.

  • Custom objects-As with XML data, serialization is based on how the custom object is used within your design. when used with Web Services and XML serializer is used and when used with WCF services the datacontractserializer is used. you can also use. net serialization by marking objects with a serializable attribute or implementing the iserializable interface.
  • Datasets-Are already designed to support serialization and can be passed into SS appdomain, process and machine boundaries. However, they are usually larger in size when compared to custom objects.
  • Datareaders-While datareaders are not used to represent business entities, they are often used to retrieve data and initialize custom objects. the datareader itself is not serializable, require a connection to a data source, and are not designed to be passed into SS appdomain, process or machine boundaries. in other words, the datareader needs direct access to a data source.
  • * XML data *-Serialization is based on how the XML data is represented. However, the. NET Framework provides extensive serialization support for XML data. In most cases attributes are used to control serialization.

 

 

From: http://www.codeplex.com/AppArch/Wiki/View.aspx? Title = How % 20to % 20-% 20 Design % 20 business % 20 entities & referringtitle = How % 20tos

Related Article

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.