A Beginner’s Guide to Object-Oriented Programming with Apex: 3. Polymorphism

This is part 3 in the series “A Beginner’s Guide to Object-Oriented Programming with Apex” and will cover the aspect of Polymorphism. For other posts in this series see the links below. A Beginner’s Guide to Object-Oriented Programming with Apex What the hell is Polymorphism? Polymorphism has the funkiest name and is my favourite aspect of OOP. If done correctly you will feel like a proper genius. Originating from Greek words, polymorphism more or less means “many forms”. This gives away very little unless you know polymorphism quite well but essentially polymorphism describes the ability of a type e.g. a set of differing Apex classes, to be used in similar ways without knowing much about those classes. An immediate example on the platform is the Type.format() static method available on Integers, DateTime, etc**. Although each of the Types represents something different this method does a similar thing for each i.e. turns …

Read more

A Beginner’s Guide to Object-Oriented Programming with Apex: 2. Abstraction

This is part 3 in the series “A Beginner’s Guide to Object-Oriented Programming with Apex” and will cover the aspect of Abstraction. For other posts in this series see the links below. A Beginner’s Guide to Object-Oriented Programming with Apex What the hell is Abstraction? Abstraction is a very interesting and surprisingly simple concept. At its core it’s about context and if Abstraction were a company it’s motto would be “Provide the right tools and data at the right time.”. There are many analogies in the “real world” e.g. Where is this applicable to developers on the platform? Ever created a Visualforce component or Apex utility class? Well you my friend you are already using abstraction! This sounds a lot like Encapsulation! Abstraction and Encapsulation go hand in hand but they are different. Encapsulation is one of the ways you can achieve abstraction but does not encompass the entire concept. …

Read more

A Beginner’s Guide to Object-Oriented Programming with Apex: 1. Encapsulation

This is part 2 in the series “A Beginner’s Guide to Object-Oriented Programming with Apex” and will cover the aspect of Encapsulation.

A Beginner’s Guide to Object-Oriented Programming with Apex

  1. Introduction
  2. Encapsulation (this post)
  3. Abstraction
  4. Polymorphism

What the hell is Encapsulation?

Encapsulation isn’t a tricky concept in itself but some confusion does arise from it’s close relationship with Abstraction (to be covered in my next post). Broadly it is defined as one of, or both of the following:

  1. An information hiding mechanism.
  2. A bundling of data and methods that operate on that data.

These are pretty abstract statements but in reality are very simple. I will demystify them with examples below but for now let’s use an analogy:

Imagine you have a watch (or if you have one just consider it, don’t worry about the imagining part) that tells you the date and time. You can adjust the date and time using buttons/knobs/switches but you have no idea what happens inside the watch, just that it results in the date and time changing. You have some data (the date and time), you have some methods to operate on that data (buttons/knobs/switches) and there is a whole lot of stuff going on in the background that you don’t know about (and it’s better that way, imagine you had to adjust all those bits and pieces yourself).

That’s encapsulation baby!

Read more

A Beginner’s Guide to Object-Oriented Programming with Apex: 0. An Introduction

Apex has come a long way in the past few years, and as Salesforce has grown so has the number of super smart people working on the platform. There are lots of guides on how to do fancy things using JavaScript, Apex and Visualforce as well as many more whitepapers on the topics of governances and standards. However I think there is a gap, and I’d like to plug it. Over the next few weeks and months I will be releasing articles that describe and show the basics of object-oriented programming (OOP) with Apex. My approach will be to make these articles as modular and simple as possible. The target audience? Developers with a-teeny-bit-of-experience through to those who have tons of experience but never had any formal training in OOP. A Beginner’s Guide to Object-Oriented Programming with Apex What the hell is OOP? Good question, and although many agree on …

Read more

Salesforce: Polymorphism driven by Apex class inheritance

Polywhatsthatnow? Polymorphism ” is the ability of one type, A, to appear as and be used like another type, B.

It is a facet of OOP and can best be described using the good ol’ example of the ‘Shape’ class problem (thanks Java!). Let’s suppose we’d like to create an application that drew a number of shapes on a page. At the time of analysis we know that we want to immediately support circles, but to future-proof our application we need to support the drawing of any shapes. Being Pretty Darn Good Developers(tm) we realise we should create a Shape class that has a single method used to draw itself, and any specific shapes should be derived from this class, and override that method. Make sense? Didn’t think so.

Read more

Flickr + jQuery + Salesforce = Awesome^5 [Part 1]

Being a mathematician, equations like those in the title usually make me wanna poke someone in the eye.. but in this case it’s just too true to not use. My aim over the next two posts is to provide you with the knowledge to,

  1. Consume web services from within the Force.com platform(without WSDLs).
  2. Use web services(we’ll be using the SOAP-based variety), or other agents, as data sources for integration with JavaScript, and in particular, jQuery.

I will cover point 1 in this post, and then bring it all together in a second post which will cover point 2. It’s gonna be a rocky ride, but I’m sure all you cowboys/girls/others can handle it. Just so we know where we want to end up, our final product will look something like this,

Read more

OOP in the Salesforce Cloud – ReCaptcha Revisited

Can I get a OOP OOP?! That’s right folks, OOP is alive and well on the Force.com platform, and over the past few months I’ve had some pretty thrilling experiences implementing projects using those trusted sidekicks Encapsulation, Polymorphism and trusty ol’ Abstraction. There is some pretty sweet documentation on the subject, but I thought I’d demo something supercool I learnt by combining two articles from the Force.com wiki.

Read more