Component-based Scalable Logical Architecture: Difference between revisions

Content deleted Content added
Illiante (talk | contribs)
Illiante (talk | contribs)
No edit summary
Line 1:
{{Unreferenced|date=July 2008}}
'''Component-based Scalable Logical Architecture (CSLA)''' is a [[software framework]] created by [[Rockford Lhotka]] that provides a standard way to create robust [[object oriented]] programs using [[Business object (computer science)|business object]]s. Business objects are objects that abstract business entities in an object oriented program. Some examples of business entities include sales orders, employees, or invoices.
 
Although CSLA itself is free to download, the only documentation the creator provides are his books and videos, which are not free.
 
CSLA was originally targeted toward [[Visual Basic]] 6 in the book ''Visual Basic 6.0 Business Objects'' by Lhotka<ref>Visual Basic 6.0 Business Objects ISBN 1-86100-107-X</ref>. With the advent of [[.NET Framework|Microsoft .NET]], CSLA was completely rewritten from the ground up, with no code carried forward, and called CSLA .NET. This revision took advantage of [[Web Services]] and the object oriented languages that came with Microsoft .NET (in particular, [[Visual Basic|Visual Basic.NET]] and [[C Sharp (programming language)|C#]]).
 
CSLA.NET was expounded in ''Expert C# Business Objects'' <ref>Expert C# Business Objects ISBN 1-59059-344-8</ref> and ''Expert One-on-One Visual Basic .NET Business Objects'' ISBN 1-59059-145-3, both written by Lhotka. Although CSLA and CSLA .NET were originally targeted toward [[Microsoft]] [[programming languages]], most of the framework can be applied to most object oriented languages.
 
Current information about CSLA .NET is available through Lhotka's self-published ''Using CSLA 4'' ebook series<ref>Using CSLA 4 (http://store.lhotka.net/Default.aspx?tabid=1560&ProductID=22)</ref>.
 
==Features of CSLA==
===Smart data===
A business object encapsulates all the data and behavior (including persistencebusiness logic and rules) associated with the object it represents. For example, an orderOrderEdit object will becontain the onlydata partand ofbusiness therule programimplementations tonecessary loadfor anthe order,application obtainto orcorrectly assignallow the order'suser memberto dataedit (order numbers, etc...), save the order, and so oninformation.
 
===TypedRules Collectionsengine===
The CSLA .NET framework provides a rules engine that supports validation rules, business rules, and authorization rules. These rules are attached to object instances or properties, and are automatically invoked by CSLA .NET when necessary. Validation rules may be implemented using the CSLA .NET rule engine, or through the use of the [[DataAnnotations]] feature of [[Microsoft .NET]].
The framework defines a standard way to create collection objects which represent a collection of objects. This allows an object model to map well to a [[relational database]]'s [[data model]]. For example, an ''Account'' table could map to an ''Accounts'' (observe the pluralization) collection object (in reality the object model will differ from the relational model, it is therefore necessary to employ [[Object-Relational Mapping]] to resolve the differences). In this case each row in the ''Account'' table would map to an ''Account'' business object which is contained in the ''Accounts'' collection object. This makes it possible to define methods for the collection object that will propagate to its constituent objects. For example, to save all the ''Account'' objects in an ''Accounts'' collection, one would type:
<br /><code>
myAccountsCollection.Save();
</code><br />
The Save() method will call the Save() method on each of its constituent Account objects.
// Inside the Accounts class
public void Save(){
// _accounts will normally be some type of array variable with class scope
// that holds all of the Account objects represented in this collection.
foreach (Account acct in _accounts){
acct.Save(); // The actual Account object does the work of saving itself to the database
}
}
This method of propagating changes to a collection's constituent object can be used for other common methods and property assignments as well(myAccountsCollection.Load(); myAccountsCollection.Active = false;).
Business objects can also contain other collection objects, in effect creating a relationship analogous to a parent child relationship between two tables. For example, the ''Account'' object mentioned above can contain an ''Orders'' collection object which in turn contains ''Order'' objects. In this case, the above call to Save() on the ''Accounts'' collection object could be written to save all of the Account objects as well as all of the orders associated with each of the accounts.
 
===Object persistence===
Data creation, retrieval, updates, and deletes ([[CRUD (acronym)|CRUD]]) are performed by clearly defined methods of the business object associated with the data testing. Data access logic is clearly separated from business logic, typically using a [[repository pattern]] or other mainstream [[object-oriented programming]] techniques.
 
===Persistence stateMetastate maintenance===
CSLA defines.NET amanages standardthe way''metastate'' ofabout allowing aeach business object to maintain information about its "persistence state". InFor other wordsexample, aneach business object knowstracks information about when it is new (it represents data that hasn't been saved yet) and when it is dirty (it needs to be saved to the database either because it is new or because its member data has been changed since it was last loaded). Business objects can also be marked for deletion so they can later be deleted (for example when a user has pressed a button confirming his or her intention to delete the rows.)
 
===''n''-Level undo===