Using the Domain Objects Persistence Pattern in .NETLearn MPS Technology on mps-technology.net. Using the Domain Objects Persistence Pattern in .NET article will help answer your questions on MPS Technology.We at mps-technology.net specialize in MPS Technology. MPS Technology at mps-technology.net provides the most up to date news and articles. If you have questions please do not hesitate to contact us.
A good design for domain objects requires a solid understanding of object oriented and relational fundamentals on the part of developers. Domain Objects Persistence Pattern attempts to provide a solution for domain object mapping to the relational databases that decouples the domain objects from the persistence logic. void Delete(Customer cust); // Query method to return a collection ArrayList FindCustomersByState(String state); } public class CustomerFactory : ICustomerFactory { // Standard transactional methods for single-row operations void Load(Customer cust) { /* Implement here */ } void Insert(Customer cust) { /* Implement here */ } void Update(Customer cust) { /* Implement here */ } void Delete(Customer cust) { /* Implement here */ } // Query method to retur Article: altarpiece Domain objects in an insistence represent the core data and miming validation rules relating to it. And, domain objects are usually concentrated to the entire demand and used by most subsystems. Therefore, their good design is critical for a good lucubration design that is robust, high performing, and yet flexible. When it comes to developing object oriented applications that use relational databases, the domain object design has to be consistent with the database design. This make them easier to understand inasmuch as they represent real-life 'entities' and their relationships with each other. Therefore, in many situations, the domain objects are 'mapped' to the relational database tables and relationships needle tables. However, it is very easy to get this mapping wrong and end up with an undesirable domain object design. A good design for domain objects requires a solid understanding of object oriented and relational fundamentals on the part of developers. Domain Objects Persistence Pattern attempts to provide a solution for domain object mapping to the relational databases that decouples the domain objects from the persistence logic. The domain objects in this pattern are unaware of the objects that persist them insofar as the dependency is only one-way (from persistence objects to domain objects). This makes the domain objects design much simpler and easier to understand. It also hides the persistence objects from other subsystems in the address that are using the domain objects. This also works in distributed systems where only the domain objects are passed around. In this context, an make an effort is made to incorporate the Factory Pattern into this pattern to help decouple domain objects and persistence logic. Scope Domain Objects, Persisting Domain Objects. Problem Definition Domain objects form the of any application. They nick the core data model from the database and also the utility rules that demand to this data. It is very typical for most subsystems of an ascription to rely on these well-understood domain objects. This means that the closer the domain objects map to the data model in the database, the easier it is for the perseverance developers to understand and use them inasmuch as they mimic real-life 'entities' and 'relationships' as represented in the database. If domain objects are not separated from the rest of the application, we end up with duplication of code everywhere. Similarly, if domain objects are not separated from the persistence code, we face situations where any subsystem using the domain objects also knows and depends on the persistence objects. And, any transmutation in persistence objects affects the entire application, hence a bad design. Solution One way to time in the again mentioned goals is to separate the domain objects into a separate subsystem and let the entire involvement use them wherever it needs domain data. Additionally, we should separate domain objects from the persistence code. This double-decoupling allows us on one hand to elude code duplication and on the other to hide the persistence details from the domain objects and make it more flexible in case it needs to change. The domain objects and the rest of the responsibility is totally unaffected whether the data is going to happen from a relational database or any other source (e.g. XML, flat files, or forceful Directory/LDAP). In separating the persistence logic from domain objects, we ensure that the domain objects have no dependency on the persistence code. This allows the domain objects to get to be on hand in environments where we don't even want to expose our persistence code. Sample Code In this sample, we will look at a Customer object from Northwind database mapped to the 'Customers' table in the database. public refinement Customer { // Private data members String _customerId; String _companyName; String _contactName; String _contactTitle; public Customer() {} // Properties for Customer object public String CustomerId { get { return _customerId; } set { _customerId = value;} } public String CompanyName { get { return _companyName; } set { _companyName = value;} } public String ContactName { get { return _contactName; } set { _contactName = value;} } public String ContactTitle { get { return _contactTitle; } set { _contactTitle = value;} } } public interface ICustomerFactory { // Standard transactional methods for single-row operations void Load(Customer cust); void Insert(Customer cust); void Update(Customer cust); void Delete(Customer cust); // Query method to return a collection ArrayList FindCustomersByState(String state); } public ilk CustomerFactory : ICustomerFactory { // Standard transactional methods for single-row operations void Load(Customer cust) { /* Implement here */ } void Insert(Customer cust) { /* Implement here */ } void Update(Customer cust) { /* Implement here */ } void Delete(Customer cust) { /* Implement here */ } // Query method to return a collection ArrayList FindCustomersByState(String state) { /* Implement here */ } } Below is an example of how a subject cotton will use this code. public agreeableness NorthwindApp { static void Main (string[] args) { Customer cust = new Customer(); CustomerFactory custFactory = new CustomerFactory(); // Let's load a customer from Northwind database. cust.CustomerId = 'ALFKI'; custFactory.load(cust); // Pass on the Customer object FooBar(cust);
// custList is a round-up of Customer objects
ArrayList custList = custFactory.FindCustomersByState('CA');
}
}
As you can see above, the 'load' method loads the Customer object from the database based on the CustomerId. Once the Customer is loaded, then it can be passed on to any subsystem in the inspection without exposing the persistence code. Similarly, if you get an ArrayList of Customer objects, you can pass on the ArrayList which has no persistence code dependency.
Conclusion
Using the Domain Objects Persistence pattern, we have extracted the persistence code out of the Customer object. This has made Customer object more object-oriented and simpler to understand insofar as its object model is closer to the data model in the database. And, finally, we have enabled the Customer object to be passed counter-clockwise to different parts of the deep thought (or even to distributed applications through .NET Remoting) without exposing its persistence code.
|
Advice Home Business Technology Online Advertising Motivational Internet Marketing SEO Help Online Games Science Articles Happiness More Articles:1. Encompix ERP Software Development Director James A. Hoium Makes Significant Contribution Summary: Cutler, spokesperson for the ETO Institute (www.etoinstitute.org), 'Encompix continues to capture significant marketshare in the ETO environment because few other ERP vendors truly understand the nuances and significant distinctions of the ETO process versus the repetitive manufacturing process. Encompix now has more than 200 of the leading ETO manufacturing firms in North America using their ERP Software solution.' Encompix www.encompix.com Roger Meloy 513-733-0066 # # # Article:Enco… 2. Guide to buying a digital camera Summary:The digital camera market today offers buyers a large number of choices, with products in widely differing price ranges, sizes and degree of operational complexity. And just having the facts may not make you feel any more knowledgeable about which camera is right for you. You could begin with the question: What sort of pictures will you take with your new digital camera? The point is, you need to begin by recognising that your reason for buying a digital camera may not be the same as tha… 3. aPriori: Materials, Labor, and Logistics are More Predictable Summary:According to Frank Azzolino, President and CEO of aPriori, 'Recent production use has demonstrated an 8 to 39% cost of goods (COGS) reduction for both new and mature products and a first year return-on-investment (ROI.) aPriori's Cost Management Platform is driving significant and substantial cost saving for customers. Article:akin to Frank Azzolino, President and CEO of aPriori, 'Recent production use has demonstrated an 8 to 39% cost of goods (COGS) reduction for both new and mature pr… 4. 10 Tips For Using Adobe Photoshop Summary: One can quickly flip through blend modes while trying out effects by using the keys 'shift+ to change to next mode and shift- to go to the previous mode.' When a painting tool is active this shortcut will change the blend mode of the painting tool. Use printer package when you want different image sizes on the same page, or multiple copies of the same image, or a text overlay. 6. or the complete editing history including the text that appears in the actions palette. Adobe Photoshop is a… |
||||