Codekiwi
Just a the musings of a kiwi who loves to code...

OO Refresher Course

My current contract is drawing to a close so I once again find myself in the unenvieable position of looking around for my next challenge (I hate interviewing).

One of the positions I applied for was with a recruitment firm called Super Coders (novel concept, IT recruitment by an outfit that, on the surface anyways, seem to understand coding). Whilst having a look around their site, I came upon this article on things you must know about OO. The upshot of the article is this list of 23 topics (which originally came from a Steve Yegge article):

  1. class, object (and the difference between the two)
  2. instantiation
  3. method (as opposed to, say, a C function)
  4. virtual method, pure virtual method
  5. class/static method
  6. static/class initializer
  7. constructor
  8. destructor/finalizer
  9. superclass or base class
  10. subclass or derived class
  11. inheritance
  12. encapsulation
  13. multiple inheritance (and give an example)
  14. delegation/forwarding
  15. composition/aggregation
  16. abstract class
  17. interface/protocol (and different from abstract class)
  18. method overriding
  19. method overloading (and difference from overriding)
  20. polymorphism (without resorting to examples)
  21. is-a versus has-a relationships (with examples)
  22. method signatures (what's included in one)
  23. method visibility (e.g. public/private/other)

So I thought as I am once more heading into the murky waters that is Contactor job hunting, I thought I would test myself. I surprised myself with the results,

It was more difficult than I anticipated.

Firstly I am primarily a VB developer so converting the concepts into VB friendly buzzwords first would have made it easier.

However for the most part I found it difficult, not because I didn't understand these concepts but more that even though I use most of them daily and read about them often, it is only during interviews that it is required to verbalise them.

I found this a great little exercise to get the grey matter churning again so I encourage you to give this a go, either in your own blog or in the comments. also any subjects that I have gotten wrong, please feel free to berate/teach me in the comments.

I treated this as a semi open book test, ie I attempted the topic but if I failed I resorted to google, however I only wanted to use google as a backup to my knowlege rather than to learn the topic.

class, object (and the difference between the two)
A class is a "blueprint" for an object. an object is an instance of a class

instantiation
instantiation is when a class is used to create an instance of an object, it is good practice to keep the instantiation responsibility for dependencies in a centrally managed location (DI and IOC)

method (as opposed to, say, a C function)
a method is a proceedure built into a class and can (assuming visibility) be called on an instance of an object. methods are split into two types, ones that produce a value and ones that don't

virtual method, pure virtual method (*Google only required because VB uses the term Overridable or MustOverride instead of virtual and pure virtual)
A virtual function is a method of a base class that can be overridden in a class that inherits from it, a pure virtual method must be overridden to be used

class/static method
a static method or class is one that can be accessed without instantiation, local methods or variables are not available in these

static/class initializer
used in the singleton pattern is a static method that returns an instance of its class

constructor
a special method (called new) that is used to create an instance of a class

destructor/finalizer
a special method that is called when an object is no longer required and its resources are to be freed up

superclass or base class
a base class in inheritance is the class that the child inherits from, with inheritance the derived class makes available the visible methods and properties of the base class

subclass or derived class
the derived class is the clild in the inheritance relationship, the relationship is one way a base class does not have access to a child classes methods or properties

inheritance
the technique of inheriting from a base class to create a derived class that is a combination of the child and parent classes

encapsulation (* One of the most basic OO concepts but I always foget the explanation of the buzzword)
encapsulation is the technique of only making available the infomation that the user (or coder) needs to see, internal methods should stay internal

multiple inheritance (and give an example) (* not an excuse but I haven't used this as it is not available in my chosen environment)
the ability for a derived class to inherit from multiple base classes, this feature is not available in C# or VB, instead chained inheritance is available, ie john inherits from male which inherits from person which inherits from mammal. whereas in languages supporting multiple inheritance John could inherit from male, person and mammal

delegation/forwarding
delegation is the technique of assigning a subroutine of work to be completed when an event occurs, this is instead of staticly defining programitic flow, this is done by assigning the location of the subroutine at runtime, an extension of this is annonymous delegates in which the entire method can be dynamically assigned.

composition/aggregation (*)
aggregation is when an object has a reference to another object but those objects have a life cycle of their own, composition is when an object is responsibile for the creation and lifecycle of a child object

abstract class
an abstact class is a class that must be inherited from before instantiation (ie cannot be directly instantiated)

interface/protocol (and different from abstract class)
an interface is a contract that an implementation must adhere to, an interface contains methods and properties that must exist in the implemented class to be valid, an abstract class may contain implementations of the methods whereas an interface is just a specificiation

method overriding
when a derived class overrides the behaviour of a method in its base class

method overloading (and difference from overriding)
the technique of creating multiple methods of the same name within a class varying by signatiure

polymorphism (without resorting to examples) (* I can never remember this)
Polymorphisim or subtype polymorphisim is the ability of one type to be used as another, this can be done using base classes or interfaces.

is-a versus has-a relationships (with examples)
the is-a/has-a rule is a simple test to decide weather two classes are related via inheritance or composition for example a boeing 747 is-a plane (747 inherits from plane) and a 747 has-a cockpit (747 contains a property of type cockpit)

method signatures (what's included in one)
A methods signature is the combination of arguments that are passed into a method

method visibility (e.g. public/private/other)
Method visiblity aka scope is the defining of who and what can see/access a method or property, this can be limited by class, inheritance or physical/library boundries.

*In the interest of full disclosure these topics are ones that I needed a little help (ie thanks google). also ctrl-c was not used in the production of these answers ;P

  1. class, object (and the difference between the two)
  2. instantiation
  3. method (as opposed to, say, a C function)
  4. virtual method, pure virtual method
  5. class/static method
  6. static/class initializer
  7. constructor
  8. destructor/finalizer
  9. superclass or base class
  10. subclass or derived class
  11. inheritance
  12. encapsulation
  13. multiple inheritance (and give an example)
  14. delegation/forwarding
  15. composition/aggregation
  16. abstract class
  17. interface/protocol (and different from abstract class)
  18. method overriding
  19. method overloading (and difference from overriding)
  20. polymorphism (without resorting to examples)
  21. is-a versus has-a relationships (with examples)
  22. method signatures (what's included in one)
  23. method visibility (e.g. public/private/other)

 



This version of SQL Server in use does not support datatype datetime2 EF problem.

Had a strange error come up today when I tried to use my home PC to run an Entity Framework project, the EDMX schema (is it a schema) was generated in SQL Server 2008 and my home dev machine has SQL Server 2005.

I wouldn't have thought this would be a problem as I don't use any 2008 specific features (except the intellisense ;P), but alas I was getting a lot of exceptions from my FunctionImports (stored proceedures in Entity Framework).

Upon investigating the stack trace it was telling me that the DateTime2 datatype was not supported in this version of SQL server, Very strange as I am sure that I do not use the Datetime2 or Date datatypes (these are 2008 specific)
 

This is due to the edmx file being generated or updated from a SQL 2008 instance and run against a SQL 2005 instance. I tried about every trick I could think of before reading about it here. Basically all you need to do is to open the EDMX file with XML Editor and change ProviderManifestToken=”2008” to ProviderManifestToken=”2005”. Thanks a bunch Alex Duggleby for the hint!

From The #Crypt Via Alex Duggleby

Just another thing that I hope will be fixed in the forthcoming EF4.



Implementing a Testable Mockable Repository pattern with the Entity Framework

I came across and found very useful, bare in mind I am relatively new to the EF and TDD so any suggestions would be welcomed.

I have been very busy recently with a new project, as I am in control of this project I have wanted to do things correctly from the start, I also am using it as an opportunity to get familiar with all the newest and shiniest of Microsoft's technologies. The platform is using a combination of ASP.Net MVC 2.0 and the Entity Framework 3.0.

Because I know this codebase is going to grow very large I wanted to get off on the right foot and have a robust but flexible data access strategy and have unit testing engrained I found a fantastic article by Morshed Anwar on CodeProject, Here is the link I highly recommend reading it.

Repository provides an in-memory like collection interface for accessing domain objects. So as far as the consuming component is concerned, it uses the repository just like a collection when working with Domain objects. The repository then neatly abstracts the internal mechanics of how the Add / Remove calls to the repository translate to the actual data access calls to the data store. Objects can be added to and removed from the Repository, as they can from a simple collection of objects, and the mapping code encapsulated by the Repository will carry out the appropriate operations behind the scenes. Conceptually, a Repository encapsulates the set of objects persisted in a data store and the operations performed over them, providing a more object-oriented view of the persistence layer. Repository also supports the objective of achieving a clean separation and one-way dependency between the domain and data mapping layers.

So with the repository we get a nice abstraction that provides us with persistence ignorance and a nice separation of concerns where the responsibility of persisting domain objects is encapsulated by the Repository leaving the domain objects to deal entirely with the domain model and domain logic.

 After implementing this thing worked very well, I could create a new repository in my business layer with a single line (albieit a long one)

This worked well for my application, allowing me to use linq to provide safe data access from my business layer while adhereing to the S in SOLID (Separation of concerns), however when I came to the unit tests (yes I know I should be doing these first, but I'm not TDD yet) I ran into a brick wall.

The problem comes from the fact the DoQuery operations return an ObjectQuery, Because ObjectQuery is not abstract and sealed it cannot be mocked using Moq or Rhino mocks, I did however find an article by Muhammad Mosa on TypeMock Isolator and the EF . This was not a solution for me as Typemock Isolator is not free and my project is so far funded by me.

After a little research I realised (with a head slapping moment) that the ObjectQuery(Of T) class implements the IQueryable(Of T) interface, after swapping this out in the Repository class everything worked brilliantly. See below for the DoQuery method

So yes this whole post is just to explain replacing the return type of the DoQuery, but the power of this simple change has mean't I can fully mock my data access, see my mocked repository below (using Rhino Mocks)



Windows 7 First Impressions

Well last night after enduring the start of Melbourne's heat wave, Air conditioning blasting and nothing worth watching on the TV, I decided to take the plunge and install the Windows 7 beta and give it a go.

I decided to install it on a separate partition on my Media Centre PC after deciding that my laptop just wouldn't be able keep up despite Microsofts claims to the contrary.

To my complete surprise, the most difficult part of the installation was trying to find a DVD to burn the image onto, The installation in total to around 20 Minutes (not including the DVD burning) and asked me no obnoxious questions.

The boot time has improved I think, but the boot time has never really bothered me, unless I am on an underpowered or cluttered machine. Until we have "instant on" I don't think I will be impressed with windows boot time.

One of the first things that struck me is the UAC (User access control A.K.A. "Bastard window thingie always asking for permission"). In Vista the UAC what was the bane of my existance, now is a tool that actually makes you feel more secure about what is going in and out of the operating system.

During my test the only time the screen actually dimmed and asked for permission was when I was installing a new application. I feel that this is a fair interruption becuase I want to know when something is being installed , relying on the application installer to be honest about what is happening is putting too much trust in the developers (it takes one to know one).

The media centre built into Windows 7, although I haven't had a full run with it, seems to be a full product in itself, whereas in Vista it seemed a bit like an afterthought. It still has a few bugs but that is to be expected with beta, for example some videos would not play, but this could be down to missing codecs (or dodgy video files).

Far and away the best new aspect of the OS is the new task bar and by extension the way that applications (both running and installed) are managed. The new task bar takes a little getting used to but once you do, I find it much more productive. and easier to manage large amounts of windows.

Gizmodo has a full breakdown on how the new taskbar works and why they think it is even better than the way Mac OSX manages applications. I highly recommend reading it if you intend on trying Windows 7 out, its a great read and also serves as a primer on how to use windows when you first get started.

There is a lot of other eye candy and Microsoft tells us there is a lot more to come. Its not just that, its the additions that just make it feel like a more polished user experiance, and starts to achieve what a true OS should do, you should forget that you are using one and only focus on the applications you are using.



When Should I test?

While doing a bit of reading on TDD I stumbled across these two fantastic links from Steven Harman.

Two quick and straight to the point reference guides to outline when and how often to write tests in your solution. 

 Nice work.


Then he follows it up with this gem "Saving the world via TDD", possibly the best example of TDD code ever. It attempts to prove that if skynet had of followed correct TDD principals arnie and his terminator pals would have never waged their war on the human race

Alternatively there is XKCD's take on a solution to the same problem below..



Windows 7 Conundrum

Ok, here it is. like a true geek I have downloaded the Windows 7 beta with a view to kick the tires on the new MS OS before the unwashed masses get it.

I only have two machines at home; The first is a slightly aging Compaq Presario v4000 laptop, which I have had for about three years, it currently runs both Windows XP home (OEM) and Windows Server 2003 on which I do casual development, however I have used it in the past for more in depth development, to be honest this machines current role mostly consists of a computer for me to throw money down the drain playing online poker..

The second machine is a new desktop that I built myself, it has fast processors (Intel E8400), adequate ram (4Gb but only half the slots used) and a truck load of disk space, I built this machine to reinstate my 'moonlighting' development work but as yet have been too busy. So this one have become my media center as there is a problem with the digital tv reception in my area, I have an HDMI cable running from this machine to my TV.

But here is the problem, I know the desktop/media center would run Windows 7 without breaking a sweat but I would ideally like to install the beta on the laptop and test it out. This way if the installation fails or for some reason the machine is taken out of action, I will still like to be able to use my media center (Solving the problems of the world huh),

I have read on many articles how well Windows 7 is performing on lower spec'd machines, even netbooks, but my question is how low do these spec's extend. I don't want to go through the whole installation experience only to find that my aging laptop is past its prime and cannot keep up with the OS Jones's.

For those of you who are considering walking the path I am currently lost on, Gizmodo has a great bunch of Windows 7 articles.

FWIW; From the feedback that is seeping through the intertubes it seems that Windows 7 is shaping up to be what we as .net developers have waited a LONG time for, an operating system that we can be proud of. I think the .Net community is holding is collective breath.



Browser wars

Found this today, thought it was pretty neat, Would have thought Safari would have a bigger market share, although not sure if its entirely to scale.

Pixel labs via {Codequeeze}

 



Well, Where do I start.

At the beginning I suspect,

I am a kiwi and I love to code.. Phew, that was difficult, they say starting is the hardest part (well its been the hardest part so far).

I have wanted to start a blog for a some time, initailly to engage more with the developer community, as time went by and I had still not started my blog, I found more and more I had things to say but no platform to make myself heard, So we find ourselves (read: me) at this point.

What better time to get underway than on the eve of the obama's inauguration. Not much in common but Im sure the enormity of the occassion is not lost on you.

The purpose of this blog is to prompt active discussions on hot topics around the .Net development platform, and dare I say it the odd argument.

Anyways, All I would like to say that I am going to make this blog an interesting, targeted read with on point topics... That said, well I dont really have anything else to say this time...

I just wanted to say HI...