I went looking everywhere for a section of code that would do the following:
Number to Mexican Pesos (Spanish)
The most important aspect of OOP is …
Recently in school we were asked a simple question. Of all the aspects of object oriented development what to you is the most important. The following is my reply to that.
I would say the single largest advantage that object oriented development brings to the table is abstraction. We've alluded to abstraction here and there in the class but I don't think we've come out and thrown down the gauntlet and said "yes here it is." Abstraction to me in terms of an object oriented model is the ability to define a theoretical system without writing actual code. We have abstract base classes and interfaces which provide this crucial functionality and the abstraction principle is at work all over Java especially in the frameworks like Swing [or Hibernate].
Why would I think this is important over any other aspect of object oriented programming? Because I think its used more than any other aspect and in reality incorporates it. Abstraction for example could not exist without interfaces, inheritance, and polymorphism. The idea that I can just define an ILogger interface that logging components of my application implement is largely beneficial especially when trying to write a loosely coupled highly extensible application. What if for example I wanted my application to support 3 types of loggers such as a ConsoleLogger, DatabaseLogger, and an XmlLogger all which implement ILogger. I could theoretically build an object factory that given some input or system heuristic return one of these aforementioned loggers and my system can work without change in any code other than the code that serves up the object that implements ILogger.
To me this is crucial for building large enterprise applications of which object oriented development is a key player. The more we learn and implement levels of abstraction in our objects the better. Of course there is always "too much abstraction" and its something like inheritance is learned with time but in all I believe it is a major aspect of OOP that every developer should learn and embrace.
I was wondering if I was going to be nailed in some way because I used something not even discussed in the class, however this was my professor’s reply
Excellent! This post needs to be saved. Realizing what abstraction is and the strength of it is the equivalent of finding the holy grail. If you see this, working with interfaces and providing concrete classes that implement these interfaces in a plug and play manner becomes automatic. One example, the VERY popular Java framework called Spring is built on this principle.
Its nice to know that I’m not the only one that feels abstraction is the end all be all of object oriented development in either Java, C#, or any other Object Oriented Language. I seriously feel we push things in OOP development that need not be learned initially and don’t take a more direct approach on proper software design. To me abstraction should be taught and we use polymorphism and inheritance/interfaces to accomplish the task.
NHibernate| many-to-many
So I’m starting to build a proof of concept product catalog as both a reason to use NHibernate in a “real world” application but also to apply ASP.Net MVC with it as well. I chose both of these technologies because they’re supposed to create strongly built applications faster.
The following data model is the start of the catalog with more being added over the next few weeks.

The tags collection on the Product is simply an ISet<Tag>. I’ve used this rather than a list because I want to have a distinct set of tags per product. Here’s the mapping for both entities.
<class name="Product">
<id name="Id">
<generator class="identity"/>
</id>
<property name="Name"/>
<property name="ShortName"/>
<property name="ItemId" />
<property name="Sku" />
<property name="Wholesale" />
<property name="Retail" />
<property name="ImageUrl" />
<property name="IsActive" />
<set name="Tags" table="TagAssociations" cascade="all" >
<key column="productId"/>
<many-to-many column="tagId" class="Tag" />
</set>
</class>
<class name="Tag">
<id name="Id">
<generator class="identity"/>
</id>
<property name="Name" unique="true"/>
</class>
Notice we’ve created an interim table to join the Tags and Products called TagAssociations (there are probably better names but meh) and done this through a many-to-many relationship on the Tags property binding it to Tag objects through the table.
From here on out our interactions with TagAssocations is nil. For example pulling products by Tag only requires the following code.
public IList<Product> GetByTag(Tag tag)
{
using (ISession session = NHibernateHelper.OpenSession())
{
var list = session
.CreateCriteria(typeof(Product), "p")
.CreateCriteria("Tags")
.Add(Restrictions.Eq("Id", tag.Id));
return list.List<Product>();
}
}
Because we’re adding in our property Tags through CreateCriteria and saying we want to pull that by Id the following TSQL is generated automatically.
SELECT this_.Id as Id3_1_, this_.Name as Name3_1_, this_.ShortName as ShortName3_1_, this_.ItemId as ItemId3_1_, this_.Sku as Sku3_1_, this_.Wholesale as Wholesale3_1_, this_.Retail as Retail3_1_, this_.ImageUrl as ImageUrl3_1_, this_.IsActive as IsActive3_1_, tags3_.productId as productId, tag1_.Id as tagId, tag1_.Id as Id5_0_, tag1_.Name as Name5_0_
FROM Product this_
inner join TagAssociations tags3_ on this_.Id=tags3_.productId inner join Tag tag1_ on tags3_.tagId=tag1_.Id
WHERE tag1_.Id = @p0; @p0 = '1'
To me this is a miracle to behold considering the shear amount of work this would take under normal circumstances.
NHibernate and Micrsoft Team Test
I couldn’t find much information on using Microsoft’s Team Test Suite and NHibernate so here’s the condensed version so you don’t have to have the same issues I went through.
If you use the “Getting Started” guide here and substitute Microsoft’s test suite for NUnit add the following attributes just below the [TestClass] attribute on the class definition. Remember to substitute your database’s name in for [Database Name].
[DeploymentItem("hibernate.cfg.xml")]
[DeploymentItem("[Database Name].sdf")]
This will tell the test suite these are dependencies and to deploy them to the TestResults folder where the tests are run.
Voila! Everything “should” run as advertised but remember to place these on every single test fixture you create. Its a bit of a pain and I hope Microsoft can fix this in either a service pack of Visual Studio or in the next version.
Crow
I swear I would never see he day in which I found something that Java does better than the .Net framework. Unfortunately for me today is that day. I usually don’t do Java very much because my job never calls for it and I have zero *umph* to take and learn the antiquated language and yet today as I’m working in Java for a class I learned something I’m very very jealous of that Java supports and .Net does not. Anonymous instances of interfaces.
Anyone who’s done a UI in Java has done this 1,000,000,000,000,000 times so if this is something of a “duh dumbass” moment as you read this go ahead and pass on by otherwise here is what I have.
Java events work extremely different that .Nets do. They have this concept of listeners in which one creates an object that implements the interface ActionListener and a method is nailed down on the fly such as the following code specifies.
btnCalculate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Calculate(e);
}
});
Notice that we’re adding the ActionListener to the JButton btnCalculate and the method is being defined on the fly. In the .Net world we have similar feats for Events and anonymous types, but generally speaking we can’t say this anonymous type is of type INotifyValueChanged and pass in a dynamic object that maps the interface as is done here in Java.
I’m envious of this because it would be such a useful construct for a host of uses including but not limited to proxy objects used in TDD.
I would like also to state that the object works as a closure due to the fact that information contained in the actionPerformed method has access to everything it’s host object does.
I imagine Java geeks use this technique often and are rolling over in their Javaesque graves right now seeing that a .Net guy is envious of such a thing but credit is due where credit is due and this is just cool. Come on CLR team give me this!
Online Shopping
This is more of a mental note for myself than anything else but I’m reading an article at the moment that talks about new experiences in online shopping systems and it just occurred to me, Why is it we don’t expose more elements of shopping as RSS feeds and read only services.
Take a weekly ad for example. You can receive a feed that would constantly feed to users sale or clearance items embedded in a feed with a link back to a retailer. A steady stream of content that allows a user to choose which information to follow and what not too.
I did browse walmart.com and found a department by department feed of clearance and sales but no general feed which I found to be disappointing. Usually bargain buyers like myself are looking for any good deal regardless of which department and having the ability to build a custom feed to fit my criteria rather than what Wal-Mart feels appropriate for me to have.
Along with this I think that Amazon.com does a great job of offering great deals etc as well as information in related items, user generated feedback, and 3rd party sellers however its presentation can be extremely cluttered and often unless one wants to search for something they’d have a difficult time just “browsing” what is stock due to the size of inventory that Amazon supports.
Additionally I like the idea of a communal shopping experience much how women currently go shopping in “wolf packs”. Someone picks an item out and they all merit if the color, size, and fit are good for a woman, otherwise it gets thrown back to the piles. This concept is very difficult as a straight forward implementation in the current web world. Various end users cannot login at the same time and share a session between one another and provide real time feedback in either text, voice, video, or a combination of the three. I suppose I’m giving a million dollar idea out here but this seems like a more natural perspective to shopping that may or may not build a better online presence.
Payments Payments Payments
I recently was called into my boss’s office to review an issue that was being reported by our website in the error log. Upon reviewing the code I was reminded of a change our “software architect” made to conform to what he felt was best as far as the naming of things.
Queue Problems.
The architect checked in the broken code which happened to break the interface in our Payment Service and didn’t even take the time up update the service reference in our main business object library. This check-in breaks every unit test associated with ordering. Now this in and of itself wasn’t too bad, I updated the service reference which regenerated the proxy objects and had to restructure some code to conform to the new standard.
Fast forward 6 weeks to today when we review that credit card declines are on the rise and errors are being generated left and right due to some of these changes.
Here’s the crux of the matter. We use an outdated method of a Payment Type and a Payment Method to determine how to authorize payments because an old payment authorizer authored by a 3rd party years ago used to use. Over the years we have completely phased out this system in favor of a new .Net platform but this system of Type and Method persist.
What’s the problem with this design? Nothing from the outside until you look at how we authorize payments globally. For any given currency we have 1 authorizer. In the US it is SuperCharge in Europe it is Bibit and that is it. These elements can be inferred either by Currency or by Country of origination either way both Type and Method can be deemed useless.
Why is this persisted into code that was created 6 weeks ago? No clue. Analysis of business practices should persist across any project irregardless of when the original design was created.
Chances are the original design was bad back when it was created and only a fraction of the “super-awesome-system-to-beat-all-systems” is used anyway. This leads me to wonder if a fresh eye on a design periodically should be done to assure code smell is reduced.
If i were to give a letter grade on this project it’d get an F for failure to think. Ugh.
XML and CSS
Recently in a lab assignment for school I had to create an XML schema for creating a book and then use CSS to directly style it. At first I felt the assignment was a bit of a WTF moment because so far as I’ve understood up until this point XSLT was the only way to transform a document for display purposes.
I am pleased to admit I was completely wrong and that not only can CSS be used to style XML directly it is also supported as a valid way of displaying XML according to the W3C.
The assignment as I developed it became an extremely fun way of utilizing XML and I was very pleased with the output. Imagine just having to style an element directly and bam your document is displayed exactly how you thought it would be right… right?
No, it won’t. Well that’s not completely true it will render 100% accurately in Internet Explorer but only in Internet Explorer. I tested it in Chrome and FireFail neither of which will even recognize that a style sheet is there or even attempt to use it. This is very disconcerting as I would love to utilize this technology for developing a content management system in the future. Its not to be I suppose. Instead the content must be translated to POS-HTML and go w/ the headache of attempting to make everything cross browser compliant.
My other curiosity is trying to fathom how both Google and Mozilla can be lauded as being at the forefront of web technologies compliance with their XML support is lacking… especially on a standard by the W3C. Granted its a rarely used technology but isn’t it both the aforementioned companies that have dinged Microsoft for picking and choosing what to support and what not too?