Wednesday, May 16, 2012

CQRS Pattern

Command Query Responsibility Segregation


This topic looks like BIG ENTERPRISE pattern for BIG and distributed systems.
But on the other hand it comes with nice idea that Command and Query are different and that gives a lot of flexibility in system design for the price of increased complexity, as usual.

So you take regular sync operation (pictures are from Martin Fowler and Udi Dahan blogs):


And you say that "Command Model" (usually more complex) and "Query Model" (usually basic select * from few joins ) could have different implementations:



And then you continue: "Query Model" becomes "Cache" and "Command Model" becomes "Event Sourcing" storage.



And you continue even more:
- start to treat UI as a "Task based UI flow"
- and "Commands" are stored in the DB (pretty much write-only DB) so you have "free" History
- and you may play "Commands" back and force and you practically don't need transaction logs.
- and you have many "Caches" designed for specific UI layouts
- and so on...

So "current" state of the Model is kind of blurry now and may require Rules Engine or some implementation of "Snap shoot" (this can be done during Command execution).

Martin Fowler gives good definition for pattern: http://martinfowler.com/bliki/CQRS.html
Udi Dahan talks about details: http://www.udidahan.com/2009/12/09/clarified-cqrs/
Some links and discussion/video from Chicago ALT.NET: http://chicagoalt.net/event/January2010Meeting-JdnpresentsCQRSinroughlyanhourorso



Monday, May 7, 2012

Tuesday, May 1, 2012

DCI #2



A week ago I spotted very inspiring video: http://vimeo.com/34522837 "Some Thoughts on Classes After 18 Months of Clojure" from Brian Marick [BM] and found  mentions about DCI in the comments.

Brian Marick treats objects as a set of features (traits) which could be used as Roles in UseCase (DCI context) implementation.

In real life even simplest object has millions of properties and features but every time I need only few and at this time I don't care about other features. I can touch and feel (getters) this object and use it (setters and methods). Kind of interface with real implementation and real properties.
Next time I may touch/use same object in different context, the interface may be the same or new, but properties with same name are indeed same properties as I am using exactly same object. Methods should be different (or same? same is easier in case of JavaSctipt), that's I am not sure yet.
So object becomes a container of all such sets of features (traits).

Technically it is pretty easy to implement:
1) define HUGE class and many interfaces with getters/setters and functions. This way is not interesting.
2) Use dynamic features of language and treat each instance as a Hash of properties and methods. Pretty easy in JavaScript.
In C# it may look like this http://houseofbilz.com/archives/2010/05/08/adventures-in-mvvm-my-viewmodel-base/

// Trait here is ViewModelBase from above article: class with Hash and few helper methods Get(), Set(), With(), As()

public class Account: Trait
{
// strongly types property
public double Balance
{
   get { return Get(() => Balance, 0.0 /* This is the default value */); }
   set { Set(() => Balance, value);}
}

public void Withdraw(double amount) { Balance -= amount; }

public void Deposit(double amount) { Balance += amount; }
}

public class BalanceChangesTrace: Trait
{
// this Balance is mapped to Account via Hash
private double Balance
{
get { return Get(() => Balance); } // it will take value from Hash
}

[DependsUpon("Balance")]
public void LogWhenBalanceChanges()
{
Console.WriteLine("New Balance is {0}", Balance);
}
}

public class OverdraftProtection: Trait
{
// I may repeat private double Balance { get { return Get(() => Balance); } }
// but there is another way to get Balance

[DependsUpon("Balance")]  // this method will be called each time Account.Balance is set.
public void LogWhenBalanceChanges()
{
var balance = this.As().Balance;

if ( balance < 0 ) throw new ApplicationException("insufficient funds");

// or even untyped, bad practice in general but may be handy sometimes
// double balance = (double)this.Get("Balance")
}
}

public class AccountTransferUseCase: Context
{
    public void Transfer(Account from, Account to, double amount)
    {
    var _from = from
.With()
    .With();

    var _to = to
 .With();

Console.WriteLine("Withdrawing " + amount);
        _from.Withdraw(amount);
       
        Console.WriteLine("Depositing " + amount);
        _to.Deposit(amount);
    }
}

var acc1 = new Account();
acc1.Balance = 100.0;

var acc2 = new Account();

(new AccountTransferUseCase()).Transfer(from: acc1, to: acc2: amount: 20.0);


With all these dynamics it may be slow but for most software it is fast enough.


[end]

Tuesday, April 24, 2012

DCI Paradigm (new Object Oriented Programming)

DCI stands for Data-Context-Interaction.

Originator: James Coplien (site: https://sites.google.com/a/gertrudandcope.com/www/jimcoplien)

Video: http://www.infoq.com/presentations/The-DCI-Architecture (1h)

Books: http://www.leansoftwarearchitecture.com/
http://www.amazon.com/Lean-Architecture-Agile-Software-Development/dp/0470684208/ref=pd_sim_b_1

C# samples:
http://horsdal.blogspot.com/2009/05/dci-in-c.html
http://horsdal.blogspot.com/2011/01/doing-dci-with-aspnet-mvc.html

Another talk with is very close to the subject is this: http://vimeo.com/34522837
In this talk DCI is built as a class inherited from Hash and Roles are built kind of Fluent API. There are no C# sample but Ruby/Clojur ideas.


More resoures: http://www.leansoftwarearchitecture.com/home/more-online-resources

DCI implementation in Java: http://oredev.org/prod/oredev/site.nsf/docsbycodename/session?opendocument&sid=88EF79931A074A1AC125759A003AB0ED&track=24116556E47101EAC12575A50049A141&day=5

Presented 4 ways: POCO with common class, interfaces, composite pattern and Qi4j mixin.
Kind of goal is achieved but I didn't like these implementations - too much code in Java.

Thursday, April 19, 2012

NW-Cadence: Introduction to Agile Product Planning in Visual Studio 11

Few short videos from ALM Rangers on TFS 2011 project planing, forecasting, web interface and tfspreview.com integration
http://blog.nwcadence.com/introduction-to-agile-product-planning-in-visual-studio-11/


Tuesday, April 3, 2012

Sync iCloud to Dropbox


Sync iCloud to Dropbox

Mac and iOS users are going to be increasingly pushed to choose between storing their documents in iCloud or Dropbox. I expect that Apple will continue to push more and more features to iCloud that will make people want to use it, and I expect that Apple will continue to make iCloud easier and easier for iOS and Mac developers to use, so developers will want to support it.

I like the idea behind iCloud, but I don't really trust iCloud yet. Apple's previous attempts at online services have left me suspicious about iCloud's performance, reliability, and long-term future. I hope I'm wrong and that iCloud turns out to be great, but in the meantime, I know Dropbox, and I trust Dropbox.

One of my favorite features of Dropbox is the ability to go back and see revisions from the previous 30 days. It's my safety net.

The good news is that you can sync iCloud to Dropbox. The bad news is that it's a one-way sync from iCloud to Dropbox. But if all you want to do is backup iCloud files and be able to retrieve previous versions from Dropbox, it's pretty simple to do.

I'm going to use Byword as an example because it's fairly straight-forward, but the process should work roughly the same for any iCloud enabled Mac app.

Step One: Make sure iCloud is enabled. Go to System Preferences » iCloud and make sure that you have "Documents & Data" set to sync.

Step Two: Create an iCloud-based file. The exact process for this differs from app to app. Byword has a File » Move to iCloud menu item.

Step Three: Find the local iCloud folder. Here's where things get a little bit tricky. You have to get into the "Library" folder in your Home directory, but that folder has been hidden in Lion. Fortunately for you there are at least 18 ways to view that folder. My recommendation is to go to the Finder, select the "Go" menu, and press the Option/Alt key. When you do that, you'll see the Library folder appear. Or use ⌘ + Shift + G and type in "~/Library/" if you prefer keyboard shortcuts. Once you are in, look for a folder called Mobile Documents

You'll find something like the list of directories shown here. Inside each one is a "Documents" sub-directory. I bet you can guess what is stored in there.

Step Four: Sync changes via Hazel. Hazel was recently updated to version 3, and one of the new features is a 'sync' option. For those who don't know Hazel, you should, it's one of my irreplaceable apps. It allows you to create rules for all sorts of actions to happen in specific folders if different criteria are met. For example, Hazel can tell if a file has been modified since the last time Hazel checked a specific folder. If it has been modified, you can tell Hazel to do specific things, including "sync" from that folder, so another one.


Click on image for a larger size

I created a 'Byword' folder in my ~/Dropbox/ and then created a Hazel rule which says "If any files have been modified since we last checked (matched) this folder, then sync the 'Documents' folder (located inside ~/Library/Mobile Documents/) with the Byword folder in Dropbox.

Step Five: (Optional) While I was checking around inside ~/Library/Mobile Documents/ I used Default Folder X to set the Byword iCloud folder to be the default folder for all new Byword documents. Now whenever I create new document on my Mac using Byword, I know that it will automatically be saved to iCloud and Dropbox.

This isn't something that I will do for all of my iCloud-enabled apps, but I've been using Byword more and more lately for all sorts of writing projects, and I want to do everything I can to make sure that I am "covered" when it comes to saving my files. Two local copies (one in Mobile Documents, one in Dropbox folder) and two copies in the "cloud" (iCloud and Dropbox sync), plus 30 days worth of "undo"? (Not to mention that each of my Macs will have local copies as well, as iCloud and Dropbox sync across my network.) That's a system I can create and then forget about.

Sync iCloud to Dropbox originally appeared on TUAW - The Unofficial Apple Weblog on Tue, 03 Apr 2012 08:00:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Original Page: http://www.tuaw.com/2012/04/03/sync-icloud-to-dropbox/

Sent from Feeddler RSS Reader



Sent from my iPad

Thursday, March 1, 2012

MSDN MAG: Windows Azure AppFabric Service Bus - Create a Continuous Client Using Portable Class Libraries

http://msdn.microsoft.com/en-us/magazine/hh852593.aspx

In this article, MSDN shows how to build a simple continuous client application that spans multiple devices and platforms. I’ll make use of the new Portable Class Libraries (PCLs) to ease the development of a cross-platform application, and the cloud—in particular Windows Azure AppFabric Service Bus—to handle the communication between the devices.

PCLs, available as a free add-on to Visual Studio 2010 (bit.ly/ekNnsN) and built into Visual Studio 11 beta, provide an easy way to target multiple platforms using a single project. 

about event aggregation, see Shawn Wildermuth’s article, “Composite Web Apps with Prism,” atmsdn.microsoft.com/magazine/dd943055.

For a full overview, check out “An Introduction to the Windows Azure AppFabric Service Bus” at bit.ly/uNVaXG.


Sunday, February 26, 2012

Beginning iOS Application Development with HTML and JavaScript

Game and Graphics Programming for iOS and Android with OpenGL ES 2.0




MonoTouch.Dialog


http://docs.xamarin.com/ios/tutorials/MonoTouch.Dialog

Nice option implemented in MonoTouch 5 to auto generate iPhone dialog controllers & views. All UI features like descriptions, input types are defined either by attributes or in Linq.XML fasion.