Showing posts with label .Net Framework. Show all posts
Showing posts with label .Net Framework. Show all posts

Sunday, November 8, 2009

PONO Plain old .Net object

i read this paragraph in other blog through searching the internet to discover the meaning of the PONO and i want to share this with you: 


I want to enforce that the domain is the core, the centerpiece, the kernel as you may of my application. I don’t want it to have any dependencies to other assemblies in my application, especially not the infrastructure assembly. This means that my domain assembly can only have a reference to the .NET framework assemblies and nothing else.


if domain objects are only made of primitive types, we could call PONO : Plain Old .NET Object in reference to Java POJO orPOCOPlain Old CLR Object. Such convention garantees that domain object are re-usable across layers and potentially increase performance since all these primitive types are CLR-optimized


so in other meaning we can Just say it is a normal class, no attributes describing infrastructure concerns or other responsibilities that your domain objects shouldn't have. POJO's (for java) are just classes which dont force inheritance or any attribute markup to make them "work" in whatever framework you are using.

POCO's are the same, except in .NET.
for example, .Net 3.5 sp1 ORM example: the Entity framework requires that classes inherit from a certain framework class. LINQ to SQL does not have this requirement. Therefore LINQ to SQL works with POCOs and the Entity framework does not
PONO (plain old .net object) is equivalent to POCO (plain old CLR object)

References 
http://codebetter.com/blogs/patricksmacchia/archive/2008/06/30/simple-core-domain-types-and-plain-old-net-objects.aspx



Monday, September 14, 2009

Passing Interface & object to Method in .Net

in this post i will illustrate the difference between passing object and interface to method, suppose that we have currency class and implement the interface ICurrency ...... Let's go through the code to discover the difference

public static decimal ExchangeRate(ICurrency FromCurrency, ICurrency targetCurrency)

{

}

public static decimal ExchangeRate(Currency FromCurrency, Currency targetCurrency)

{

}

the difference is so simple -->Using ICurrency in the method signature will allow you to pass any object of a class that implements ICurrency, while using Currency in the method signature will only allow you to pass a Currency object.

For example: If you only want the method signature to accept a System.Data.SqlClient.SqlDataReader object, then you would use that. However, if you wanted it to accept any DataReader object you would use System.Data.IDataReader since all DataReader classes implement System.Data.IDataReader. That is one of the nice things about interfaces





Sunday, June 7, 2009

2 Minute at Resource File in .Net

The .resx resource file format consists of XML entries, which specify objects and strings inside XML tags. One advantage of a .resx file is that when opened with a text editor (such as Notepad or Microsoft Word) it can be written to, parsed, and manipulated. When viewing a .resx file, you can actually see the binary form of an embedded object (a picture for example) when this binary information is a part of the resource manifest. Apart from this binary information, a .resx file is completely readable and maintainable.

Note Do not use resource files to store passwords, security-sensitive information, or private data.

I think the main advantage of using .NET resource file(or resx file) is that you can make full use of the built-in API or coding syntax support. For example, .NET provide "ResourceManager Class" to help you programmatically load resource keys from resource file or resx file. Also, net resource file can be embeded into assembly. If you're using custom xml solution.

If you're using .net resource model(resource file or embeded in assembly), then, you should not change them frequently or dynamically at runtime. Because when .net application running, the resource items will be loaded into memory after it is used, just like it load the required assemblies. Therefore, it won't let you to flexibly update and refresh it immediately if you changed them when the application is running.


you can add multiple such resx files in a project. When you build the project, they will be compiled(as embeded resource) into your assembly(or separate satellite
assemlies that contains resource for specific cultures).

For ASP.NET application, it has some further encapsulated functionality.You can provide a local resource file for each aspx page or serveral global resource files for the entire application. These resource items are easy to reference in your aspx page(both through declarative syntax or programatic code)

Saturday, May 23, 2009

Look at Difference between XmlDocument and XmlDataDocument

The DataSet class in ADO.NET provides the developer with a relational view of data. Using the DataSet, data are stored as tables, which allows for easy retrievals using SQL statements. However, there are times when you need a hierarchical representation of the data, allowing you to perform quick searches using, say, XPath queries. You may also need to transform a set of data into another format using XSLT. In such cases, the .NET framework provides you with the XmlDocument class for this purpose.

However, the DataSet and XmlDocument classes only allow one way of data representation--either you have a relational or hierarchical view, but not both. It is with this purpose that the XmlDataDocument class was designed. The XmlDataDocument class is derived from the XmlDocument class, providing a hierarchical view of data as well as a relational view by binding it to a DataSet. Best of all, it automatically synchronizes the data changes made by either one of the two views. XmlDataDocument provides the best of both worlds--it can manipulate the data using the familiarDataSet, as well as support the various services in the XML classes (such as DOM, XPath, and XSLT). In this case, I will show you how you how to use the XmlDataDocument class

XmlDataDocument Allows structured data to be stored, retrieved, and manipulated through a relational DataSetThis class extends XmlDocument. It enables you to load either relational data or XML data and manipulate that data using the World Wide Web Consortium (W3C) Document Object Model (DOM). The DOM presents data as a hierarchy of node objects. Because XmlDataDocument implements the IXPathNavigable interface, it can also be used as the source document for the XslTransform class.

XmlDataDocument has a close affiliation with the DataSet class, which provides a relational view of the loaded XML data. Any changes made to theXmlDataDocument are reflected in the DataSet and vice versa.
 
And Now let's go through the difference between XmlDocument and XmlDataDocument 

  • XML Document
  1. The XmlDocument, XmlNode and other classes implement the W3C Document Object Model Level 1 Core and the Core DOM Level 2 specifications. 
  2. The XmlDocument is an in-memory (cache) tree representation of an XML document. 
  3. There are different node types specializing from XmlNode to enable you to manipulate the XML document. 
  4. You can get faster, non-cached, forward-only stream access to XML using the XmlTextReader and XmlTextWriter classes
  • XML DataDocument
  1. The XmlDataDocument class provides an in memory cache for XML data. 
  2. The XmlDataDocument extends the XmlDocument class. XmlDataDocument can be used anywhere the XmlDocument class is used. 
  3. There is a close association between the XmlDataDocument and the DataSet classes. In fact, you can regard the XmlDataDocument as a DataSet-aware XmlDocument.