View this PageEdit this Page (locked)Attachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Discussion two

P1 - 4) Describe the Portland Form; why is it useful? :

The Portland Form is used to format the explanation of design patterns. A document written in the Portland Form contains several paragraphs which discribe different design patterns followed by a summary section. At , the Portland Form is described as a type of narrative where the author talks about problems that can be solved by using certain design patterns which, in turn, create their own problems that can be solved by other patterns. In this way, the Portland Form is described as 'narrative' because it reads like a story. The summary section in Portland Form papers locates and identifies groups of design patterns which deal with the same or similar problems. This section basically describes the problem at hand and then lists any design patterns that deal with that problem. Connections and applications are left for the reader to make. The Portland Form is useful because it allows authors to link together different design patterns that can be used to solve complex problems and once these patterns are linked, they can be looked at as one thing instead of several things. This is good because single ideas seem to be more easily understood than several ideas at once.

P2) Describe a design pattern. - Singleton Pattern :

The Singleton Pattern defines the creation and use of a single instance of a class. It defines a 'singleton' as a class that has only one instance and a global point of access to that instance. This implementation is useful when only one instance of a thing should exist such as a network interface or a database. Access to singleton classes places them apart from simple things such as global variables. Access is given by calling a function in the class which then returns a reference to the only instance. Since a function must be called to access the instance, anything that needs to be set up before the reference is returned can be executed. This provides a certain amount of control over the instance and can insure its proper functioning. The use of singletons is also welcomed where the programmer would otherwise have to pass a reference of an instance through all function calls. This eliminates an amount of coding, breaks interdependancies between otherwise unrelated pieces of code, and makes code easier to read. A variation of the Singleton Pattern allows for a pool of instances that may be accessed globally through the original class. This is useful when more than one thing represented by the class might exist but the programmer still wants to retain control over the instances. An example, provided on , involves a programmer wanting to provide support for multiple graphics cards. Usually, there will not be more than one card in any single computer but when there is, the 'singleton-pool' type class can handle it by giving the same access to the second instance which represents the second graphics card.

I believe this pattern to be very useful because it simplifies code and allows me to visualize systems more clearly. I have actually used the Singleton Pattern in my code before because it simplified the workings of my program greatly. It allowed me to centralize certain objects in my system which needed to be accessed by many or all other parts of the program. I made the network portion a singleton and that made my life a lot easier when it came to communicating with a server that was set up. I didn't have to worry about passing the socket class' variable everywhere or making sure I only accessed it where it was defined. I also avoided having copies of that variable in different classes.

Link to this Page