Web Design Software Development

Web Design, Software Development And Tuorials, Tarpaulin printing ...

Using the singleton design pattern

What is the Singleton Design Patternc
A group of authors now affectionately known as the ‘Gang of Four’ (Erich Gamma, Richard Helm, Ralph Johnson, and John Vilssides) wrote a book called ‘Design Patterns: Elements of Reusable Object-Oriented Software’. In this book they defined three categories of design patterns which are:
Creational Patterns Structural Patterns Behavioural Patterns
The Singleton Design pattern falls into the category of Creational Design Patterns, the Singleton Design Pattern ensures your software has only one instance of the class and provides a global access to it. In other wordsthe Singleton design pattern is all about making sure that you can instantiate only one object of a particular class. If you don’tuse a pattern like this one, the new operator justkeeps oncreating moreand more objects.
Could I not just use a Static Class
Technically you could just use a static class as then there would only be one shared instance of a class for. However, if you did that then you would miss out on some of the benefits of the singleton design pattern. These benefits that singletons have over static classes include:
Singletons can implement interfaces and inherit from other classes A singletons can be lazy loaded. Only when it is actually needed. That’s very handy if the initialisation includes expensive resource loading or database connections Singeltons offer an actual object Singletons can be extended into a software factory. The object management behind the scenes is abstract so it’s better maintainable and results in better code Static classes are instantiated at runtime. This could be time consuming. Singletons can be instantiated only when needed So how do you use the Singleton Design Patternc
In object oriented programming and softwaredevelopmentyou generally create an instance of an object by using a new operator, for example:

C#: MyObject myNewInstance = new MyObject()
VB.NET: Dim myNewInstance As New MyObject()

Each time a new object the computer allocates a heap of memory, creating lots of these object will increase the amount of memory is used and potentially effect the performance of your softwareproduct.

So how do we make it so that we only ever have one instance of our class, well it is a very simple 2 stage process:
Create the objects contructor as PRIVATE , that way no code outside of the class can creat an instance of the object. Create a static/shared method within the class that will return a newly created instance of your class, or if an instance already exists then it will return the current instance. Singleton Design PatternExample

public class MyObject
//create a private static variale to store our instance
private static MyObject singletonObject;

//create a private constructor
private MyObject()

//create a publi static method to return the instance
public static MyObject CreateInstance()
//check if we already have an instance, if soreturn it, else create a new

if (singletonObject == null)
singletonObject = new MyObject();



Public Class MyObject

‘create a private static variale to store our instance
Private SharedsingletonObject As MyObject

‘create a private constructor
Private Sub New()

‘initialise the object
End Sub

‘create a public static method to return the instance
Public Shared Function CreateInstance() As MyObject

‘check if we already have an instance, if soreturn it, else create a new

If singletonObject Is NothingThen
singletonObject = new MyObject()
End If

End Function
End Class

Notice how inthe implementation of the singleton design pattern we declare a private static variable to store the instance of our class. When we call the function we have created to create our instance a check is performed to see if an instance exists in that variable, if not one is created and returned.

About the author: About the Author: This article was provided by Real IT Solutions, a Derbyshire based Derby Web Design, Software Development and Internet Marketing company.

Source: http://www.articlesbase.com/programming-articles/using-the-singleton-design-pattern-931313.html

10 thoughts on “Web Design Software Development”

  1. What’s the essential software for web design and development?
    If you had to create a course of 500 hours, where students were to learn to use the adobe package and some programming languages to create and maintain a web site, what courses would you include and what would be the duration of each?

  2. I need a unique name for my software development, web designing and consulting company…?
    which may or may not have dictionary meaning associated with that but in future the world will know it. I dont want to give a cheap name to my firm so kindly suggest a better name for a web designing, software development and consultation company.

  3. Best city to open new web design/internet marketing/software development office in NCR or best city in India?

    We are planning to start one new office.
    Please let me know in which city we can find talented developer easily and have quality living too.

    Issue: Easy to find technical persons and safe for night shifts too.

    If you are a software developer OR work / Own IT company please let me know in which city you work.

    Thank You

  4. Web design and software development couse help?
    Can someone please help with choosing what course that offers these two subject at university based in England.

  5. best city is gurgaon to start a IT company as it is close to delhi and having very good infrastructure it is the best city to start a business here are various towers which allow only IT companies at a cheap price.To know more about gurgaon check it out.

  6. What web design / development software is the best?
    I have been told so many different versions of the ” Best ” Web design software.
    For a few years I was learning, practicing and using Microsoft Publisher.
    A Sales rep from one store told me I would need to use front page.
    Another store told me to use Adobe and last I was told to use Microsoft Visual Basic.

    And the prices of each of these are drastically different.

    Does anyone know which software is the best or let me know if there is an even better one than I listed above?

    Thank you for your time

  7. – Photoshop for the graphics (Industry standard). Basics in 6 to 10 one hour lessons should be enough for the basics: remember, your scholars are “Artists”
    – Marketing (no software, but a market driven course: a website that is not “market” oriented is doomed to fail – 90% fail for that reason). The time it takes to get an MBA?
    – Coding: one program only: a text editor (Notepad++), and 490 to 494 hours, in various languages: (X)HTML (20hrs), javascript (40hrs), CSS (20hrs), Php (the rest), MySQL (5hrs), AJAX (3hrs).
    Extra curriculum:
    – Why NOT use any window based server (20 mins)
    – Why NOT use any Microsoft based web development tools (IIS, ASP, JSP, .net etc) – See http://www.web2coders, articles, “ASP v Php”.

    You would be forming pretty powerful web developers!
    (And if you need a teacher, I am your man! Teacher in Machine Vision, Cardiff University – Teacher in Computer Criminology, Police Academy Abu dabi – and more…)

  8. i’ve written websites for major international companies and i’m rewriting one for a university now and the software I use varies a lot.

    The newer WYSIWYG editors support a variety of languages and write validated code – I don’t know why people still go on about FrontPage it was good in its day but is 10 years old and has now been replaced by Microsoft.

    Here’s some editors that I know…

    Adobe Dreamweaver – http://www.adobe.com/products/dreamweaver/
    Microsoft SharePoint Developer – http://office.microsoft.com/en-us/sharepointdesigner/FX100487631033.aspx – Made for SharePoint server technologies. I like using this editor.
    Microsft Expression – http://www.microsoft.com/expression/products/Overview.aspx?key=studio – Haven’t tried this yet but it looks good as it supports ASP and PHP

    There are some nice free ones as well

    NVU – http://www.net2.com/nvu/ has been been superceeded by KompoZer – http://kompozer.net/
    Microsoft Visual Web Developeer 2008 – http://www.microsoft.com/express/vwd/ – this software is great, just like the other Express products. The only thing I found missing in it is a multi-line find and replace – only single line find and replace is available in this edition.

    I still sometimes write code in Notepad but with so many good tools available now that’s more like the good old days of writing C or Basic programs without an IDE (Integrated Development Environment).

Comments are closed.