Monthly Archives: November 2013

GetTemplateChild or Template.FindName?

“yes, you’re right, Microsoft uses GetTemplateChild in their controls. But the MSDN-Doc says for GetTemplateChild “Do not use. Use FindName instead.”

http://social.msdn.microsoft.com/Forums/es-ES/c8f50416-5e52-45a1-94c3-c1c505b59d3a/change-control-in-genericsxaml-from-the-customcontrolvb?forum=wpf

Advertisements

Concern: How to design a distributed service?

I have a major concern nowadays when trying to design distributed services that are consumed by the UI.
Imagine that you want to abstract as much as you can thinking of a View. This View consumes a distributed service that can fail to work under a lots of different situations. The most common failure: The connection cannot be established / is lost.
The view can be aware of those problems and try to recover from a failure, for example, warning the user and attempting to reconnect. But, then we totally break the abstraction! we start to think of it as a connected service.
What can we do? Should we put every method call in a try-catch block and a add reconnection loop?
It seems very ugly to me.
How to proceed?

After seeing 1000 ctors

I heard it a lot of times. When I was learning Java, a flash definition about constructor methods faded away in the classroom. A “silly” definition that nobody seemed to remember a bunch of years later.

Sometimes the things that are easily forgotten are the most basic principles. We take them as a fact and we rarely reevaluate them.

One of the basics in OOP is the role of a constructor method:

A constructor method is a special method that contains ONLY the required initializations for the instance to be created in a valid state, ready to be used.

Said this, any constructor what invokes complex methods, services to retrieve data, contains lots of lines of code, or even loops, IS A MISTAKE and needs to be fixed.

A constructor has to be minimum! The instance should be created just in time and any complex initialization should be the responsibility of any other method of the instance.

This answer on Stack Overflow is very good. Be sure to read it 🙂 and keep you ctors clean!

http://stackoverflow.com/questions/1183531/how-much-work-should-the-constructor-for-an-html-parsing-class-do