Article :: Understanding Service Component Architecture: Assembling and Deploying a Composite

Learn the basics of building an SCA application, including how to create components that offer services, configure those components and wire them together as part of a composite, expose a service as a web service, and package and deploy the composite to a domain.

Categories: Computers | InformIT | InformIT Web Services | Programming | Service Oriented Architecture | SOA | Technology | Web Development | Web Services
Article :: Beyond HTML: Returning JSON and XML Data From Your MVC Endpoints

You adopted MVC to get better control over your URL structure. Then you're asked to provide REST access over the same data. Instead of developing a new API and set of endpoints that mirrors what you already have, you can augment the existing application to respond to requests for JSON and XML as well as handle data updates and deletes. Scott Seely shows you how.

Categories: Computers | InformIT | InformIT Web Services | Programming | Service Oriented Architecture | SOA | Technology | Web Development | Web Services
Article :: Objective-C Design Patterns

David Chisnall looks at some of the patterns that are commonly found in Objective-C code.

Categories: Computers | InformIT | InformIT Programming | Programming | Technology
LosTechies welcomes John Petersen!

I am proud to announce that John Pertersen has joined LosTechies!  We are all looking forward to his perspective and insights into software development.

Kick It on DotNetKicks.com



Categories: Computers | CSharp | Dot Net | Los Techies | Programming | Technology
Role Specific Interfaces: DIP And ISP In Action

I do most of my UI development – in ASP.NET WebForms and in WinForms – with a Model-View-Presenter setup. It helps me keep my application logic separate from my view implementations, makes it possible to unit test the presenters, etc. I also like to use custom controls – often with their own presenter - to help encapsulate UI related process and keep my UI implementations clean. The challenge with custom controls is getting them to converse to each other and getting the parent form to converse with the controls. My favorite way of solving this challenge is through simple messaging patterns. This gives you a lot of control and ensures your system is nice and decoupled. Of course, there is a cost/benefit tradeoff that needs to be considered. There may not need the indirection and potential complexities that come along with those solutions. The system in question may not need a messaging system, event aggregator, command pattern or whatever else. There are times when its easier and makes more sense to forego these patterns and have the presenters talk directly to each other.

 

Role Specific Interfaces

When the cost of the messaging pattern architecture out-weighs the benefits, stick to simple abstractions that still  keep the presenters decoupled by one layer. This can easily be done with an interface or abstract base class in static languages like C#, Java and C++. However, don't take the easy way out in this abstraction and creating a one-to-one mapping between the abstraction and the implementation. Doing so will create a semantic coupling between the two presenters.

For example, the IProductCodeSelectionPresenter may have the following definition:

   1: public interface IProductCodeSelectionPresenter
   2: {
   3:   void Initialize();
   4:   void ProductCodeSelected(ProductCode code);
   5:   ProductCode GetSelectedProductCode();
   6:   void SelectionCancelled();
   7:   void SelectionConfirmed();
   8: }
   9:  

Which of these methods should another presenter call in order to retrieve the ProductCode? Should GetSelectedProductCode be called? Does this method guarantee the view to select a product code was run and that the product code has been specified by the user? Or maybe the ProductCodeSelected method should be called instead, or Initialize or ... This easy-to-create interface may cause semantic coupling by forcing another developer to look at the implementation in order to know which methods should be called, when.

It would be better to define a role that the presenter is playing in the communication and create an interface that is specific to that role. In this situation, the name of the presenter provides some insight to what role the presenter is playing - product code selection. A simple role specific interface for this presenter may look like this:

   1: public interface IProductCodeSelector
   2: {
   3:   ProductCode GetProductCode();
   4: }

With an interface defined like this, a developer calling this code will not have any confusion on what needs to be called. There is no need to look at the implementation of the interface, and semantic coupling has been avoided. Making a call to this interface is easy.

 

The Interface Segregation Principle (ISP)

The driving principle in making the decision to create the role specific interface is often the Interface Segregation Principle (ISP). This principles says that we should not force a client – the code that is calling out to our interface – to know about methods and properties that it does not need.

In this case, the client code does not need to know that the interface sits on top of a presenter. Therefore, take the name "presenter" out of the interface that the client calls. This gives the interface more flexibility for the future and prevents the client code from knowing that a view and user input is likely to be the implementation. The client code also doesn't need to know about the Initialize, ProductCodeSelected and other methods that the presenter has. These methods are specific to the interactions between the View implementation and the Presenter – a different role that the presenter is playing. By removing these methods from the interface, the client code is no longer bound to the knowledge of which methods should and should not be called, when.

 

The Dependency Inversion Principle (DIP)

The Dependency Inversion Principle (DIP) may also be at play in this scenario. DIP is not just about creating an abstraction and passing it into a constructor. That would only be dependency abstraction and dependency injection. Rather, DIP talks about abstraction ownership. In the case of a role specific interface, the owner of that interface is the code that depends on it – the client code that calls out to it.

If another presenter, such as a ProductDefinitionPresenter, is the driving force behind the need to create the IProduceCodeSelector interface, then this presenter should own that abstraction. This means that the ProductDefinitionPresenter determines what that interface looks like. What methods and properties are available, and the name of the interface are all driven by the needs of the ProductDefinitionPresenter.

   1: public class ProductDefinitionPresenter
   2: {
   3:   private IProductCodeSelector ProductCodeSelector;
   4:  
   5:   public ProductDefinitionPresenter(IProductCodeSelector productCodeSelector)
   6:   {
   7:     ProductCodeSelector = productCodeSelector;
   8:   }
   9:  
  10:   public void SelectProductCode()
  11:   {
  12:     var productCode = ProductCodeSelector.GetProductCode();
  13:     //do something with the productCode, here
  14:   }
  15: }

There is not syntax or markup that declares ProductDefinitionPresenter as the owner of this interface, in this example. That responsibility is left to the standards, conventions and organizational means of the system in question and the team that maintains it.

 

Other Considerations

Model-View-Presenter scenarios are not the only place that roles need to be considered. Any time two or more objects interact and there is a need for them to be decoupled, the roles that the objects are playing need to be considered. There are likely other principles and patterns that come into play when considering a role specific interface, as well. Each scenario's needs must be considered for their own reasons, and ISP and DIP may not always be at play when defining an interface for an object. And role specific interfaces are not always needed. There are other benefits to creating interfaces or other abstractions that can be referenced in place of concrete implementations such as dependency injection, general decoupling, creating service layer or other context specific barriers, etc.

Kick It on DotNetKicks.com



Categories: Computers | CSharp | Dot Net | Los Techies | Programming | Technology
Article :: Snow Leopard: The Underhyped APIs

David Chisnall takes a look at some of the new APIs in OS X 10.6 that will make life easier for developers but didn't receive much publicity.

Categories: Computers | InformIT | InformIT Programming | Programming | Technology
Article :: SOA Pattern of the Week (#5): Service Decomposition

The Service Decomposition pattern provides a technique for splitting up a service after its initial deployment into two or more fine-grained services.

Categories: Computers | InformIT | InformIT Web Services | Programming | Service Oriented Architecture | SOA | Technology | Web Development | Web Services
It's great to be here at Los Techies!

This being my first blog post at Los Techies, I want first say how excited I am to be part of a vibrant community of developers. For some time now, I have been "going it alone" with my blog efforts. I believe that when afforded an opportunity to add to an ecosystem that has such a positive effect on the development community at large - you don't let that opportunity pass.  You can find my former blog at www.johnvpetersen.com.

A little about me...I have been a professional software developer for about 20 years. Currently, my development focus is in the ASP MVC space - and I love it. I have also been dabbling into Ruby on Rails. I have a forthcoming article in Code Magazine where I discuss my efforts at porting Nerd Dinner to Rails. Most recently, I have been making the rounds to local Code Camps (Philadelphia, Harrisburg and New York City) giving talks on the BI Stack, NHibernate and ASP MVC.  Over the years, the community has provided me with many opportunities. In that regard, I appreciate the opportunity, whenever possible, to give back. Of particular interest, I enjoy the opportunity to help new developers learn the ropes. To that end, I have been working with the Philadelphia Microsoft Developer Evangelist Dani Diaz in building up a new site called http://www.devready.net/. Should you have the desire to give back, I encourage you to contribute a 20-40 minute screen cast on a topic of your choosing. As of this blog post, the site is still in the ramp-up phase.

Until next time, happy coding!!

 

< JVP >

 

 

 

 

 

Kick It on DotNetKicks.com



Categories: Computers | CSharp | Dot Net | Los Techies | Programming | Technology
Article :: Software [In]security: Cargo Cult Computer Security

Gary McGraw argues that the time is right to turn to real science to combat the "Cargo Cult" mentality of the software security field.

Categories: Computers | InformIT | InformIT Programming | Programming | Technology
Article :: C# 4.0 How-To: Creating Versatile Types

This chapter is all about making your own objects as useful and versatile as possible. In many cases, this means implementing the standard interfaces that .NET provides or simply overriding base class methods.

Categories: Computers | InformIT | InformIT Programming | Programming | Technology
I don't just code

I have an obscure, personal blog to which I fled back to recently. I posted the following entry:

Well whadaya know? I'm having existential doubts these days. There's a battle that rages inside of me every time I get a little bit of free time: what should I spend my precious little time on? Until recently, I had been trying to get an enterprise-y application going, but it filled me with dread. Every line of code had to be extracted from my body with forceps, put into place and tested. It was a fine equilibrium, a delicate balance that I maintained by making myself believe that this is what I wanted to do. It was more that just something to do on a rainy day; it was more than just a reason to go out and hang out in a coffee shop all afternoon on Sundays. It was what I wanted to do. But I hated it. Well, most of it.

Anyway, that balance tipped over when I lost control of the app. Slowly, I stopped unit testing features. Then I simply started hacking it without too much thought or process. I started drifting. Thoughts would come and distract me. What is the next big thing? How can I become hugely successful and never have to worry about money again? Should I remain a Windows developer, forever branded as a .Net guy, or should I venture to the free ecosystem that is Linux? What about Mono? Oh, I could write server apps with Mono! But what about Lisp? I've always wanted to learn Lisp! I could write a Command &amp; Query type application and start with the Login system and write it in Lisp. Or even better yet, I should write a .Net version of Common Lisp, just like that dude that wrote Clojure on top of the JVM. And of course, it would have to be done entirely by using the command line and VIM... Is there a book on Amazon for VIM?..

And on, and on, and on it would go. Every Sunday. Torture. I would power on my laptop and sit transfixed in front of the monitor, my hands calmly positioned over the keyboard. There would be a shell prompt and a VIM window open, waiting. Oh, the possibilities! And yet, I couldn't come up with anything to do. Eventually, I'd give up and log on to twitter, facebook, news.ycombinator, arstechica, slashdot, news.google, nytime, programmer-looking-for-a-problem-to-solve-that-wont-bore-him-to-death.com... I'd then slam shut the laptop lid and be in a funky mood all day. Hell, that's exactly what happened today. Again!

Except that today I decided it was all over. I would stop wasting the rest of my life pursuing something I'm starting to feel weak at. Focus on my strength. That's what I need to do! But then I read a blog post about using object databases and cracked open my Common Lisp book. Damn it! I feel excited about programming again. It makes me feel like getting my laptop down from the shelf where it's quietly sitting and hack on something.

Why?

I'm clearly passionate about something! I just can't put my finger on it. So here's what I'm going to do. I'm gonna blog about that until I figure out what it is. Yeah. Blogging. That's so 2005! It's so not the next big thing.... oh... here I go again!

It's only been a month, and already my mind is on something else. You guys have read my posts, or if you haven't, go check my post history. I'm all over the place! Why the hell did I want to learn Lisp? Why go away from what I know best? I think we all want to do something significant in life. We all want to get better. But in my case, I clearly need some focus. Instead of learning something new and obscure (and hard!), why not get better at what I already do? I'll admit it: I'm not a spare time or weekend coder. I can't do it. I don't pull the all nighters. I don't stay up until 2am at night. I actually try to get between 8 and 9 hours of sleep every night because that's what makes me feel great during the day. This sort of balance is what I need. When I try to focus too much on code, I end up developing this allergic reaction that causes the kind of posts I just showed you. It's not fun. Yet, I envy all of you who do code all the time. I feel that not doing it slows me down on my journey to become a better programmer.

I suppose the journey is what's important. The important thing is that we go forward. The pace doesn't matter. As for me, I'm not forcing myself to code anymore. I'm enjoying my time with my family and feel I'm a better developer at work because of it.

Kick It on DotNetKicks.com



Categories: Computers | CSharp | Dot Net | Los Techies | Programming | Technology
Article :: An Introduction to DataPower SOA Appliances

The authors explain what exactly SOA appliances are, how they are used, and how they are similar and dissimilar to traditional household appliances.

Categories: Computers | InformIT | InformIT Web Services | Programming | Service Oriented Architecture | SOA | Technology | Web Development | Web Services
Field Vs. Property: Does It Really Matter?

Given my recent experiences with Ruby, my cursory knowledge of Java, and my past experiences with other object oriented systems, I find myself asking a lot of questions about why we do things the way we do in the C#/.NET space. Today's questioning is about one of those fundamental things that I have been preaching for a long time, yet suddenly find myself unable to answer ‘why':

field vs property: does it really matter?

As I sit and think about in the back of my head while writing code or this post, I can't really say that I have any good reason for saying "you should use a property instead of a field" other than the defacto answer of encapsulation. But what if encapsulation doesn't matter when you just want to store and retrieve a simple piece of data? Why is oh so important to use a property as the public API for a class?

Ruby doesn't really have properties. It just has methods that allow you to use an = sign, but those methods are not even required to "set" a value. It's only the conventional use of = methods that say you should. Java doesn't have properties at all. It's convention to use getWhatever and setWhatever methods, but it's better design to not use mutators and I like the general reasons behind that.

So why does it matter if it's a field vs. a property? Someone convince me that it's important. Someone convince me that it's not.  Better yet – someone explain the contexts in which it is important and the contexts in which it's not, and someone point out where it's important to hide the data behind the process through a mutator-less API of service methods.

...

Question everything – especially your own assumptions.

Kick It on DotNetKicks.com



Categories: Computers | CSharp | Dot Net | Los Techies | Programming | Technology
Article :: My MacBook: Managing Contacts and Appointments

Learn how to use your MacBook to manage your contacts, calendars, and appointments.

Categories: Computers | InformIT | InformIT Programming | Programming | Technology
Article :: Agile Product Responsibility in the Enterprise, Part 3: Maintaining the Product Roadmap

Dean Leffingwell continues his series on the responsibilities of the Agile product manager with this discussion of developing and maintaining the product roadmap.

Categories: Computers | InformIT | InformIT Programming | Programming | Technology
What is Projection?

I think there’s great benefit in not only knowing how to design your code to use common patterns but also to be able to speak about them clearly and concisely to others. If I mention that the problem sounds like it could be solved using the Strategy Pattern, somebody who knows what I’m talking about shouldn’t need much more of an explanation than that. Knowing certain terms in code will help with communication. Obviously, the better your team is at communicating, the more successful you’re going to be.

Very Simple Projection

I’ve seen the following code all over the place. It’s very common to turn one collection into another or loop through and capture certain properties of the items you’re enumerating. How often have you seen this code:

public IList<string> GetNames(IEnumerable<Person> people)
{
IList<string> names = new List<string>();
foreach (var person in people)
{
names.Add(person.Name);
}
return names;
}

This is simple projection, but languages are seemingly giving you better ways to achieve this same thing. I’ll get to that later.

Different types of projection

I see three basic types of projection. There are variations of these same ideas, but for the most part these cover the bulk.

  • Selection: Imagine you have a collection of customers and you want only the email addresses, this is where selection projection would be used. This isn’t always a one-to-one relationship, your customers may have more than one email address (if you allow it) and you’ll end up with more items in the projected collection than the starting collection.
  • Creational: This is the type of projection that returns new values from an existing collection. Below, you’ll see two concrete examples in C#.
  • Transformation: Given a list of numbers, you want those numbers squared. This is similar to creational, because you'll be getting a new item, but it shouldn’t modify the elements in the original collection.

Projection with LINQ in C#

An example that lends itself well to the concept of projection is the following:

My user interface allows strings to come into my application. I want to transform these strings into tags like any blog post, video or photo might have assigned to it. I don’t want my tag service class to have to deal with strings, I want to give it a collection of Tag objects. How do I do this?

With LINQ, this creational projection was very simple:

public void SaveTags(IEnumerable<string> tagNames)
{
var tags = tagNames.Select(name => new Tag(name));
tagService.SaveOrUpdateTags(tags);
}

Another great use of creational projection are some of the usages I’ve seen with SelectListItems in the ASP.NET MVC space. Given a list of objects, create a list of HTML drop down items for a select list.

K. Scott Allen has a good write up entitled Drop-down Lists and ASP.NET MVC on this very thing. There are also many good examples over on the MSDN Visual C# Developer Center.

Your Thoughts on Projection…

I see this pattern often enough but I don’t hear the term “projection” nearly as often. Is there a more common name to this that I’m not hearing or are people just not referring to it by this name?

Kick It on DotNetKicks.com



Categories: Computers | CSharp | Dot Net | Los Techies | Programming | Technology