(Java) Java inheritance example

This example demonstrates advanced object-oriented concepts including inheritance, getters/setters, method overloading and reflection.

Read More »

→ Continue Reading

(Java) Java data structures example

This example demonstrates intermediate object-oriented programming concepts including Data Structures, Linked Lists and how method overriding works. In addition, it demonstrates how to document code properly, with ample comments and proper Javadocs which can generate corresponding code API docs.

Read More »

→ Continue Reading

(JavaScript) JavaScript Factory Pattern

The Factory Pattern suggests defining an interface for creating an object where you allow the subclasses to decide which class to instantiate. This pattern handles the problem by defining a completely separate method for the creation of objects and which sub-classes are able to override so they can specify the ‘type’ of factory product that will be created.

Read More »

→ Continue Reading

(JavaScript) JavaScript Basic Decorator Pattern

In this section we’re going to explore the decorator – a structural design pattern that promotes code reuse and is a flexible alternative to subclassing. This pattern is also useful for modifying existing systems where you may wish to add additional features to objects without the need to change the underlying code that uses them.

Traditionally, the decorator is defined as a design pattern that allows behavior to be added to an existing object dynamically. The idea is that the decoration itself isn’t essential to the base functionality of an object otherwise it would be baked into the ‘superclass’ object itself.

Read More »

→ Continue Reading

(JavaScript) JavaScript Mediator Pattern

In software engineering, a mediator is a behavioral design pattern that allows us to
expose a unified interface through which the different parts of a system may communicate. If it appears a system may have too many direct relationships between modules (colleagues), it may be time to have a central point of control that modules communicate through instead. The Mediator promotes loose coupling by ensuring that instead of modules referring to each other explicitly, their interaction is handled through this central point.

If you would prefer a real-world analogy, consider a typical airport traffic control system. A tower (mediator) handles what planes can take off and land because all communications (notifications being listened out for or broadcast) are done from the planes to the control tower, rather than from plane-to-plane. A centralized controller is key to the success of this system and that’s really the role a mediator plays in software design.

Read More »

→ Continue Reading

(JavaScript) JavaScript Command Pattern

The Command pattern aims to encapsulate method invocation, requests or operations
into a single object and gives you the ability to both parameterize and pass method calls
around that can be executed at your discretion. In addition, it enables you to decouple
objects invoking the action from the objects which implement them, giving you a
greater degree of overall flexibility in swapping out concrete ‘classes’.

Read More »

→ Continue Reading

(JavaScript) JavaScript Observer Pattern

The Observer pattern is more popularly known these days as the Publish/Subscribe
pattern. It is a design pattern which allows an object (known as a subscriber) to watch another object (the publisher), where we provide a means for the subscriber and pub-lisher form a listen and broadcast relationship.

Popular JavaScript libraries such as dojo, jQuery (custom events) and YUI
already have utilities that can assist in easily implementing a Pub/Sub system with very little effort.

Read More »

→ Continue Reading

(JavaScript) Javascript Module Pattern

The module pattern was originally defined as a way to provide both private and public encapsulation for classes in conventional software engineering.
In JavaScript, the module pattern is used to further emulate the concept of classes in such a way that we’re able to include both public/private methods and variables inside a single object, thus shielding particular parts from the global scope. What this results in is a reduction in the likelihood of your function names conflicting with other functions defined in additional scripts on the page.

Read More »

→ Continue Reading

(JavaScript) Javascript Object Literal

In object literal notation, an object is described as a set of comma-separated name/
value pairs enclosed in curly braces ({}). Names inside the object may be either strings or identifiers that are followed by a colon. There should be no comma used after the final name/value pair in the object as this may result in errors.

Read More »

→ Continue Reading

(MySQL) Age in Years for Given Birthdate

Given a birthdate in @dob, here are two simple formulae for age in years :
(the second formulae is for age in years to two decimal places, ignoring day of month)

Read More »

→ Continue Reading