<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rbjeffer</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rbjeffer"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Rbjeffer"/>
	<updated>2026-08-10T00:27:22Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56345</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56345"/>
		<updated>2011-11-30T00:57:01Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the Gang of Four&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
Similar to the Call Super antipattern is the BaseBean antipattern.  It is found in object-oriented programming when a concrete domain class is formed using inheritance from a utility class.  This relationship is used simply to inherit utility methods from the utility class.  This is sometimes referred to as inheritance for implementation.&lt;br /&gt;
&lt;br /&gt;
Inheritance for the sake of gaining the functionality in the parent class is not good style.  This obviously is not an &amp;quot;is-a&amp;quot; a relationship and may violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle]. By inheriting from the utility class, the domain class becomes dependent on the internals of the utility class.  This can make the system difficult to maintain.  Additionally, the domain class now has all the functionality of the utility class - some of which it might not need.  This blurs the concept of the domain class and may cause it to have more than a single responsibility.&lt;br /&gt;
&lt;br /&gt;
In good object-oriented programming, objects should be representative of the real-world entities they exemplify and should relate to each other as such.  In this scenario a &amp;quot;has-a&amp;quot; relationship would be more appropriate.  The inherited functionality can be obtained using delegation instead of inheritance.  By using the [http://en.wikipedia.org/wiki/Composition_over_inheritance composition over inheritance] principle, we can avoid the BaseBean antipattern.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we want to create a class that emulates a toll booth.  The cars at the toll booth form a queue, so our toll booth will need the functionality (queue, dequeue, isEmpty, etc.) of a queue.  We could implement our toll booth by inheriting this functionality from a Queue class as such:&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth extends Queue{&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Obviously, a tollbooth is not a queue, but more appropriately, has a queue.  Hence, our toll booth class should be created to contain a queue to model the line of cars.&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth&lt;br /&gt;
      private Queue&amp;lt;Vehicles&amp;gt;&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Our TollBooth class now has the functionality it needs without the inherent liabilities of extending the Queue class.&lt;br /&gt;
&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  Because it has many responsibilities, it would be difficult to reuse in a future project.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
An example of class approaching '''The Blob''' that may be familiar to many students this semester is the [http://wikis.lib.ncsu.edu/index.php/Expertiza  Expertiza] Project's assignment model.&amp;lt;ref name=&amp;quot;expertiza&amp;quot; /&amp;gt;  The assignment model in Expertiza does not encapsulate the majority of functionality in the entire application, but it is out of proportion with most of the other classes, and it does include functionality that should be in some other classes.&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;  One of the Open-Source Software projects for this semester is to correct some of these problems.  The project assignment contains the following notes:&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;[The assignment model] contains functionality for adding and removing participants for this assignment, which should really be in a participant class, for assigning reviewers, which should probably be in a reviewer class, and for computing the maximum score possible on a questionnaire.  Functions like compute_scores, and candidate_topics_to_review, among others, should be moved to other classes.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These notes describe some of the excessive functionality of assignment.rb.  It also suggests some other classes that would be more appropriate locations for some functionalities.  If these modifications are made, then the assignment model will be of a more manageable size, and will not be in danger of becoming '''The Blob'''.  &lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  &lt;br /&gt;
&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for a new problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  This can occur if the developers are simply comfortable with or used to an existing approach, or even the result of narrow-mindedness or hubris.   It can also be the direct result of reliance on proprietary technologies or products, or a deliberate effort to try to build a previous projects' success into a new program.  A '''Golden Hammer''' will typically manifest itself with poor performance or scalability.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
When [http://en.wikipedia.org/wiki/Automated_teller_machine Automated Teller Machines (ATMs)] were popularized in the 1970s, they were often designed using [http://en.wikipedia.org/wiki/Computer_terminal Dumb Terminals], a contemporary computer technology.  In the 1990s and 2000s, many banks began replacing their aging ATMs with more modern ones that were physically more difficult to break into.  Many of these banks have not changed the communication protocols that the ATMs use to conduct transactions with the bank's servers or mainframe, because weaknesses in the protocol or cryptography is not the cause of most ATM fraud.&amp;lt;ref name=&amp;quot;crypto&amp;quot; /&amp;gt;  As a result, many banks designed new ATMs that were required to somehow use the existing technology: encrypted dumb terminal sessions.  The majority of these systems that have been deployed used a familiar '''Golden Hammer''' to do this: [http://en.wikipedia.org/wiki/Terminal_emulator Terminal Emulator] software installed on a variant of the [http://en.wikipedia.org/wiki/Microsoft_windows Microsoft Windows] operating system.&amp;lt;ref name=&amp;quot;wikipedia_atm&amp;quot; /&amp;gt;  This design decision has several negative effects, including:&lt;br /&gt;
* Increased unit cost of ATMs, because each one must have a licensed copy of a commercial operating system&lt;br /&gt;
* Concerns about the reliability and trustworthiness of the underlying ATM software&amp;lt;ref name=windowsatm /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
In this article, we have described some of the most commonly occurring AntiPatterns.  AntiPatterns comprise a set of defective processes and pitfalls in software development.  They describe common errors in judgment or design made by both software engineers and project managers.  They explain the causes of these errors, and offer suggestions for correcting the errors.  AntiPatterns also define a standard set of vocabulary, so that they can be understood broadly.  They are important for both programmers and managers to know and understand, in order to avoid costly mistakes.  &lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
For additional information regarding antipatterns, check out the following resources.&lt;br /&gt;
&lt;br /&gt;
===Books===&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/exec/obidos/ISBN=0471197130/portlandpatternrA/ ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''.] Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, (ed) (1998).&lt;br /&gt;
&lt;br /&gt;
* [http://sourcemaking.com/antipatterns-book ''AntiPatterns: The Survival Guide'']&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612  ''Design Patterns: Elements of Reusable Object-Oriented Software''] by Erich Gamma, Richard Helm], Ralph Johnson, and John Vlissides(the Gang Of Four)&lt;br /&gt;
&lt;br /&gt;
===Websites===&lt;br /&gt;
&lt;br /&gt;
* [http://c2.com/cgi/wiki?AntiPatternsCatalog AntiPatterns Catalog]&lt;br /&gt;
&lt;br /&gt;
* [http://www.antipatterns.com/ AntiPatterns.com] Web site for the ''AntiPatterns'' book&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Category:Anti-patterns Wikipedia Antipatterns Category]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by the Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; [http://sourcemaking.com/antipatterns/the-blob http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; [http://en.wikipedia.org/wiki/Golden_hammer http://en.wikipedia.org/wiki/Golden_hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; [http://sourcemaking.com/antipatterns/golden-hammer http://sourcemaking.com/antipatterns/golden-hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = expertiza&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza - Reusable learning objects through peer review] &amp;lt;/ref&amp;gt; &lt;br /&gt;
&amp;lt;ref name = fall2011_oss&amp;gt; [https://docs.google.com/a/ncsu.edu/document/d/1zZ-a_tkLGrbYJbG-2QBCRqe_Y9XLR4AZMH0rc6KvrYU/edit?hl=en_US CSC/ECE517 Fall 2011 OSS Projects in Expertiza] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = crypto&amp;gt; Anderson, R. 1993. Why cryptosystems fail. In Proceedings of the 1st ACM Conference on Computer and Communications Security (Fairfax, Virginia, United States, November 03 - 05, 1993). CCS '93 [http://www.cl.cam.ac.uk/~rja14/Papers/wcf.pdf]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wikipedia_atm&amp;gt; [http://en.wikipedia.org/wiki/Automatic_Teller_Machine http://en.wikipedia.org/wiki/Automatic_Teller_Machine]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = windowsatm&amp;gt; [http://www.technewsworld.com/story/32350.html &amp;quot;Technology News: Security: Windows Cash-Machine Worm Generates Concern&amp;quot;. Technewsworld.com] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56344</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56344"/>
		<updated>2011-11-30T00:55:35Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the Gang of Four&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
Similar to the Call Super antipattern is the BaseBean antipattern.  It is found in object-oriented programming when a concrete domain class is formed using inheritance from a utility class.  This relationship is used simply to inherit utility methods from the utility class.  This is sometimes referred to as inheritance for implementation.&lt;br /&gt;
&lt;br /&gt;
Inheritance for the sake of gaining the functionality in the parent class is not good style.  This obviously is not an &amp;quot;is-a&amp;quot; a relationship and may violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle]. By inheriting from the utility class, the domain class becomes dependent on the internals of the utility class.  This can make the system difficult to maintain.  Additionally, the domain class now has all the functionality of the utility class - some of which it might not need.  This blurs the concept of the domain class and may cause it to have more than a single responsibility.&lt;br /&gt;
&lt;br /&gt;
In good object-oriented programming, objects should be representative of the real-world entities they exemplify and should relate to each other as such.  In this scenario a &amp;quot;has-a&amp;quot; relationship would be more appropriate.  The inherited functionality can be obtained using delegation instead of inheritance.  By using the [http://en.wikipedia.org/wiki/Composition_over_inheritance composition over inheritance] principle, we can avoid the BaseBean antipattern.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we want to create a class that emulates a toll booth.  The cars at the toll booth form a queue, so our toll booth will need the functionality (queue, dequeue, isEmpty, etc.) of a queue.  We could implement our toll booth by inheriting this functionality from a Queue class as such:&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth extends Queue{&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Obviously, a tollbooth is not a queue, but more appropriately, has a queue.  Hence, our toll booth class should be created to contain a queue to model the line of cars.&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth&lt;br /&gt;
      private Queue&amp;lt;Vehicles&amp;gt;&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Our TollBooth class now has the functionality it needs without the inherent liabilities of extending the Queue class.&lt;br /&gt;
&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  Because it has many responsibilities, it would be difficult to reuse in a future project.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
An example of class approaching '''The Blob''' that may be familiar to many students this semester is the [http://wikis.lib.ncsu.edu/index.php/Expertiza  Expertiza] Project's assignment model.&amp;lt;ref name=&amp;quot;expertiza&amp;quot; /&amp;gt;  The assignment model in Expertiza does not encapsulate the majority of functionality in the entire application, but it is out of proportion with most of the other classes, and it does include functionality that should be in some other classes.&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;  One of the Open-Source Software projects for this semester is to correct some of these problems.  The project assignment contains the following notes:&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;[The assignment model] contains functionality for adding and removing participants for this assignment, which should really be in a participant class, for assigning reviewers, which should probably be in a reviewer class, and for computing the maximum score possible on a questionnaire.  Functions like compute_scores, and candidate_topics_to_review, among others, should be moved to other classes.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These notes describe some of the excessive functionality of assignment.rb.  It also suggests some other classes that would be more appropriate locations for some functionalities.  If these modifications are made, then the assignment model will be of a more manageable size, and will not be in danger of becoming '''The Blob'''.  &lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  &lt;br /&gt;
&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for a new problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  This can occur if the developers are simply comfortable with or used to an existing approach, or even the result of narrow-mindedness or hubris.   It can also be the direct result of reliance on proprietary technologies or products, or a deliberate effort to try to build a previous projects' success into a new program.  A '''Golden Hammer''' will typically manifest itself with poor performance or scalability.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
When [http://en.wikipedia.org/wiki/Automated_teller_machine Automated Teller Machines (ATMs)] were popularized in the 1970s, they were often designed using [http://en.wikipedia.org/wiki/Computer_terminal Dumb Terminals], a contemporary computer technology.  In the 1990s and 2000s, many banks began replacing their aging ATMs with more modern ones that were physically more difficult to break into.  Many of these banks have not changed the communication protocols that the ATMs use to conduct transactions with the bank's servers or mainframe, because weaknesses in the protocol or cryptography is not the cause of most ATM fraud.&amp;lt;ref name=&amp;quot;crypto&amp;quot; /&amp;gt;  As a result, many banks designed new ATMs that were required to somehow use the existing technology: encrypted dumb terminal sessions.  The majority of these systems that have been deployed used a familiar '''Golden Hammer''' to do this: [http://en.wikipedia.org/wiki/Terminal_emulator Terminal Emulator] software installed on a variant of the [http://en.wikipedia.org/wiki/Microsoft_windows Microsoft Windows] operating system.&amp;lt;ref name=&amp;quot;wikipedia_atm&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
In this article, we have described some of the most commonly occurring AntiPatterns.  AntiPatterns comprise a set of defective processes and pitfalls in software development.  They describe common errors in judgment or design made by both software engineers and project managers.  They explain the causes of these errors, and offer suggestions for correcting the errors.  AntiPatterns also define a standard set of vocabulary, so that they can be understood broadly.  They are important for both programmers and managers to know and understand, in order to avoid costly mistakes.  This design decision has several negative effects, including:&lt;br /&gt;
* Increased unit cost of ATMs, because each one must have a licensed copy of a commercial operating system&lt;br /&gt;
* Concerns about the reliability and trustworthiness of the underlying ATM software&amp;lt;ref name=windowsatm /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
For additional information regarding antipatterns, check out the following resources.&lt;br /&gt;
&lt;br /&gt;
===Books===&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/exec/obidos/ISBN=0471197130/portlandpatternrA/ ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''.] Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, (ed) (1998).&lt;br /&gt;
&lt;br /&gt;
* [http://sourcemaking.com/antipatterns-book ''AntiPatterns: The Survival Guide'']&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612  ''Design Patterns: Elements of Reusable Object-Oriented Software''] by Erich Gamma, Richard Helm], Ralph Johnson, and John Vlissides(the Gang Of Four)&lt;br /&gt;
&lt;br /&gt;
===Websites===&lt;br /&gt;
&lt;br /&gt;
* [http://c2.com/cgi/wiki?AntiPatternsCatalog AntiPatterns Catalog]&lt;br /&gt;
&lt;br /&gt;
* [http://www.antipatterns.com/ AntiPatterns.com] Web site for the ''AntiPatterns'' book&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Category:Anti-patterns Wikipedia Antipatterns Category]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by the Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; [http://sourcemaking.com/antipatterns/the-blob http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; [http://en.wikipedia.org/wiki/Golden_hammer http://en.wikipedia.org/wiki/Golden_hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; [http://sourcemaking.com/antipatterns/golden-hammer http://sourcemaking.com/antipatterns/golden-hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = expertiza&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza - Reusable learning objects through peer review] &amp;lt;/ref&amp;gt; &lt;br /&gt;
&amp;lt;ref name = fall2011_oss&amp;gt; [https://docs.google.com/a/ncsu.edu/document/d/1zZ-a_tkLGrbYJbG-2QBCRqe_Y9XLR4AZMH0rc6KvrYU/edit?hl=en_US CSC/ECE517 Fall 2011 OSS Projects in Expertiza] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = crypto&amp;gt; Anderson, R. 1993. Why cryptosystems fail. In Proceedings of the 1st ACM Conference on Computer and Communications Security (Fairfax, Virginia, United States, November 03 - 05, 1993). CCS '93 [http://www.cl.cam.ac.uk/~rja14/Papers/wcf.pdf]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wikipedia_atm&amp;gt; [http://en.wikipedia.org/wiki/Automatic_Teller_Machine http://en.wikipedia.org/wiki/Automatic_Teller_Machine]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = windowsatm&amp;gt; [http://www.technewsworld.com/story/32350.html &amp;quot;Technology News: Security: Windows Cash-Machine Worm Generates Concern&amp;quot;. Technewsworld.com] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56343</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56343"/>
		<updated>2011-11-30T00:55:05Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the Gang of Four&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
Similar to the Call Super antipattern is the BaseBean antipattern.  It is found in object-oriented programming when a concrete domain class is formed using inheritance from a utility class.  This relationship is used simply to inherit utility methods from the utility class.  This is sometimes referred to as inheritance for implementation.&lt;br /&gt;
&lt;br /&gt;
Inheritance for the sake of gaining the functionality in the parent class is not good style.  This obviously is not an &amp;quot;is-a&amp;quot; a relationship and may violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle]. By inheriting from the utility class, the domain class becomes dependent on the internals of the utility class.  This can make the system difficult to maintain.  Additionally, the domain class now has all the functionality of the utility class - some of which it might not need.  This blurs the concept of the domain class and may cause it to have more than a single responsibility.&lt;br /&gt;
&lt;br /&gt;
In good object-oriented programming, objects should be representative of the real-world entities they exemplify and should relate to each other as such.  In this scenario a &amp;quot;has-a&amp;quot; relationship would be more appropriate.  The inherited functionality can be obtained using delegation instead of inheritance.  By using the [http://en.wikipedia.org/wiki/Composition_over_inheritance composition over inheritance] principle, we can avoid the BaseBean antipattern.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we want to create a class that emulates a toll booth.  The cars at the toll booth form a queue, so our toll booth will need the functionality (queue, dequeue, isEmpty, etc.) of a queue.  We could implement our toll booth by inheriting this functionality from a Queue class as such:&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth extends Queue{&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Obviously, a tollbooth is not a queue, but more appropriately, has a queue.  Hence, our toll booth class should be created to contain a queue to model the line of cars.&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth&lt;br /&gt;
      private Queue&amp;lt;Vehicles&amp;gt;&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Our TollBooth class now has the functionality it needs without the inherent liabilities of extending the Queue class.&lt;br /&gt;
&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  Because it has many responsibilities, it would be difficult to reuse in a future project.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
An example of class approaching '''The Blob''' that may be familiar to many students this semester is the [http://wikis.lib.ncsu.edu/index.php/Expertiza  Expertiza] Project's assignment model.&amp;lt;ref name=&amp;quot;expertiza&amp;quot; /&amp;gt;  The assignment model in Expertiza does not encapsulate the majority of functionality in the entire application, but it is out of proportion with most of the other classes, and it does include functionality that should be in some other classes.&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;  One of the Open-Source Software projects for this semester is to correct some of these problems.  The project assignment contains the following notes:&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;[The assignment model] contains functionality for adding and removing participants for this assignment, which should really be in a participant class, for assigning reviewers, which should probably be in a reviewer class, and for computing the maximum score possible on a questionnaire.  Functions like compute_scores, and candidate_topics_to_review, among others, should be moved to other classes.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These notes describe some of the excessive functionality of assignment.rb.  It also suggests some other classes that would be more appropriate locations for some functionalities.  If these modifications are made, then the assignment model will be of a more manageable size, and will not be in danger of becoming '''The Blob'''.  &lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  &lt;br /&gt;
&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for a new problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  This can occur if the developers are simply comfortable with or used to an existing approach, or even the result of narrow-mindedness or hubris.   It can also be the direct result of reliance on proprietary technologies or products, or a deliberate effort to try to build a previous projects' success into a new program.  A '''Golden Hammer''' will typically manifest itself with poor performance or scalability.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
When [http://en.wikipedia.org/wiki/Automated_teller_machine Automated Teller Machines (ATMs)] were popularized in the 1970s, they were often designed using [http://en.wikipedia.org/wiki/Computer_terminal Dumb Terminals], a contemporary computer technology.  In the 1990s and 2000s, many banks began replacing their aging ATMs with more modern ones that were physically more difficult to break into.  Many of these banks have not changed the communication protocols that the ATMs use to conduct transactions with the bank's servers or mainframe, because weaknesses in the protocol or cryptography is not the cause of most ATM fraud.&amp;lt;ref name=&amp;quot;crypto&amp;quot; /&amp;gt;  As a result, many banks designed new ATMs that were required to somehow use the existing technology: encrypted dumb terminal sessions.  The majority of these systems that have been deployed used a familiar '''Golden Hammer''' to do this: [http://en.wikipedia.org/wiki/Terminal_emulator Terminal Emulator] software installed on a variant of the [http://en.wikipedia.org/wiki/Microsoft_windows Microsoft Windows] operating system.&amp;lt;ref name=&amp;quot;wikipedia_atm&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
In this article, we have described some of the most commonly occurring AntiPatterns.  AntiPatterns comprise a set of defective processes and pitfalls in software development.  They describe common errors in judgment or design made by both software engineers and project managers.  They explain the causes of these errors, and offer suggestions for correcting the errors.  AntiPatterns also define a standard set of vocabulary, so that they can be understood broadly.  They are important for both programmers and managers to know and understand, in order to avoid costly mistakes.  This design decision has several negative effects, including:&lt;br /&gt;
+ Increased unit cost of ATMs, because each one must have a licensed copy of a commercial operating system&lt;br /&gt;
+ Concerns about the reliability and trustworthiness of the underlying ATM software&amp;lt;ref name=windowsatm /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
For additional information regarding antipatterns, check out the following resources.&lt;br /&gt;
&lt;br /&gt;
===Books===&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/exec/obidos/ISBN=0471197130/portlandpatternrA/ ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''.] Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, (ed) (1998).&lt;br /&gt;
&lt;br /&gt;
* [http://sourcemaking.com/antipatterns-book ''AntiPatterns: The Survival Guide'']&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612  ''Design Patterns: Elements of Reusable Object-Oriented Software''] by Erich Gamma, Richard Helm], Ralph Johnson, and John Vlissides(the Gang Of Four)&lt;br /&gt;
&lt;br /&gt;
===Websites===&lt;br /&gt;
&lt;br /&gt;
* [http://c2.com/cgi/wiki?AntiPatternsCatalog AntiPatterns Catalog]&lt;br /&gt;
&lt;br /&gt;
* [http://www.antipatterns.com/ AntiPatterns.com] Web site for the ''AntiPatterns'' book&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Category:Anti-patterns Wikipedia Antipatterns Category]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by the Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; [http://sourcemaking.com/antipatterns/the-blob http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; [http://en.wikipedia.org/wiki/Golden_hammer http://en.wikipedia.org/wiki/Golden_hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; [http://sourcemaking.com/antipatterns/golden-hammer http://sourcemaking.com/antipatterns/golden-hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = expertiza&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza - Reusable learning objects through peer review] &amp;lt;/ref&amp;gt; &lt;br /&gt;
&amp;lt;ref name = fall2011_oss&amp;gt; [https://docs.google.com/a/ncsu.edu/document/d/1zZ-a_tkLGrbYJbG-2QBCRqe_Y9XLR4AZMH0rc6KvrYU/edit?hl=en_US CSC/ECE517 Fall 2011 OSS Projects in Expertiza] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = crypto&amp;gt; Anderson, R. 1993. Why cryptosystems fail. In Proceedings of the 1st ACM Conference on Computer and Communications Security (Fairfax, Virginia, United States, November 03 - 05, 1993). CCS '93 [http://www.cl.cam.ac.uk/~rja14/Papers/wcf.pdf]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wikipedia_atm&amp;gt; [http://en.wikipedia.org/wiki/Automatic_Teller_Machine http://en.wikipedia.org/wiki/Automatic_Teller_Machine]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = windowsatm&amp;gt; [http://www.technewsworld.com/story/32350.html &amp;quot;Technology News: Security: Windows Cash-Machine Worm Generates Concern&amp;quot;. Technewsworld.com] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56342</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56342"/>
		<updated>2011-11-30T00:46:53Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the Gang of Four&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
Similar to the Call Super antipattern is the BaseBean antipattern.  It is found in object-oriented programming when a concrete domain class is formed using inheritance from a utility class.  This relationship is used simply to inherit utility methods from the utility class.  This is sometimes referred to as inheritance for implementation.&lt;br /&gt;
&lt;br /&gt;
Inheritance for the sake of gaining the functionality in the parent class is not good style.  This obviously is not an &amp;quot;is-a&amp;quot; a relationship and may violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle]. By inheriting from the utility class, the domain class becomes dependent on the internals of the utility class.  This can make the system difficult to maintain.  Additionally, the domain class now has all the functionality of the utility class - some of which it might not need.  This blurs the concept of the domain class and may cause it to have more than a single responsibility.&lt;br /&gt;
&lt;br /&gt;
In good object-oriented programming, objects should be representative of the real-world entities they exemplify and should relate to each other as such.  In this scenario a &amp;quot;has-a&amp;quot; relationship would be more appropriate.  The inherited functionality can be obtained using delegation instead of inheritance.  By using the [http://en.wikipedia.org/wiki/Composition_over_inheritance composition over inheritance] principle, we can avoid the BaseBean antipattern.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we want to create a class that emulates a toll booth.  The cars at the toll booth form a queue, so our toll booth will need the functionality (queue, dequeue, isEmpty, etc.) of a queue.  We could implement our toll booth by inheriting this functionality from a Queue class as such:&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth extends Queue{&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Obviously, a tollbooth is not a queue, but more appropriately, has a queue.  Hence, our toll booth class should be created to contain a queue to model the line of cars.&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth&lt;br /&gt;
      private Queue&amp;lt;Vehicles&amp;gt;&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Our TollBooth class now has the functionality it needs without the inherent liabilities of extending the Queue class.&lt;br /&gt;
&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  Because it has many responsibilities, it would be difficult to reuse in a future project.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
An example of class approaching '''The Blob''' that may be familiar to many students this semester is the [http://wikis.lib.ncsu.edu/index.php/Expertiza  Expertiza] Project's assignment model.&amp;lt;ref name=&amp;quot;expertiza&amp;quot; /&amp;gt;  The assignment model in Expertiza does not encapsulate the majority of functionality in the entire application, but it is out of proportion with most of the other classes, and it does include functionality that should be in some other classes.&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;  One of the Open-Source Software projects for this semester is to correct some of these problems.  The project assignment contains the following notes:&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;[The assignment model] contains functionality for adding and removing participants for this assignment, which should really be in a participant class, for assigning reviewers, which should probably be in a reviewer class, and for computing the maximum score possible on a questionnaire.  Functions like compute_scores, and candidate_topics_to_review, among others, should be moved to other classes.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These notes describe some of the excessive functionality of assignment.rb.  It also suggests some other classes that would be more appropriate locations for some functionalities.  If these modifications are made, then the assignment model will be of a more manageable size, and will not be in danger of becoming '''The Blob'''.  &lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  &lt;br /&gt;
&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for a new problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  This can occur if the developers are simply comfortable with or used to an existing approach, or even the result of narrow-mindedness or hubris.   It can also be the direct result of reliance on proprietary technologies or products, or a deliberate effort to try to build a previous projects' success into a new program.  A '''Golden Hammer''' will typically manifest itself with poor performance or scalability.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
When [http://en.wikipedia.org/wiki/Automated_teller_machine Automated Teller Machines (ATMs)] were popularized in the 1970s, they were often designed using [http://en.wikipedia.org/wiki/Computer_terminal Dumb Terminals], a contemporary computer technology.  In the 1990s and 2000s, many banks began replacing their aging ATMs with more modern ones that were physically more difficult to break into.  Many of these banks have not changed the communication protocols that the ATMs use to conduct transactions with the bank's servers or mainframe, because weaknesses in the protocol or cryptography is not the cause of most ATM fraud.&amp;lt;ref name=&amp;quot;crypto&amp;quot; /&amp;gt;  As a result, many banks designed new ATMs that were required to somehow use the existing technology: encrypted dumb terminal sessions.  The majority of these systems that have been deployed used a familiar '''Golden Hammer''' to do this: [http://en.wikipedia.org/wiki/Terminal_emulator Terminal Emulator] software installed on a variant of the [http://en.wikipedia.org/wiki/Microsoft_windows Microsoft Windows] operating system. &lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
In this article, we have described some of the most commonly occurring AntiPatterns.  AntiPatterns comprise a set of defective processes and pitfalls in software development.  They describe common errors in judgment or design made by both software engineers and project managers.  They explain the causes of these errors, and offer suggestions for correcting the errors.  AntiPatterns also define a standard set of vocabulary, so that they can be understood broadly.  They are important for both programmers and managers to know and understand, in order to avoid costly mistakes.  &lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
For additional information regarding antipatterns, check out the following resources.&lt;br /&gt;
&lt;br /&gt;
===Books===&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/exec/obidos/ISBN=0471197130/portlandpatternrA/ ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''.] Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, (ed) (1998).&lt;br /&gt;
&lt;br /&gt;
* [http://sourcemaking.com/antipatterns-book ''AntiPatterns: The Survival Guide'']&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612  ''Design Patterns: Elements of Reusable Object-Oriented Software''] by Erich Gamma, Richard Helm], Ralph Johnson, and John Vlissides(the Gang Of Four)&lt;br /&gt;
&lt;br /&gt;
===Websites===&lt;br /&gt;
&lt;br /&gt;
* [http://c2.com/cgi/wiki?AntiPatternsCatalog AntiPatterns Catalog]&lt;br /&gt;
&lt;br /&gt;
* [http://www.antipatterns.com/ AntiPatterns.com] Web site for the ''AntiPatterns'' book&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Category:Anti-patterns Wikipedia Antipatterns Category]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by the Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; [http://sourcemaking.com/antipatterns/the-blob http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; [http://en.wikipedia.org/wiki/Golden_hammer http://en.wikipedia.org/wiki/Golden_hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; [http://sourcemaking.com/antipatterns/golden-hammer http://sourcemaking.com/antipatterns/golden-hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = expertiza&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza - Reusable learning objects through peer review] &amp;lt;/ref&amp;gt; &lt;br /&gt;
&amp;lt;ref name = fall2011_oss&amp;gt; [https://docs.google.com/a/ncsu.edu/document/d/1zZ-a_tkLGrbYJbG-2QBCRqe_Y9XLR4AZMH0rc6KvrYU/edit?hl=en_US CSC/ECE517 Fall 2011 OSS Projects in Expertiza] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = crypto&amp;gt; Anderson, R. 1993. Why cryptosystems fail. In Proceedings of the 1st ACM Conference on Computer and Communications Security (Fairfax, Virginia, United States, November 03 - 05, 1993). CCS '93 [http://www.cl.cam.ac.uk/~rja14/Papers/wcf.pdf]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56341</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56341"/>
		<updated>2011-11-30T00:20:16Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the Gang of Four&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
Similar to the Call Super antipattern is the BaseBean antipattern.  It is found in object-oriented programming when a concrete domain class is formed using inheritance from a utility class.  This relationship is used simply to inherit utility methods from the utility class.  This is sometimes referred to as inheritance for implementation.&lt;br /&gt;
&lt;br /&gt;
Inheritance for the sake of gaining the functionality in the parent class is not good style.  This obviously is not an &amp;quot;is-a&amp;quot; a relationship and may violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle]. By inheriting from the utility class, the domain class becomes dependent on the internals of the utility class.  This can make the system difficult to maintain.  Additionally, the domain class now has all the functionality of the utility class - some of which it might not need.  This blurs the concept of the domain class and may cause it to have more than a single responsibility.&lt;br /&gt;
&lt;br /&gt;
In good object-oriented programming, objects should be representative of the real-world entities they exemplify and should relate to each other as such.  In this scenario a &amp;quot;has-a&amp;quot; relationship would be more appropriate.  The inherited functionality can be obtained using delegation instead of inheritance.  By using the [http://en.wikipedia.org/wiki/Composition_over_inheritance composition over inheritance] principle, we can avoid the BaseBean antipattern.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we want to create a class that emulates a toll booth.  The cars at the toll booth form a queue, so our toll booth will need the functionality (queue, dequeue, isEmpty, etc.) of a queue.  We could implement our toll booth by inheriting this functionality from a Queue class as such:&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth extends Queue{&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Obviously, a tollbooth is not a queue, but more appropriately, has a queue.  Hence, our toll booth class should be created to contain a queue to model the line of cars.&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth&lt;br /&gt;
      private Queue&amp;lt;Vehicles&amp;gt;&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Our TollBooth class now has the functionality it needs without the inherent liabilities of extending the Queue class.&lt;br /&gt;
&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  Because it has many responsibilities, it would be difficult to reuse in a future project.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
An example of class approaching '''The Blob''' that may be familiar to many students this semester is the [http://wikis.lib.ncsu.edu/index.php/Expertiza  Expertiza] Project's assignment model.&amp;lt;ref name=&amp;quot;expertiza&amp;quot; /&amp;gt;  The assignment model in Expertiza does not encapsulate the majority of functionality in the entire application, but it is out of proportion with most of the other classes, and it does include functionality that should be in some other classes.&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;  One of the Open-Source Software projects for this semester is to correct some of these problems.  The project assignment contains the following notes:&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;[The assignment model] contains functionality for adding and removing participants for this assignment, which should really be in a participant class, for assigning reviewers, which should probably be in a reviewer class, and for computing the maximum score possible on a questionnaire.  Functions like compute_scores, and candidate_topics_to_review, among others, should be moved to other classes.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These notes describe some of the excessive functionality of assignment.rb.  It also suggests some other classes that would be more appropriate locations for some functionalities.  If these modifications are made, then the assignment model will be of a more manageable size, and will not be in danger of becoming '''The Blob'''.  &lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  &lt;br /&gt;
&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for a new problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  This can occur if the developers are simply comfortable with or used to an existing approach, or even the result of narrow-mindedness or hubris.   It can also be the direct result of reliance on proprietary technologies or products, or a deliberate effort to try to build a previous projects' success into a new program.  A '''Golden Hammer''' will typically manifest itself with poor performance or scalability.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
In this article, we have described some of the most commonly occurring AntiPatterns.  AntiPatterns comprise a set of defective processes and pitfalls in software development.  They describe common errors in judgment or design made by both software engineers and project managers.  They explain the causes of these errors, and offer suggestions for correcting the errors.  AntiPatterns also define a standard set of vocabulary, so that they can be understood broadly.  They are important for both programmers and managers to know and understand, in order to avoid costly mistakes.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
For additional information regarding antipatterns, check out the following resources.&lt;br /&gt;
&lt;br /&gt;
===Books===&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/exec/obidos/ISBN=0471197130/portlandpatternrA/ ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''.] Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, (ed) (1998).&lt;br /&gt;
&lt;br /&gt;
* [http://sourcemaking.com/antipatterns-book ''AntiPatterns: The Survival Guide'']&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612  ''Design Patterns: Elements of Reusable Object-Oriented Software''] by Erich Gamma, Richard Helm], Ralph Johnson, and John Vlissides(the Gang Of Four)&lt;br /&gt;
&lt;br /&gt;
===Websites===&lt;br /&gt;
&lt;br /&gt;
* [http://c2.com/cgi/wiki?AntiPatternsCatalog AntiPatterns Catalog]&lt;br /&gt;
&lt;br /&gt;
* [http://www.antipatterns.com/ AntiPatterns.com] Web site for the ''AntiPatterns'' book&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Category:Anti-patterns Wikipedia Antipatterns Category]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by the Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; [http://sourcemaking.com/antipatterns/the-blob http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; [http://en.wikipedia.org/wiki/Golden_hammer http://en.wikipedia.org/wiki/Golden_hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; [http://sourcemaking.com/antipatterns/golden-hammer http://sourcemaking.com/antipatterns/golden-hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = expertiza&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza - Reusable learning objects through peer review] &amp;lt;/ref&amp;gt; &lt;br /&gt;
&amp;lt;ref name = fall2011_oss&amp;gt; [https://docs.google.com/a/ncsu.edu/document/d/1zZ-a_tkLGrbYJbG-2QBCRqe_Y9XLR4AZMH0rc6KvrYU/edit?hl=en_US CSC/ECE517 Fall 2011 OSS Projects in Expertiza] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56340</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56340"/>
		<updated>2011-11-30T00:17:30Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the Gang of Four&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
Similar to the Call Super antipattern is the BaseBean antipattern.  It is found in object-oriented programming when a concrete domain class is formed using inheritance from a utility class.  This relationship is used simply to inherit utility methods from the utility class.  This is sometimes referred to as inheritance for implementation.&lt;br /&gt;
&lt;br /&gt;
Inheritance for the sake of gaining the functionality in the parent class is not good style.  This obviously is not an &amp;quot;is-a&amp;quot; a relationship and may violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle]. By inheriting from the utility class, the domain class becomes dependent on the internals of the utility class.  This can make the system difficult to maintain.  Additionally, the domain class now has all the functionality of the utility class - some of which it might not need.  This blurs the concept of the domain class and may cause it to have more than a single responsibility.&lt;br /&gt;
&lt;br /&gt;
In good object-oriented programming, objects should be representative of the real-world entities they exemplify and should relate to each other as such.  In this scenario a &amp;quot;has-a&amp;quot; relationship would be more appropriate.  The inherited functionality can be obtained using delegation instead of inheritance.  By using the [http://en.wikipedia.org/wiki/Composition_over_inheritance composition over inheritance] principle, we can avoid the BaseBean antipattern.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we want to create a class that emulates a toll booth.  The cars at the toll booth form a queue, so our toll booth will need the functionality (queue, dequeue, isEmpty, etc.) of a queue.  We could implement our toll booth by inheriting this functionality from a Queue class as such:&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth extends Queue{&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Obviously, a tollbooth is not a queue, but more appropriately, has a queue.  Hence, our toll booth class should be created to contain a queue to model the line of cars.&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth&lt;br /&gt;
      private Queue&amp;lt;Vehicles&amp;gt;&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Our TollBooth class now has the functionality it needs without the inherent liabilities of extending the Queue class.&lt;br /&gt;
&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  Because it has many responsibilities, it would be difficult to reuse in a future project.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
An example of class approaching '''The Blob''' that may be familiar to many students this semester is the [http://wikis.lib.ncsu.edu/index.php/Expertiza  Expertiza] Project's assignment model.&amp;lt;ref name=&amp;quot;expertiza&amp;quot; /&amp;gt;  The assignment model in Expertiza does not encapsulate the majority of functionality in the entire application, but it is out of proportion with most of the other classes, and it does include functionality that should be in some other classes.&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;  One of the Open-Source Software projects for this semester is to correct some of these problems.  The project assignment contains the following notes:&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;[The assignment model] contains functionality for adding and removing participants for this assignment, which should really be in a participant class, for assigning reviewers, which should probably be in a reviewer class, and for computing the maximum score possible on a questionnaire.  Functions like compute_scores, and candidate_topics_to_review, among others, should be moved to other classes.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These notes describe some of the excessive functionality of assignment.rb.  It also suggests some other classes that would be more appropriate locations for some functionalities.  If these modifications are made, then the assignment model will be of a more manageable size, and will not be in danger of becoming '''The Blob'''.  &lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  &lt;br /&gt;
&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for a new problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  This can occur if the developers are simply comfortable with or used to an existing approach, or even the result of narrow-mindedness or hubris.   It can also be the direct result of reliance on proprietary technologies or products, or a deliberate effort to try to build a previous projects' success into a new program.  A '''Golden Hammer''' will typically manifest itself with poor performance or scalability.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
In this article, we have described some of the most commonly occurring AntiPatterns.  AntiPatterns comprise a set of defective processes and pitfalls in software development.  They describe common errors in judgment or design made by both software engineers and project managers.  They explain the causes of these errors, and offer suggestions for correcting the errors.  AntiPatterns also define a standard set of vocabulary, so that they can be understood broadly.  They are important for both programmers and managers to know and understand, in order to avoid costly mistakes.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
For additional information regarding antipatterns, check out the following resources.&lt;br /&gt;
&lt;br /&gt;
===Books===&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/exec/obidos/ISBN=0471197130/portlandpatternrA/ ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''.] Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, (ed) (1998).&lt;br /&gt;
&lt;br /&gt;
* [http://sourcemaking.com/antipatterns-book ''AntiPatterns: The Survival Guide'']&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612  ''Design Patterns: Elements of Reusable Object-Oriented Software''] by Erich Gamma, Richard Helm], Ralph Johnson, and John Vlissides(the Gang Of Four)&lt;br /&gt;
&lt;br /&gt;
===Websites===&lt;br /&gt;
&lt;br /&gt;
* [http://c2.com/cgi/wiki?AntiPatternsCatalog AntiPatterns Catalog]&lt;br /&gt;
&lt;br /&gt;
* [http://www.antipatterns.com/ AntiPatterns.com] Web site for the ''AntiPatterns'' book&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Category:Anti-patterns Wikipedia Antipatterns Category]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; [http://sourcemaking.com/antipatterns/the-blob http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; [http://en.wikipedia.org/wiki/Golden_hammer http://en.wikipedia.org/wiki/Golden_hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; [http://sourcemaking.com/antipatterns/golden-hammer http://sourcemaking.com/antipatterns/golden-hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = expertiza&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza - Reusable learning objects through peer review] &amp;lt;/ref&amp;gt; &lt;br /&gt;
&amp;lt;ref name = fall2011_oss&amp;gt; [https://docs.google.com/a/ncsu.edu/document/d/1zZ-a_tkLGrbYJbG-2QBCRqe_Y9XLR4AZMH0rc6KvrYU/edit?hl=en_US CSC/ECE517 Fall 2011 OSS Projects in Expertiza] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56339</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56339"/>
		<updated>2011-11-30T00:17:07Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the Gang of Four&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
Similar to the Call Super antipattern is the BaseBean antipattern.  It is found in object-oriented programming when a concrete domain class is formed using inheritance from a utility class.  This relationship is used simply to inherit utility methods from the utility class.  This is sometimes referred to as inheritance for implementation.&lt;br /&gt;
&lt;br /&gt;
Inheritance for the sake of gaining the functionality in the parent class is not good style.  This obviously is not an &amp;quot;is-a&amp;quot; a relationship and may violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle]. By inheriting from the utility class, the domain class becomes dependent on the internals of the utility class.  This can make the system difficult to maintain.  Additionally, the domain class now has all the functionality of the utility class - some of which it might not need.  This blurs the concept of the domain class and may cause it to have more than a single responsibility.&lt;br /&gt;
&lt;br /&gt;
In good object-oriented programming, objects should be representative of the real-world entities they exemplify and should relate to each other as such.  In this scenario a &amp;quot;has-a&amp;quot; relationship would be more appropriate.  The inherited functionality can be obtained using delegation instead of inheritance.  By using the [http://en.wikipedia.org/wiki/Composition_over_inheritance composition over inheritance] principle, we can avoid the BaseBean antipattern.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we want to create a class that emulates a toll booth.  The cars at the toll booth form a queue, so our toll booth will need the functionality (queue, dequeue, isEmpty, etc.) of a queue.  We could implement our toll booth by inheriting this functionality from a Queue class as such:&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth extends Queue{&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Obviously, a tollbooth is not a queue, but more appropriately, has a queue.  Hence, our toll booth class should be created to contain a queue to model the line of cars.&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth&lt;br /&gt;
      private Queue&amp;lt;Vehicles&amp;gt;&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Our TollBooth class now has the functionality it needs without the inherent liabilities of extending the Queue class.&lt;br /&gt;
&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  Because it has many responsibilities, it would be difficult to reuse in a future project.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
An example of class approaching '''The Blob''' that may be familiar to many students this semester is the [http://wikis.lib.ncsu.edu/index.php/Expertiza  Expertiza] Project's assignment model.&amp;lt;ref name=&amp;quot;expertiza&amp;quot; /&amp;gt;  The assignment model in Expertiza does not encapsulate the majority of functionality in the entire application, but it is out of proportion with most of the other classes, and it does include functionality that should be in some other classes.&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;  One of the Open-Source Software projects for this semester is to correct some of these problems.  The project assignment contains the following notes:&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;[The assignment model] contains functionality for adding and removing participants for this assignment, which should really be in a participant class, for assigning reviewers, which should probably be in a reviewer class, and for computing the maximum score possible on a questionnaire.  Functions like compute_scores, and candidate_topics_to_review, among others, should be moved to other classes.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These notes describe some of the excessive functionality of assignment.rb.  It also suggests some other classes that would be more appropriate locations for some functionalities.  If these modifications are made, then the assignment model will be of a more manageable size, and will not be in danger of becoming '''The Blob'''.  &lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  &lt;br /&gt;
&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for a new problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  This can occur if the developers are simply comfortable with or used to an existing approach, or even the result of narrow-mindedness or hubris.   It can also be the direct result of reliance on proprietary technologies or products, or a deliberate effort to try to build a previous projects' success into a new program.  A '''Golden Hammer''' will typically manifest itself with poor performance or scalability.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
==Conclusions==&lt;br /&gt;
&lt;br /&gt;
In this article, we have described some of the most commonly occurring AntiPatterns.  AntiPatterns comprise a set of defective processes and pitfalls in software development.  They describe common errors in judgment or design made by both software engineers and project managers.  They explain the causes of these errors, and offer suggestions for correcting the errors.  AntiPatterns also define a standard set of vocabulary, so that they can be understood broadly.  They are important for both programmers and managers to know and understand, in order to avoid costly mistakes.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
For additional information regarding antipatterns, check out the following resources.&lt;br /&gt;
&lt;br /&gt;
===Books===&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/exec/obidos/ISBN=0471197130/portlandpatternrA/ ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''.] Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, (ed) (1998).&lt;br /&gt;
&lt;br /&gt;
* [http://sourcemaking.com/antipatterns-book ''AntiPatterns: The Survival Guide'']&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612  ''Design Patterns: Elements of Reusable Object-Oriented Software''] by Erich Gamma, Richard Helm], Ralph Johnson, and John Vlissides(the Gang Of Four)&lt;br /&gt;
&lt;br /&gt;
===Websites===&lt;br /&gt;
&lt;br /&gt;
* [http://c2.com/cgi/wiki?AntiPatternsCatalog AntiPatterns Catalog]&lt;br /&gt;
&lt;br /&gt;
* [http://www.antipatterns.com/ AntiPatterns.com] Web site for the ''AntiPatterns'' book&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Category:Anti-patterns Wikipedia Antipatterns Category]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; [http://sourcemaking.com/antipatterns/the-blob http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; [http://en.wikipedia.org/wiki/Golden_hammer http://en.wikipedia.org/wiki/Golden_hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; [http://sourcemaking.com/antipatterns/golden-hammer http://sourcemaking.com/antipatterns/golden-hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = expertiza&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza - Reusable learning objects through peer review] &amp;lt;/ref&amp;gt; &lt;br /&gt;
&amp;lt;ref name = fall2011_oss&amp;gt; [https://docs.google.com/a/ncsu.edu/document/d/1zZ-a_tkLGrbYJbG-2QBCRqe_Y9XLR4AZMH0rc6KvrYU/edit?hl=en_US CSC/ECE517 Fall 2011 OSS Projects in Expertiza] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56338</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56338"/>
		<updated>2011-11-29T23:26:10Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the Gang of Four&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
Similar to the Call Super antipattern is the BaseBean antipattern.  It is found in object-oriented programming when a concrete domain class is formed using inheritance from a utility class.  This relationship is used simply to inherit utility methods from the utility class.  This is sometimes referred to as inheritance for implementation.&lt;br /&gt;
&lt;br /&gt;
Inheritance for the sake of gaining the functionality in the parent class is not good style.  This obviously is not an &amp;quot;is-a&amp;quot; a relationship and may violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle]. By inheriting from the utility class, the domain class becomes dependent on the internals of the utility class.  This can make the system difficult to maintain.  Additionally, the domain class now has all the functionality of the utility class - some of which it might not need.  This blurs the concept of the domain class and may cause it to have more than a single responsibility.&lt;br /&gt;
&lt;br /&gt;
In good object-oriented programming, objects should be representative of the real-world entities they exemplify and should relate to each other as such.  In this scenario a &amp;quot;has-a&amp;quot; relationship would be more appropriate.  The inherited functionality can be obtained using delegation instead of inheritance.  By using the [http://en.wikipedia.org/wiki/Composition_over_inheritance composition over inheritance] principle, we can avoid the BaseBean antipattern.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we want to create a class that emulates a toll booth.  The cars at the toll booth form a queue, so our toll booth will need the functionality (queue, dequeue, isEmpty, etc.) of a queue.  We could implement our toll booth by inheriting this functionality from a Queue class as such:&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth extends Queue{&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Obviously, a tollbooth is not a queue, but more appropriately, has a queue.  Hence, our toll booth class should be created to contain a queue to model the line of cars.&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth&lt;br /&gt;
      private Queue&amp;lt;Vehicles&amp;gt;&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Our TollBooth class now has the functionality it needs without the inherent liabilities of extending the Queue class.&lt;br /&gt;
&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  Because it has many responsibilities, it would be difficult to reuse in a future project.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
An example of class approaching '''The Blob''' that may be familiar to many students this semester is the [http://wikis.lib.ncsu.edu/index.php/Expertiza  Expertiza] Project's assignment model.&amp;lt;ref name=&amp;quot;expertiza&amp;quot; /&amp;gt;  The assignment model in Expertiza does not encapsulate the majority of functionality in the entire application, but it is out of proportion with most of the other classes, and it does include functionality that should be in some other classes.&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;  One of the Open-Source Software projects for this semester is to correct some of these problems.  The project assignment contains the following notes:&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;[The assignment model] contains functionality for adding and removing participants for this assignment, which should really be in a participant class, for assigning reviewers, which should probably be in a reviewer class, and for computing the maximum score possible on a questionnaire.  Functions like compute_scores, and candidate_topics_to_review, among others, should be moved to other classes.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These notes describe some of the excessive functionality of assignment.rb.  It also suggests some other classes that would be more appropriate locations for some functionalities.  If these modifications are made, then the assignment model will be of a more manageable size, and will not be in danger of becoming '''The Blob'''.  &lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  &lt;br /&gt;
&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for a new problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  This can occur if the developers are simply comfortable with or used to an existing approach, or even the result of narrow-mindedness or hubris.   It can also be the direct result of reliance on proprietary technologies or products, or a deliberate effort to try to build a previous projects' success into a new program.  A '''Golden Hammer''' will typically manifest itself with poor performance or scalability.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
==Conclusions==&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
For additional information regarding antipatterns, check out the following resources.&lt;br /&gt;
&lt;br /&gt;
===Books===&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/exec/obidos/ISBN=0471197130/portlandpatternrA/ ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''.] Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, (ed) (1998).&lt;br /&gt;
&lt;br /&gt;
* [http://sourcemaking.com/antipatterns-book ''AntiPatterns: The Survival Guide'']&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612  ''Design Patterns: Elements of Reusable Object-Oriented Software''] by Erich Gamma, Richard Helm], Ralph Johnson, and John Vlissides(the Gang Of Four)&lt;br /&gt;
&lt;br /&gt;
===Websites===&lt;br /&gt;
&lt;br /&gt;
* [http://c2.com/cgi/wiki?AntiPatternsCatalog AntiPatterns Catalog]&lt;br /&gt;
&lt;br /&gt;
* [http://www.antipatterns.com/ AntiPatterns.com] Web site for the ''AntiPatterns'' book&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Category:Anti-patterns Wikipedia Antipatterns Category]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; [http://sourcemaking.com/antipatterns/the-blob http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; [http://en.wikipedia.org/wiki/Golden_hammer http://en.wikipedia.org/wiki/Golden_hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; [http://sourcemaking.com/antipatterns/golden-hammer http://sourcemaking.com/antipatterns/golden-hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = expertiza&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza - Reusable learning objects through peer review] &amp;lt;/ref&amp;gt; &lt;br /&gt;
&amp;lt;ref name = fall2011_oss&amp;gt; [https://docs.google.com/a/ncsu.edu/document/d/1zZ-a_tkLGrbYJbG-2QBCRqe_Y9XLR4AZMH0rc6KvrYU/edit?hl=en_US CSC/ECE517 Fall 2011 OSS Projects in Expertiza] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56337</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56337"/>
		<updated>2011-11-29T23:13:38Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the GoF&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
Similar to the Call Super antipattern is the BaseBean antipattern.  It is found in object-oriented programming when a concrete domain class is formed using inheritance from a utility class.  This relationship is used simply to inherit utility methods from the utility class.  This is sometimes referred to as inheritance for implementation.&lt;br /&gt;
&lt;br /&gt;
Inheritance for the sake of gaining the functionality in the parent class is not good style.  This obviously is not an &amp;quot;is-a&amp;quot; a relationship and may violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle]. By inheriting from the utility class, the domain class becomes dependent on the internals of the utility class.  This can make the system difficult to maintain.  Additionally, the domain class now has all the functionality of the utility class - some of which it might not need.  This blurs the concept of the domain class and may cause it to have more than a single responsibility.&lt;br /&gt;
&lt;br /&gt;
In good object-oriented programming, objects should be representative of the real-world entities they exemplify and should relate to each other as such.  In this scenario a &amp;quot;has-a&amp;quot; relationship would be more appropriate.  The inherited functionality can be obtained using delegation instead of inheritance.  By using the [http://en.wikipedia.org/wiki/Composition_over_inheritance composition over inheritance] principle, we can avoid the BaseBean antipattern.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we want to create a class that emulates a toll booth.  The cars at the toll booth form a queue, so our toll booth will need the functionality (queue, dequeue, isEmpty, etc.) of a queue.  We could implement our toll booth by inheriting this functionality from a Queue class as such:&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth extends Queue{&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Obviously, a tollbooth is not a queue, but more appropriately, has a queue.  Hence, our toll booth class should be created to contain a queue to model the line of cars.&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth&lt;br /&gt;
      private Queue&amp;lt;Vehicles&amp;gt;&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Our TollBooth class now has the functionality it needs without the inherent liabilities of extending the Queue class.&lt;br /&gt;
&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  Because it has many responsibilities, it would be difficult to reuse in a future project.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
An example of class approaching '''The Blob''' that may be familiar to many students this semester is the [http://wikis.lib.ncsu.edu/index.php/Expertiza  Expertiza] Project's assignment model.&amp;lt;ref name=&amp;quot;expertiza&amp;quot; /&amp;gt;  The assignment model in Expertiza does not encapsulate the majority of functionality in the entire application, but it is out of proportion with most of the other classes, and it does include functionality that should be in some other classes.&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;  One of the Open-Source Software projects for this semester is to correct some of these problems.  The project assignment contains the following notes:&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;[The assignment model] contains functionality for adding and removing participants for this assignment, which should really be in a participant class, for assigning reviewers, which should probably be in a reviewer class, and for computing the maximum score possible on a questionnaire.  Functions like compute_scores, and candidate_topics_to_review, among others, should be moved to other classes.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These notes describe some of the excessive functionality of assignment.rb.  It also suggests some other classes that would be more appropriate locations for some functionalities.  If these modifications are made, then the assignment model will be of a more manageable size, and will not be in danger of becoming '''The Blob'''.  &lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  &lt;br /&gt;
&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for a new problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  This can occur if the developers are simply comfortable with or used to an existing approach, or even the result of narrow-mindedness or hubris.   It can also be the direct result of reliance on proprietary technologies or products, or a deliberate effort to try to build a previous projects' success into a new program.  A '''Golden Hammer''' will typically manifest itself with poor performance or scalability.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
==Conclusions==&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
For additional information regarding antipatterns, check out the following resources.&lt;br /&gt;
&lt;br /&gt;
===Books===&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/exec/obidos/ISBN=0471197130/portlandpatternrA/ ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''.] Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, (ed) (1998).&lt;br /&gt;
&lt;br /&gt;
* [http://sourcemaking.com/antipatterns-book ''AntiPatterns: The Survival Guide'']&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612  ''Design Patterns: Elements of Reusable Object-Oriented Software''] by Erich Gamma, Richard Helm], Ralph Johnson, and John Vlissides(the Gang Of Four)&lt;br /&gt;
&lt;br /&gt;
===Websites===&lt;br /&gt;
&lt;br /&gt;
* [http://c2.com/cgi/wiki?AntiPatternsCatalog AntiPatterns Catalog]&lt;br /&gt;
&lt;br /&gt;
* [http://www.antipatterns.com/ AntiPatterns.com] Web site for the ''AntiPatterns'' book&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Category:Anti-patterns Wikipedia Anitpatterns Category]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; [http://sourcemaking.com/antipatterns/the-blob http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; [http://en.wikipedia.org/wiki/Golden_hammer http://en.wikipedia.org/wiki/Golden_hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; [http://sourcemaking.com/antipatterns/golden-hammer http://sourcemaking.com/antipatterns/golden-hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = expertiza&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza - Reusable learning objects through peer review] &amp;lt;/ref&amp;gt; &lt;br /&gt;
&amp;lt;ref name = fall2011_oss&amp;gt; [https://docs.google.com/a/ncsu.edu/document/d/1zZ-a_tkLGrbYJbG-2QBCRqe_Y9XLR4AZMH0rc6KvrYU/edit?hl=en_US CSC/ECE517 Fall 2011 OSS Projects in Expertiza] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56336</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56336"/>
		<updated>2011-11-29T23:06:43Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the GoF&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
Similar to the Call Super antipattern is the BaseBean antipattern.  It is found in object-oriented programming when a concrete domain class is formed using inheritance from a utility class.  This relationship is used simply to inherit utility methods from the utility class.  This is sometimes referred to as inheritance for implementation.&lt;br /&gt;
&lt;br /&gt;
Inheritance for the sake of gaining the functionality in the parent class is not good style.  This obviously is not an &amp;quot;is-a&amp;quot; a relationship and may violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle]. By inheriting from the utility class, the domain class becomes dependent on the internals of the utility class.  This can make the system difficult to maintain.  Additionally, the domain class now has all the functionality of the utility class - some of which it might not need.  This blurs the concept of the domain class and may cause it to have more than a single responsibility.&lt;br /&gt;
&lt;br /&gt;
In good object-oriented programming, objects should be representative of the real-world entities they exemplify and should relate to each other as such.  In this scenario a &amp;quot;has-a&amp;quot; relationship would be more appropriate.  The inherited functionality can be obtained using delegation instead of inheritance.  By using the [http://en.wikipedia.org/wiki/Composition_over_inheritance composition over inheritance] principle, we can avoid the BaseBean antipattern.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we want to create a class that emulates a toll booth.  The cars at the toll booth form a queue, so our toll booth will need the functionality (queue, dequeue, isEmpty, etc.) of a queue.  We could implement our toll booth by inheriting this functionality from a Queue class as such:&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth extends Queue{&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Obviously, a tollbooth is not a queue, but more appropriately, has a queue.  Hence, our toll booth class should be created to contain a queue to model the line of cars.&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth&lt;br /&gt;
      private Queue&amp;lt;Vehicles&amp;gt;&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Our TollBooth class now has the functionality it needs without the inherent liabilities of extending the Queue class.&lt;br /&gt;
&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  Because it has many responsibilities, it would be difficult to reuse in a future project.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
An example of class approaching '''The Blob''' that may be familiar to many students this semester is the [http://wikis.lib.ncsu.edu/index.php/Expertiza  Expertiza] Project's assignment model.&amp;lt;ref name=&amp;quot;expertiza&amp;quot; /&amp;gt;  The assignment model in Expertiza does not encapsulate the majority of functionality in the entire application, but it is out of proportion with most of the other classes, and it does include functionality that should be in some other classes.&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;  One of the Open-Source Software projects for this semester is to correct some of these problems.  The project assignment contains the following notes:&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;[The assignment model] contains functionality for adding and removing participants for this assignment, which should really be in a participant class, for assigning reviewers, which should probably be in a reviewer class, and for computing the maximum score possible on a questionnaire.  Functions like compute_scores, and candidate_topics_to_review, among others, should be moved to other classes.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These notes describe some of the excessive functionality of assignment.rb.  It also suggests some other classes that would be more appropriate locations for some functionalities.  If these modifications are made, then the assignment model will be of a more manageable size, and will not be in danger of becoming '''The Blob'''.  &lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  &lt;br /&gt;
&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for a new problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  This can occur if the developers are simply comfortable with or used to an existing approach, or even the result of narrow-mindedness or hubris.   It can also be the direct result of reliance on proprietary technologies or products, or a deliberate effort to try to build a previous projects' success into a new program.  A '''Golden Hammer''' will typically manifest itself with poor performance or scalability.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
==Conclusions==&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
For additional information regarding antipatterns, check out the following resources.&lt;br /&gt;
&lt;br /&gt;
===Books===&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/exec/obidos/ISBN=0471197130/portlandpatternrA/ ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''.] Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, (ed) (1998).&lt;br /&gt;
&lt;br /&gt;
* [http://sourcemaking.com/antipatterns-book ''AntiPatterns: The Survival Guide'']&lt;br /&gt;
&lt;br /&gt;
* [http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612  ''Design Patterns: Elements of Reusable Object-Oriented Software''] by Erich Gamma, Richard Helm], Ralph Johnson, and John Vlissides(the Gang Of Four)&lt;br /&gt;
&lt;br /&gt;
===Websites===&lt;br /&gt;
&lt;br /&gt;
* [http://c2.com/cgi/wiki?AntiPatternsCatalog AntiPatterns Catalog]&lt;br /&gt;
&lt;br /&gt;
* [http://www.antipatterns.com/ AntiPatterns.com] Web site for the ''AntiPatterns'' book&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Category:Anti-patterns Wikipedia Anitpatterns Category]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; [http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; http://en.wikipedia.org/wiki/Golden_hammer [http://en.wikipedia.org/wiki/Golden_hammer] ''Golden Hammer''&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; http://sourcemaking.com/antipatterns/golden-hammer [http://sourcemaking.com/antipatterns/golden-hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = expertiza&amp;gt; Expertiza - Reusable learning objects through peer review [http://wikis.lib.ncsu.edu/index.php/Expertiza] &amp;lt;/ref&amp;gt; &lt;br /&gt;
&amp;lt;ref name = fall2011_oss&amp;gt; CSC/ECE517 Fall 2011 OSS Projects in Expertiza [https://docs.google.com/a/ncsu.edu/document/d/1zZ-a_tkLGrbYJbG-2QBCRqe_Y9XLR4AZMH0rc6KvrYU/edit?hl=en_US] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56329</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56329"/>
		<updated>2011-11-29T21:43:47Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the GoF&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
Similar to the Call Super antipattern is the BaseBean antipattern.  It is found in object-oriented programming when a concrete domain class is formed using inheritance from a utility class.  This relationship is used simply to inherit utility methods from the utility class.  This is sometimes referred to as inheritance for implementation.&lt;br /&gt;
&lt;br /&gt;
Inheritance for the sake of gaining the functionality in the parent class is not good style.  This obviously is not an &amp;quot;is-a&amp;quot; a relationship and may violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle]. By inheriting from the utility class, the domain class becomes dependent on the internals of the utility class.  This can make the system difficult to maintain.  Additionally, the domain class now has all the functionality of the utility class - some of which it might not need.  This blurs the concept of the domain class and may cause it to have more than a single responsibility.&lt;br /&gt;
&lt;br /&gt;
In good object-oriented programming, objects should be representative of the real-world entities they exemplify and should relate to each other as such.  In this scenario a &amp;quot;has-a&amp;quot; relationship would be more appropriate.  The inherited functionality can be obtained using delegation instead of inheritance.  By using the [http://en.wikipedia.org/wiki/Composition_over_inheritance composition over inheritance] principle, we can avoid the BaseBean antipattern.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we want to create a class that emulates a toll booth.  The cars at the toll booth form a queue, so our toll booth will need the functionality (queue, dequeue, isEmpty, etc.) of a queue.  We could implement our toll booth by inheriting this functionality from a Queue class as such:&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth extends Queue{&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Obviously, a tollbooth is not a queue, but more appropriately, has a queue.  Hence, our toll booth class should be created to contain a queue to model the line of cars.&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth&lt;br /&gt;
      private Queue&amp;lt;Vehicles&amp;gt;&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Our TollBooth class now has the functionality it needs without the inherent liabilities of extending the Queue class.&lt;br /&gt;
&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
An example of class approaching '''The Blob''' status that may be familiar to many students this semester is the [http://wikis.lib.ncsu.edu/index.php/Expertiza  Expertiza] Project's assignment model.&amp;lt;ref name=&amp;quot;expertiza&amp;quot; /&amp;gt;  The assignment model in Expertiza does not encapsulate the majority of functionality in the entire application, but it is out of proportion with most of the other classes, and it does include functionality that should be in some other classes.&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;  One of the Open-Source Software projects for this semester is to correct some of these problems.  The project assignment contains the following notes:&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;It contains functionality for adding and removing participants for this assignment, which should really be in a participant class, for assigning reviewers, which should probably be in a reviewer class, and for computing the maximum score possible on a questionnaire.  Functions like compute_scores, and candidate_topics_to_review, among others, should be moved to other classes.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These notes describe some of the excessive functionality of assignment.rb.  It also suggests some other classes that would be more appropriate locations for some functionalities.  If these modifications are made, then the assignment model will not be in danger of becoming '''The Blob'''.  &lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  &lt;br /&gt;
&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for a new problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  This can occur if the developers are simply comfortable with or used to an existing approach, or even the result of narrow-mindedness or hubris.   It can also be the direct result of reliance on proprietary technologies or products, or a deliberate effort to try to build a previous projects' success into a new program.  A '''Golden Hammer''' will typically manifest itself with poor performance or scalability.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
==Conclusions==&lt;br /&gt;
==Resources==&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; [http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; http://en.wikipedia.org/wiki/Golden_hammer [http://en.wikipedia.org/wiki/Golden_hammer] ''Golden Hammer''&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; http://sourcemaking.com/antipatterns/golden-hammer [http://sourcemaking.com/antipatterns/golden-hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = expertiza&amp;gt; Expertiza - Reusable learning objects through peer review [http://wikis.lib.ncsu.edu/index.php/Expertiza] &amp;lt;/ref&amp;gt; &lt;br /&gt;
&amp;lt;ref name = fall2011_oss&amp;gt; CSC/ECE517 Fall 2011 OSS Projects in Expertiza [https://docs.google.com/a/ncsu.edu/document/d/1zZ-a_tkLGrbYJbG-2QBCRqe_Y9XLR4AZMH0rc6KvrYU/edit?hl=en_US] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56324</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56324"/>
		<updated>2011-11-29T18:20:44Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the GoF&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
Similar to the Call Super antipattern is the BaseBean antipattern.  It is found in object-oriented programming when a concrete domain class is formed using inheritance from a utility class.  This relationship is used simply to inherit utility methods from the utility class.  This is sometimes referred to as inheritance for implementation.&lt;br /&gt;
&lt;br /&gt;
Inheritance for the sake of gaining the functionality in the parent class is not good style.  This obviously is not an &amp;quot;is-a&amp;quot; a relationship and may violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle]. By inheriting from the utility class, the domain class becomes dependent on the internals of the utility class.  This can make the system difficult to maintain.  Additionally, the domain class now has all the functionality of the utility class - some of which it might not need.  This blurs the concept of the domain class and may cause it to have more than a single responsibility.&lt;br /&gt;
&lt;br /&gt;
In good object-oriented programming, objects should be representative of the real-world entities they exemplify and should relate to each other as such.  In this scenario a &amp;quot;has-a&amp;quot; relationship would be more appropriate.  The inherited functionality can be obtained using delegation instead of inheritance.  By using the [http://en.wikipedia.org/wiki/Composition_over_inheritance composition over inheritance] principle, we can avoid the BaseBean antipattern.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we want to create a class that emulates a toll booth.  The cars at the toll booth form a queue, so our toll booth will need the functionality (queue, dequeue, isEmpty, etc.) of a queue.  We could implement our toll booth by inheriting this functionality from a Queue class as such:&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth extends Queue{&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Obviously, a tollbooth is not a queue, but more appropriately, has a queue.  Hence, our toll booth class should be created to contain a queue to model the line of cars.&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth&lt;br /&gt;
      private Queue&amp;lt;Vehicles&amp;gt;&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Our TollBooth class now has the functionality it needs without the inherent liabilities of extending the Queue class.&lt;br /&gt;
&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
An example of class approaching '''The Blob''' status that may be familiar to many students this semester is the [http://wikis.lib.ncsu.edu/index.php/Expertiza  Expertiza Project]'s assignment controller.&amp;lt;ref name=&amp;quot;expertiza&amp;quot; /&amp;gt;  The assignment controller in Expertiza does not encapsulate the majority of functionality in the entire application, but it is out of proportion with most of the other classes, and it does include functionality that should be in some other classes.&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;  The project assignment contains the following notes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;It contains functionality for adding and removing participants for this assignment, which should really be in a participant class, for assigning reviewers, which should probably be in a reviewer class, and for computing the maximum score possible on a questionnaire.  Functions like compute_scores, and candidate_topics_to_review, among others, should be moved to other classes.&amp;lt;/blockquote&amp;gt;&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  &lt;br /&gt;
&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for a new problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  This can occur if the developers are simply comfortable with or used to an existing approach, or even the result of narrow-mindedness or hubris.   It can also be the direct result of reliance on proprietary technologies or products, or a deliberate effort to try to build a previous projects' success into a new program.  A '''Golden Hammer''' will typically manifest itself with poor performance or scalability.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
==Conclusions==&lt;br /&gt;
==Resources==&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; [http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; http://en.wikipedia.org/wiki/Golden_hammer [http://en.wikipedia.org/wiki/Golden_hammer] ''Golden Hammer''&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; http://sourcemaking.com/antipatterns/golden-hammer [http://sourcemaking.com/antipatterns/golden-hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = expertiza&amp;gt; Expertiza - Reusable learning objects through peer review [http://wikis.lib.ncsu.edu/index.php/Expertiza] &amp;lt;/ref&amp;gt; &lt;br /&gt;
&amp;lt;ref name = fall2011_oss&amp;gt; CSC/ECE517 Fall 2011 OSS Projects in Expertiza [https://docs.google.com/a/ncsu.edu/document/d/1zZ-a_tkLGrbYJbG-2QBCRqe_Y9XLR4AZMH0rc6KvrYU/edit?hl=en_US] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56323</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56323"/>
		<updated>2011-11-29T18:19:21Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the GoF&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
Similar to the Call Super antipattern is the BaseBean antipattern.  It is found in object-oriented programming when a concrete domain class is formed using inheritance from a utility class.  This relationship is used simply to inherit utility methods from the utility class.  This is sometimes referred to as inheritance for implementation.&lt;br /&gt;
&lt;br /&gt;
Inheritance for the sake of gaining the functionality in the parent class is not good style.  This obviously is not an &amp;quot;is-a&amp;quot; a relationship and may violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle]. By inheriting from the utility class, the domain class becomes dependent on the internals of the utility class.  This can make the system difficult to maintain.  Additionally, the domain class now has all the functionality of the utility class - some of which it might not need.  This blurs the concept of the domain class and may cause it to have more than a single responsibility.&lt;br /&gt;
&lt;br /&gt;
In good object-oriented programming, objects should be representative of the real-world entities they exemplify and should relate to each other as such.  In this scenario a &amp;quot;has-a&amp;quot; relationship would be more appropriate.  The inherited functionality can be obtained using delegation instead of inheritance.  By using the [http://en.wikipedia.org/wiki/Composition_over_inheritance composition over inheritance] principle, we can avoid the BaseBean antipattern.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we want to create a class that emulates a toll booth.  The cars at the toll booth form a queue, so our toll booth will need the functionality (queue, dequeue, isEmpty, etc.) of a queue.  We could implement our toll booth by inheriting this functionality from a Queue class as such:&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth extends Queue{&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Obviously, a tollbooth is not a queue, but more appropriately, has a queue.  Hence, our toll booth class should be created to contain a queue to model the line of cars.&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth&lt;br /&gt;
      private Queue&amp;lt;Vehicles&amp;gt;&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Our TollBooth class now has the functionality it needs without the inherent liabilities of extending the Queue class.&lt;br /&gt;
&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
An example of class approaching '''The Blob''' status that may be familiar to many students this semester is the [http://wikis.lib.ncsu.edu/index.php/Expertiza  Expertiza Project]'s assignment controller.&amp;lt;ref name=&amp;quot;expertiza&amp;quot; /&amp;gt;  The assignment controller in Expertiza does not encapsulate the majority of functionality in the entire application, but it is out of proportion with most of the other classes, and it does include functionality that should be in some other classes.&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;  The project assignment contains the following notes:&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;It contains functionality for adding and removing participants for this assignment, which should really be in a participant class, for assigning reviewers, which should probably be in a reviewer class, and for computing the maximum score possible on a questionnaire.  Functions like compute_scores, and candidate_topics_to_review, among others, should be moved to other classes.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  &lt;br /&gt;
&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for a new problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  This can occur if the developers are simply comfortable with or used to an existing approach, or even the result of narrow-mindedness or hubris.   It can also be the direct result of reliance on proprietary technologies or products, or a deliberate effort to try to build a previous projects' success into a new program.  A '''Golden Hammer''' will typically manifest itself with poor performance or scalability.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
==Conclusions==&lt;br /&gt;
==Resources==&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; http://sourcemaking.com/antipatterns/the-blob [http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; http://en.wikipedia.org/wiki/Golden_hammer [http://en.wikipedia.org/wiki/Golden_hammer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; http://sourcemaking.com/antipatterns/golden-hammer [http://sourcemaking.com/antipatterns/golden-hammer] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = expertiza&amp;gt; Expertiza - Reusable learning objects through peer review [http://wikis.lib.ncsu.edu/index.php/Expertiza] &amp;lt;/ref&amp;gt; &lt;br /&gt;
&amp;lt;ref name = fall2011_oss&amp;gt; CSC/ECE517 Fall 2011 OSS Projects in Expertiza [https://docs.google.com/a/ncsu.edu/document/d/1zZ-a_tkLGrbYJbG-2QBCRqe_Y9XLR4AZMH0rc6KvrYU/edit?hl=en_US] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56322</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56322"/>
		<updated>2011-11-29T18:18:18Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the GoF&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
Similar to the Call Super antipattern is the BaseBean antipattern.  It is found in object-oriented programming when a concrete domain class is formed using inheritance from a utility class.  This relationship is used simply to inherit utility methods from the utility class.  This is sometimes referred to as inheritance for implementation.&lt;br /&gt;
&lt;br /&gt;
Inheritance for the sake of gaining the functionality in the parent class is not good style.  This obviously is not an &amp;quot;is-a&amp;quot; a relationship and may violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle]. By inheriting from the utility class, the domain class becomes dependent on the internals of the utility class.  This can make the system difficult to maintain.  Additionally, the domain class now has all the functionality of the utility class - some of which it might not need.  This blurs the concept of the domain class and may cause it to have more than a single responsibility.&lt;br /&gt;
&lt;br /&gt;
In good object-oriented programming, objects should be representative of the real-world entities they exemplify and should relate to each other as such.  In this scenario a &amp;quot;has-a&amp;quot; relationship would be more appropriate.  The inherited functionality can be obtained using delegation instead of inheritance.  By using the [http://en.wikipedia.org/wiki/Composition_over_inheritance composition over inheritance] principle, we can avoid the BaseBean antipattern.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we want to create a class that emulates a toll booth.  The cars at the toll booth form a queue, so our toll booth will need the functionality (queue, dequeue, isEmpty, etc.) of a queue.  We could implement our toll booth by inheriting this functionality from a Queue class as such:&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth extends Queue{&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Obviously, a tollbooth is not a queue, but more appropriately, has a queue.  Hence, our toll booth class should be created to contain a queue to model the line of cars.&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth&lt;br /&gt;
      private Queue&amp;lt;Vehicles&amp;gt;&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Our TollBooth class now has the functionality it needs without the inherent liabilities of extending the Queue class.&lt;br /&gt;
&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
An example of class approaching '''The Blob''' status that may be familiar to many students this semester is the [http://wikis.lib.ncsu.edu/index.php/Expertiza  Expertiza Project]'s assignment controller.&amp;lt;ref name=&amp;quot;expertiza&amp;quot; /&amp;gt;  The assignment controller in Expertiza does not encapsulate the majority of functionality in the entire application, but it is out of proportion with most of the other classes, and it does include functionality that should be in some other classes.&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;  The project assignment contains the following notes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;It contains functionality for adding and removing participants for this assignment, which should really be in a participant class, for assigning reviewers, which should probably be in a reviewer class, and for computing the maximum score possible on a questionnaire.  Functions like compute_scores, and candidate_topics_to_review, among others, should be moved to other classes.&amp;lt;/blockquote&amp;gt;&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  &lt;br /&gt;
&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for a new problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  This can occur if the developers are simply comfortable with or used to an existing approach, or even the result of narrow-mindedness or hubris.   It can also be the direct result of reliance on proprietary technologies or products, or a deliberate effort to try to build a previous projects' success into a new program.  A '''Golden Hammer''' will typically manifest itself with poor performance or scalability.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
==Conclusions==&lt;br /&gt;
==Resources==&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; http://sourcemaking.com/antipatterns/the-blob [http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; http://en.wikipedia.org/wiki/Golden_hammer [http://en.wikipedia.org/wiki/Golden_hammer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; http://sourcemaking.com/antipatterns/golden-hammer [http://sourcemaking.com/antipatterns/golden-hammer] &lt;br /&gt;
&amp;lt;ref name = expertiza&amp;gt; Expertiza - Reusable learning objects through peer review [http://wikis.lib.ncsu.edu/index.php/Expertiza] &amp;lt;/ref&amp;gt; &lt;br /&gt;
&amp;lt;ref name = fall2011_oss&amp;gt; CSC/ECE517 Fall 2011 OSS Projects in Expertiza [https://docs.google.com/a/ncsu.edu/document/d/1zZ-a_tkLGrbYJbG-2QBCRqe_Y9XLR4AZMH0rc6KvrYU/edit?hl=en_US] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56321</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56321"/>
		<updated>2011-11-29T18:15:46Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the GoF&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
Similar to the Call Super antipattern is the BaseBean antipattern.  It is found in object-oriented programming when a concrete domain class is formed using inheritance from a utility class.  This relationship is used simply to inherit utility methods from the utility class.  This is sometimes referred to as inheritance for implementation.&lt;br /&gt;
&lt;br /&gt;
Inheritance for the sake of gaining the functionality in the parent class is not good style.  This obviously is not an &amp;quot;is-a&amp;quot; a relationship and may violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle]. By inheriting from the utility class, the domain class becomes dependent on the internals of the utility class.  This can make the system difficult to maintain.  Additionally, the domain class now has all the functionality of the utility class - some of which it might not need.  This blurs the concept of the domain class and may cause it to have more than a single responsibility.&lt;br /&gt;
&lt;br /&gt;
In good object-oriented programming, objects should be representative of the real-world entities they exemplify and should relate to each other as such.  In this scenario a &amp;quot;has-a&amp;quot; relationship would be more appropriate.  The inherited functionality can be obtained using delegation instead of inheritance.  By using the [http://en.wikipedia.org/wiki/Composition_over_inheritance composition over inheritance] principle, we can avoid the BaseBean antipattern.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we want to create a class that emulates a toll booth.  The cars at the toll booth form a queue, so our toll booth will need the functionality (queue, dequeue, isEmpty, etc.) of a queue.  We could implement our toll booth by inheriting this functionality from a Queue class as such:&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth extends Queue{&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Obviously, a tollbooth is not a queue, but more appropriately, has a queue.  Hence, our toll booth class should be created to contain a queue to model the line of cars.&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth&lt;br /&gt;
      private Queue&amp;lt;Vehicles&amp;gt;&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Our TollBooth class now has the functionality it needs without the inherent liabilities of extending the Queue class.&lt;br /&gt;
&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
An example of class approaching '''The Blob''' status that may be familiar to many students this semester is the [http://wikis.lib.ncsu.edu/index.php/Expertiza  Expertiza Project]'s assignment controller.&amp;lt;ref name=&amp;quot;expertiza&amp;quot; /&amp;gt;  The assignment controller in Expertiza does not encapsulate the majority of functionality in the entire application, but it is out of proportion with most of the other classes, and it does include functionality that should be in some other classes.&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;  The project assignment contains the following notes:&lt;br /&gt;
&lt;br /&gt;
  It contains functionality for adding and removing participants for this assignment, which should really be in a participant class, for assigning reviewers, which should probably be in a reviewer class, and for computing the maximum score possible on a questionnaire.  Functions like compute_scores, and candidate_topics_to_review, among others, should be moved to other classes.&amp;lt;ref name=&amp;quot;fall2011_oss&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  &lt;br /&gt;
&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for a new problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  This can occur if the developers are simply comfortable with or used to an existing approach, or even the result of narrow-mindedness or hubris.   It can also be the direct result of reliance on proprietary technologies or products, or a deliberate effort to try to build a previous projects' success into a new program.  A '''Golden Hammer''' will typically manifest itself with poor performance or scalability.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
==Conclusions==&lt;br /&gt;
==Resources==&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; http://sourcemaking.com/antipatterns/the-blob [http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; http://en.wikipedia.org/wiki/Golden_hammer [http://en.wikipedia.org/wiki/Golden_hammer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; http://sourcemaking.com/antipatterns/golden-hammer [http://sourcemaking.com/antipatterns/golden-hammer] &lt;br /&gt;
&amp;lt;ref name = expertiza&amp;gt; Expertiza - Reusable learning objects through peer review [http://wikis.lib.ncsu.edu/index.php/Expertiza] &amp;lt;/ref&amp;gt; &lt;br /&gt;
&amp;lt;ref name = fall2011_oss&amp;gt; CSC/ECE517 Fall 2011 OSS Projects in Expertiza [https://docs.google.com/a/ncsu.edu/document/d/1zZ-a_tkLGrbYJbG-2QBCRqe_Y9XLR4AZMH0rc6KvrYU/edit?hl=en_US] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56320</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56320"/>
		<updated>2011-11-29T18:02:34Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the GoF&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
Similar to the Call Super antipattern is the BaseBean antipattern.  It is found in object-oriented programming when a concrete domain class is formed using inheritance from a utility class.  This relationship is used simply to inherit utility methods from the utility class.  This is sometimes referred to as inheritance for implementation.&lt;br /&gt;
&lt;br /&gt;
Inheritance for the sake of gaining the functionality in the parent class is not good style.  This obviously is not an &amp;quot;is-a&amp;quot; a relationship and may violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle]. By inheriting from the utility class, the domain class becomes dependent on the internals of the utility class.  This can make the system difficult to maintain.  Additionally, the domain class now has all the functionality of the utility class - some of which it might not need.  This blurs the concept of the domain class and may cause it to have more than a single responsibility.&lt;br /&gt;
&lt;br /&gt;
In good object-oriented programming, objects should be representative of the real-world entities they exemplify and should relate to each other as such.  In this scenario a &amp;quot;has-a&amp;quot; relationship would be more appropriate.  The inherited functionality can be obtained using delegation instead of inheritance.  By using the [http://en.wikipedia.org/wiki/Composition_over_inheritance composition over inheritance] principle, we can avoid the BaseBean antipattern.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we want to create a class that emulates a toll booth.  The cars at the toll booth form a queue, so our toll booth will need the functionality (queue, dequeue, isEmpty, etc.) of a queue.  We could implement our toll booth by inheriting this functionality from a Queue class as such:&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth extends Queue{&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Obviously, a tollbooth is not a queue, but more appropriately, has a queue.  Hence, our toll booth class should be created to contain a queue to model the line of cars.&lt;br /&gt;
&lt;br /&gt;
   public class TollBooth&lt;br /&gt;
      private Queue&amp;lt;Vehicles&amp;gt;&lt;br /&gt;
      /*additional methods and properties for toll booth such as&lt;br /&gt;
        toll booth operator, token processor, cross arm, change processor, etc. */&lt;br /&gt;
&lt;br /&gt;
Our TollBooth class now has the functionality it needs without the inherent liabilities of extending the Queue class.&lt;br /&gt;
&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
An example of class approaching '''The Blob''' status that may be familiar to many students this semester is the [http://wikis.lib.ncsu.edu/index.php/Expertiza  Expertiza Project]'s assignment controller.  The assignment controller in Expertiza does not encapsulate the majority of functionality in the entire application, but it is out of proportion with most of the other classes, and it does include functionality that should be &lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  &lt;br /&gt;
&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for a new problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  This can occur if the developers are simply comfortable with or used to an existing approach, or even the result of narrow-mindedness or hubris.   It can also be the direct result of reliance on proprietary technologies or products, or a deliberate effort to try to build a previous projects' success into a new program.  A '''Golden Hammer''' will typically manifest itself with poor performance or scalability.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
==Conclusions==&lt;br /&gt;
==Resources==&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; http://sourcemaking.com/antipatterns/the-blob [http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; http://en.wikipedia.org/wiki/Golden_hammer [http://en.wikipedia.org/wiki/Golden_hammer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; http://sourcemaking.com/antipatterns/golden-hammer [http://sourcemaking.com/antipatterns/golden-hammer] &lt;br /&gt;
&amp;lt;ref name = expertiza&amp;gt; Expertiza - Reusable learning objects through peer review [http://wikis.lib.ncsu.edu/index.php/Expertiza] &amp;lt;/ref&amp;gt; &lt;br /&gt;
&amp;lt;ref name = fall2011_fp&amp;gt; CSC/ECE517 Fall 2011 Final Projects in Expertiza [https://docs.google.com/a/ncsu.edu/document/d/1LDWHpdIaaQ37NwHfOuSq-baqCr5SvQgaouSPeVM7qNA/edit?authkey=CMusubYH] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56305</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56305"/>
		<updated>2011-11-28T21:36:38Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the GoF&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===Base Beans===&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  &lt;br /&gt;
&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for a new problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  This can occur if the developers are simply comfortable with or used to an existing approach, or even the result of narrow-mindedness or hubris.   It can also be the direct result of reliance on proprietary technologies or products, or a deliberate effort to try to build a previous projects' success into a new program.  A '''Golden Hammer''' will typically manifest itself with poor performance or scalability.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
==Conclusions==&lt;br /&gt;
==Resources==&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; [http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; [http://en.wikipedia.org/wiki/Golden_hammer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; [http://sourcemaking.com/antipatterns/golden-hammer] &lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56304</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56304"/>
		<updated>2011-11-28T21:25:47Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the GoF&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===Base Beans===&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design AntiPattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Many software engineering projects solve problems or use techniques that programmers are strongly familiar with.  Programmers often reuse strategies, algorithms, or entire sections of code that they or another programmer has applied to a different project in the past.  Reuse in this manner can save development time and cost, but only when reused code is appropriate for the new application.  The '''Golden Hammer''' design anti-pattern results from reusing a familiar solution that is a poor match for the problem.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;  &lt;br /&gt;
==Conclusions==&lt;br /&gt;
==Resources==&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; [http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; [http://en.wikipedia.org/wiki/Golden_hammer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; [http://sourcemaking.com/antipatterns/golden-hammer] &lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56303</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56303"/>
		<updated>2011-11-28T21:15:13Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the GoF&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===Base Beans===&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking_tb /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
==Conclusions==&lt;br /&gt;
==Resources==&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; [http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; [http://en.wikipedia.org/wiki/Golden_hammer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; [http://sourcemaking.com/antipatterns/golden-hammer] &lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56302</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56302"/>
		<updated>2011-11-28T21:14:14Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the GoF&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===Base Beans===&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking_tb/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
The '''Golden Hammer''' design anti-pattern, also known as the '''Law of the instrument''', is an over-reliance on a familiar tool.&amp;lt;ref name=&amp;quot;wiki_gh&amp;quot; /&amp;gt;  It is one of the most common antipatterns seen in the industry.&amp;lt;ref name=&amp;quot;sourcemaking_gh&amp;quot; /&amp;gt;&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
==Conclusions==&lt;br /&gt;
==Resources==&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_tb&amp;gt; [http://sourcemaking.com/antipatterns/the-blob]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = wiki_gh&amp;gt; [http://en.wikipedia.org/wiki/Golden_hammer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking_gh&amp;gt; [http://sourcemaking.com/antipatterns/golden-hammer] &lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56301</id>
		<title>CSC/ECE 517 Fall 2011/ch7 7d rt</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch7_7d_rt&amp;diff=56301"/>
		<updated>2011-11-27T20:03:19Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;FONT size=5&amp;gt;AntiPatterns in Software Development&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
The term ''antipattern'' was coined by Andrew Koenig&amp;lt;ref name = koenig/&amp;gt;,  in 1995.  His inspiration was a story told about Thomas Edison's many failed attempts to find a suitable material for the filament of a light bulb.  When asked if he was discouraged, Edison replied that indeed he was not; he now knew hundreds of items that wouldn't work.&lt;br /&gt;
&lt;br /&gt;
Koenig believed that the same philosophy should be applied to software development.  As he studied the book ''Design Patterns'' presented by the GoF&amp;lt;ref name = gof/&amp;gt;, he felt that it was just as important to identify potential pitfalls as well as positive practices.  He named these non-solutions ''antipatterns''.  He defined an ''antipattern'' as &amp;quot;just like a pattern, except that instead of a solution it gives something that looks superficially like a solution but isn't one.&amp;quot; &amp;lt;ref name = koenig/&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
In 1998, a different group of four expanded on this idea publishing '''''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis'''''&amp;lt;ref name = ap/&amp;gt;.  The book identified antipatterns from three different viewpoints:  the software developer, the software architect and the software manager.  The authors used two criteria to distinguish antipatterns:&lt;br /&gt;
* It was a frequent occurrence, that initially seemed to be beneficial, but ultimately was not and&lt;br /&gt;
* There is a alternate, preferred solution that is proven and repeatable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through the years the concept of antipatterns has been further extended to apply to additional areas of software development as well as areas outside the realm of programming.  This article will address software development antipatterns.&lt;br /&gt;
&lt;br /&gt;
Just like patterns, antipatterns have certain elements.  They include:&lt;br /&gt;
# Name so that they can be identified.&lt;br /&gt;
# A description of why the bad solution might be attractive.&lt;br /&gt;
# An explanation of how that solution is bad long-term.&lt;br /&gt;
# Suggestions for other patterns that provide better solutions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several catalogs of antipatterns available as well as a number of books that address the topic.  Below we will explore a few of the more common antipatterns.&lt;br /&gt;
&lt;br /&gt;
==AntiPatterns==&lt;br /&gt;
===Call Super===&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
We are all familiar with the concept of inheritance in object-oriented programming where a subclass takes on the properties and actions of a superclass.  The subclass can then override the methods of the superclass either replacing or augmenting the functionality provided in the superclass.  The '''call super''' antipattern requires subclasses to override methods of the super class and then call back the overridden method at some point. This requirement may stem from the fact that the superclass does some set up operations that cannot be done in the subclass or if the subclass is expanding the superclass task rather than replacing it.&lt;br /&gt;
&lt;br /&gt;
Calling a superclass method from a subclass is not in general a bad practice, but '''requiring''' it to do so is. Imposing such a constraint can lead to several problems.  Future developers may forget to call the superclass causing untold bugs and system errors. Additionally, it requires anyone using the interface to have an understanding of the inner workings of the superclass.  Ideally, they would only need to understand the public interface.  Finally, if the superclass expects specific actions from the subclass, it may not perform well (or at all) if those actions aren't performed as expected.&lt;br /&gt;
&lt;br /&gt;
A better approach to obtaining the desired functionality would be to use the [http://en.wikipedia.org/wiki/Template_method_pattern  Template Method] pattern.  Here the superclass would include a public method and define a separate method (often called a hook method) for the subclass to override.  The superclass method would then call the hook method.  The hook method can either be an abstract method in the superclass and fully implemented in the subclass, or have some basic functionality in the superclass and augmented in the superclass.  Either way the subclass does not have to worry about calling the superclass.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
Let's say we have a class registration framework with an EventHandler superclass. The EventHandler is used to process all &amp;quot;transactions&amp;quot;  - administrators adding classes, students registering for classes, students dropping classes, etc.  It has to do some basic setup and housekeeping functions (checking availability, permissions, etc.) before the registration event can be processed. Our original code for a student registering for a class might be something like the following.&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler...&lt;br /&gt;
    public void handle(RegistrationEvent e) {&lt;br /&gt;
      super.handle(e);&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The method StudentClassRegistrationHandler must call super.handle() before it can begin its task of registering the student. If we refactor this code using the Template Method pattern, we could get the following code:&lt;br /&gt;
&lt;br /&gt;
  public class EventHandler ...&lt;br /&gt;
    public void handle (RegistrationEvent e) {&lt;br /&gt;
      setup(e);&lt;br /&gt;
      doAction(e);&lt;br /&gt;
    }&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
  public class StudentClassRegistrationHandler extends EventHandler ...&lt;br /&gt;
    protected void doAction(RegistrationEvent e) {&lt;br /&gt;
      RegisterStudent(e);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The subclass is now only responsible for its own functionality.  This arrangement also allows the superclass to call some follow-up or clean-up methods after the subclass method if necessary.&lt;br /&gt;
&lt;br /&gt;
===Base Beans===&lt;br /&gt;
===The Blob===&lt;br /&gt;
====Description====&lt;br /&gt;
'''The Blob''', also called a '''God Class''', is a development antipattern that results when one single class has too many attributes, operations, or both.&amp;lt;ref name =  sourcemaking/&amp;gt;   '''The Blob''' is usually an indicator of poor object-oriented design, or a poorly-migrated legacy program.&amp;lt;ref name = ap/&amp;gt;  It can often resemble a procedural 'main' program, and may even encapsulate most or all of the functionality of an application.  '''The Blob''' class violates the ''One Responsibility Rule'', which makes it unlikely to be reusable.  '''The Blob''' class may be expensive to load into memory, and wasteful if only part of the functionality is used.  It also will likely be difficult to effectively test.&amp;lt;ref name = ap/&amp;gt;   '''The Blob''' is typically caused by a lack of an object-oriented architecture.&amp;lt;ref name = ap/&amp;gt;  It can also be the result of an up-front object-oriented design that did not take into account a requirement, and developers choosing not to rearrange the class hierarchy after the initial design.  It can also be a ''Specified Disaster''; the result of requirements that specify a procedural solution.&amp;lt;ref name = ap/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution to '''The Blob''' is to refactor the code, with the goal of moving behavior away from the offending class.&amp;lt;ref name = sourcemaking /&amp;gt;  If '''The Blob''' encapsulates data in some other objects, then code manipulating that data should be moved to the other classes, in an effort to make the other classes more complex and '''The Blob''' less complex.  If possible, the developers should try to split '''The Blob''' into multiple classes with class minimal coupling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Golden Hammer===&lt;br /&gt;
====Description====&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
==Conclusions==&lt;br /&gt;
==Resources==&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name = koenig&amp;gt; Koenig, Andrew (March/April 1995). &amp;quot;Patterns and Antipatterns&amp;quot;. Journal of Object-Oriented Programming 8 (1): 46–48.; was later re-printed in the: Rising, Linda (1998). [http://books.google.com/?id=HBAuixGMYWEC&amp;amp;pg=PT1&amp;amp;dq=0-521-64818-1 The patterns handbook: techniques, strategies, and applications]. Cambridge, U.K.: Cambridge University Press. p. 387. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = gof&amp;gt; [http://en.wikipedia.org/wiki/Design_Patterns_%28book%29 Design Patterns]  by Gang of Four&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = ap&amp;gt; Brown, William J.; Raphael C. Malveau, Hays W. &amp;quot;Skip&amp;quot; McCormick, Thomas J. Mowbray, Theresa Hudson (ed) (1998). [http://www.antipatterns.com/AntiPatterns/Welcome.html ''AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis''. ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name = sourcemaking&amp;gt; [http://sourcemaking.com/antipatterns/the-blob]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54301</id>
		<title>CSC/ECE 517 Fall 2011/ch3 3h rr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54301"/>
		<updated>2011-10-29T22:01:34Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''3h. Primitive objects.  At the beginning of Lecture 11, we discovered that Fixnums and Bignums are handled differently behind the scenes in Ruby.  Other languages, like Java, have made similar distinctions.  By contrast, languages such as C# and Eiffel try to hide these implementation differences from users.  Answer two questions: (1) How have different o-o languages implemented primitive objects?  E.g., how are they represented in memory, how are they tested for, do comparisons do anything different than for class objects, etc.  (2) What are the advantages and disadvantages of treating primitives differently from class objects in source code?''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Programming languages, whether statically or dynamically typed, have support for certain in-built data types. These data types, known as primitive types, are the basic representation of information in programs and have certain fixed attributes for a specific language[http://en.wikipedia.org/wiki/Primitive_data_type]. Statically typed languages such as C++, Java, Perl etc. support primitive data types, whereas with dynamically typed languages such as Ruby, Smalltalk, Lisp etc. they are actually in the form of primitive objects.  These primitive types are used to store the basic types of information that a computer can store and manipulate, and can also be used as building blocks for creating more complex data types. &lt;br /&gt;
This article explains the way different primitive types are implemented in certain object oriented languages. An analysis of the benefits and drawbacks of such types and the methods used to operate on them is also presented. &lt;br /&gt;
&lt;br /&gt;
== Primitive Types ==&lt;br /&gt;
The primitive types commonly included in most programming languages are:&lt;br /&gt;
* Boolean&lt;br /&gt;
* Character&lt;br /&gt;
* Integer&lt;br /&gt;
* Floating-point number&lt;br /&gt;
* Fixed-point number&lt;br /&gt;
* Reference&lt;br /&gt;
&lt;br /&gt;
=== Boolean ===&lt;br /&gt;
A Boolean is a primitive data type used to store one of two logical types: true or false.  Boolean data types are most commonly used as input paramters to a conditional statement (such as an ‘if’ statement), or as the output of a comparison between two comparable data types.  Booleans can be implemented in languages as either a discrete logical type, or implicitly as a numerical type.  In many languages, booleans can be implicitly converted to and from integer types.  &lt;br /&gt;
&lt;br /&gt;
=== Character ===&lt;br /&gt;
A character is a data type that represents an element of a written language, such as a letter, number, or symbol.  A character can also represent a control character, such as a carriage return or newline, which does not have a written meaning but controls how other characters are stored or displayed.   Characters are commonly stored as integers, and encoded using a character map.  &lt;br /&gt;
&lt;br /&gt;
=== Integer ===&lt;br /&gt;
An integer is a data type that represents one element of a finite subset of mathematical integers.  Integer, or Integral, data types can be either unsigned (able to store only positive whole numbers) or signed (able to store either positive or negative whole numbers).  The range of values that can be represented by an integer depends on the number of bits used to store the integer, whether or not it is a signed integer, and the encoding scheme (if it is signed).  Typically, an integer has a minimum and maximum value, and can store any integer in the range between those values.  The minimum value for unsigned integers is typically 0, and the maximum value is typically determined by the amount of memory used to store the integer.  For example, a un unsigned 8-bit number can store 2^8 (or 256) possible integral values; and would typically store any value from 0 to 255.  More generally, an n-bit unsigned integer can store from 0 to (2^n)-1.  For signed integers, modern computers use the Two’s Complement encoding scheme.  This allows for a range of −2^(n−1) through 2^(n−1)−1.  For example, an 8-bit signed integer could store any whole number in the range from -128 through +127.&lt;br /&gt;
&lt;br /&gt;
=== Floating-Point Number ===&lt;br /&gt;
A floating point number is a data type used to represent real numbers in a large range with varying degrees of precision.  In this representation, numbers are represented with a variable number of significant digits, and a variable number of exponential digits.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed-Point number ===&lt;br /&gt;
A fixed-point number is a data type used to represent real numbers.  Fixed-point numbers are called fixed-point because they have a set number of digits before and after a decimal mark.  In this regard, fixed-point numbers are represented as an integer, but are scaled by a predetermined factor.  &lt;br /&gt;
&lt;br /&gt;
Fixed-point numbers are commonly used in microprocessors that do not have a floating-point unit, or in systems in which computational efficiency is critical.  Fixed-point numbers can be treated as integers by an arithmetic logic unit (ALU) and scaled after a result is obtained, which can significantly lower the amount of time needed for a processor to obtain the result for some algorithms. &lt;br /&gt;
&lt;br /&gt;
Implementing algorithms using fixed-point arithmetic requires great care, because of the potential for information loss.  Fixed-point arithmetic operations -- multiplication in particular, has the potential to cause overflow.  Algorithms must be written with care to ensure that each term of an equation has a similar range and that the result will not cause an overflow.&lt;br /&gt;
&lt;br /&gt;
=== Reference ===&lt;br /&gt;
&lt;br /&gt;
A Reference is a data type that enables a program to access another item in memory.  A reference differs from other primitive data types in that it does not store data itself; instead it stores a value referring to another data object.  References are commonly used to refer to objects of large non-primitive data types.  References commonly store the physical memory address of the data that they are referring to.  Accessing the data referred to by a Reference is called dereferencing.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C++ ==&lt;br /&gt;
&lt;br /&gt;
C++ is a statically-typed object oriented language.  C++ is based on the C programming language, which is procedural, and adds support for object-oriented code.  &lt;br /&gt;
&lt;br /&gt;
These data types are defined in C++: [http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php] &lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! Name &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| void &lt;br /&gt;
| N/A &lt;br /&gt;
| the void data type is used to explicitly identify that a data has no type &lt;br /&gt;
| N/A&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits&lt;br /&gt;
| simple numerical type&lt;br /&gt;
| See [[http://www.jk-technology.com/c/inttypes.html]]&lt;br /&gt;
|-&lt;br /&gt;
| float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 8 bits &lt;br /&gt;
| a char is a single 8-bit character encoded using ASCII &lt;br /&gt;
| Ascii character 0x00 through ascii character 0xFF&lt;br /&gt;
|}&lt;br /&gt;
C++ supports Pointers for all of the types listed in the table above, as well as more complex data types (such as structs).  A Pointer in C++ is a data type that stores the physical address of some other data.  Pointers are created in C++ by using the * operator.  For example, a *Double[] is a pointer to an array of double-precision floating point numbers.  C++ Also supports function pointers -- pointers that reference the beginning address of a function in memory.  They are commonly used to implement callback functions [http://newty.de/fpt/intro.html#what]&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in Java == &lt;br /&gt;
&lt;br /&gt;
Java is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  These data types are defined in Java: [http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html]&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;|Name&lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte&lt;br /&gt;
|8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
|128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
|16 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647 &lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Java also defines a String class, which is used to create objects of many chars.  The String class provides functionality commonly implemented using arrays of chars in other languages, such as C. &lt;br /&gt;
&lt;br /&gt;
Java also defines the 'unsigned' keyword, which can be used to as a modifier to any of the integral types listed in the table above.  If the 'unsigned' keyword is used, the integral type will be unsigned instead of signed, and its range will change correspondingly. &lt;br /&gt;
&lt;br /&gt;
Java is capable of using any two objects of the same primitive data type for comparison.  Java defines a class for each data type, which have the same name but a capitalized first letter (e.g. Float instead of float).  These classes, called wrapper classes provide a series of methods that can manipulate their associated primitive data type, as well as convert to and from other data types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C# == &lt;br /&gt;
&lt;br /&gt;
C# is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  C# has all of the data types that are available in Java, as well as some additional ones.  &lt;br /&gt;
&lt;br /&gt;
Similar to Java, C# defines a String class which is used to create objects of many chars.  These data types are defined in C#: [http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! .NET Class &lt;br /&gt;
! width=&amp;quot;50&amp;quot; | Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte &lt;br /&gt;
| Byte &lt;br /&gt;
| 8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
| -128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| sbyte &lt;br /&gt;
| SByte &lt;br /&gt;
| 8 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -0 to 255&lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
| Int16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| ushort &lt;br /&gt;
| UInt16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 65,535&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| Int32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647&lt;br /&gt;
|-&lt;br /&gt;
| uint &lt;br /&gt;
| UInt32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 4,294,967,295&lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| Int64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|-&lt;br /&gt;
| ulong &lt;br /&gt;
| UInt64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 18,446,744,073,709,551,615&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| Float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| -3.402823e38 to 3.02823e38&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| Double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| -1.79769313486232e308 to 1.79769313486232e308&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| Boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| Char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|-&lt;br /&gt;
| object &lt;br /&gt;
| Object &lt;br /&gt;
| N/A &lt;br /&gt;
| Object is the base type of all other types&lt;br /&gt;
| N/A &lt;br /&gt;
|-&lt;br /&gt;
| string &lt;br /&gt;
| String &lt;br /&gt;
| N/A &lt;br /&gt;
| String is the base type for a sequence of chars&lt;br /&gt;
| N/A &lt;br /&gt;
|-&lt;br /&gt;
| decimal &lt;br /&gt;
| Decimal &lt;br /&gt;
| 128 &lt;br /&gt;
| Decimal is an integral type that can represent a decimal number with 29 significant digits &lt;br /&gt;
| ±1.0 × 10e−28 to ±7.9 × 10e28&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Like Java, each primitive data type in C# also has a class associated with it that.  These classes serve a similar purpose to their associated ones in Java.  They are used for comparison of objects, as well as conversion between other similar types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Objects in Ruby ==&lt;br /&gt;
Ruby is a pure object oriented language as compared to languages such as Java or C#, which use a more hybrid approach. In Ruby, all data types are represented as Objects. There are some [http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html inbuilt classes] that are provided to users in Ruby. However, only some of them are a basic building block for forming other types. This subset shown below gives us a list of primitive objects that can be used for data representation and manipulation:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! Description&lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| TrueClass&lt;br /&gt;
| Singleton instance &amp;quot;true&amp;quot; allowed&lt;br /&gt;
| true&lt;br /&gt;
|-&lt;br /&gt;
| FalseClass&lt;br /&gt;
| Singleton instance &amp;quot;false&amp;quot; allowed&lt;br /&gt;
| false&lt;br /&gt;
|-&lt;br /&gt;
| Integer [http://www.ruby-doc.org/core/Integer.html]&lt;br /&gt;
| Abstract class that forms the basis for Fixnum and Bignum&lt;br /&gt;
| See Fixnum and Bignum&lt;br /&gt;
|-&lt;br /&gt;
| Fixnum [http://www.ruby-doc.org/core-1.8.7/Fixnum.html]&lt;br /&gt;
| Integer representations that fit in native machine word&lt;br /&gt;
| Machine architecture dependent. 2^30-1 to -2^30 on 32-bit machines.&lt;br /&gt;
|-&lt;br /&gt;
| Bignum [http://www.ruby-doc.org/core/Bignum.html]&lt;br /&gt;
| Integer representations that do not fit in Fixnum width&lt;br /&gt;
| Machine architecture dependent. Values above Fixnum range.&lt;br /&gt;
|-&lt;br /&gt;
| Float [http://www.ruby-doc.org/core/Float.html]&lt;br /&gt;
| Real numbers using double precision representation&lt;br /&gt;
| Value after decimal point can be formatted&lt;br /&gt;
|-&lt;br /&gt;
| String [http://corelib.rubyonrails.org/classes/String.html]&lt;br /&gt;
| Contains sequence of characters&lt;br /&gt;
| No physical limit, but can be decided by machine architecture&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
One interesting observation from the above table is that Ruby does not have a Boolean class; instead it has a separate TrueClass and FalseClass [http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby].&lt;br /&gt;
&lt;br /&gt;
  puts true.class &lt;br /&gt;
  =&amp;gt; TrueClass&lt;br /&gt;
  puts false.class&lt;br /&gt;
  =&amp;gt; FalseClass&lt;br /&gt;
&lt;br /&gt;
Although types such as Array, Hash are also in-built types, they can be further composed of elements that are internally represented in one of the primitive types. Hence, they will not be treated by us as primitive objects, in the traditional definition of the term.&lt;br /&gt;
Each of the primitive objects listed above also provide certain convenience methods that are applicable for the underlying type.&lt;br /&gt;
For example, the Fixnum, Bignum and Float types provide support for arithmetic operations such as addition (+), subtraction(--), multiplication(*) and so on.&lt;br /&gt;
As with all other classes in Ruby, users can add functionality to existing primitive objects by reopening classes. The amount of memory required to implement the primitive objects in Ruby is machine dependent in some cases.&lt;br /&gt;
&lt;br /&gt;
== Merit Analysis of Primitive Types ==&lt;br /&gt;
This section deals with a brief analysis of the relative merits and demerits of primitive data types. While we focus on Java or Ruby for this purpose, most of these points are applicable across all object oriented languages.&lt;br /&gt;
&lt;br /&gt;
=== Advantages ===&lt;br /&gt;
Primitive types in object oriented languages have certain advantages over their class object counterparts. &lt;br /&gt;
* Simplicity: Primitive types/objects provide users a simple mechanism of manipulating data without relying on additional objects to achieve the same functionality. Operations on primitive types are more intuitive.&lt;br /&gt;
* Efficiency: This statement is applicable if the underlying primitive object definition is not modified (a feature that languages such as Ruby provide to users). As the representation in memory is designed to be make most efficient use of the underlying datatype, use of primitives can provide a benefit to the user, over the use of class objects to store the same data. &lt;br /&gt;
  Eg. Java provides wrappers [http://www.glenmccl.com/tip_016.htm] for certain primitive types. There is a certain performance and space cost associated with these. &lt;br /&gt;
  So, to maximize efficiency, direct use of the primitive types would provide the most benefit.&lt;br /&gt;
* Ability to use inbuilt methods: Depending on the primitive type, languages such as Ruby provide methods that can be used specifically to probe or manipulate objects. &lt;br /&gt;
  Eg. [http://corelib.rubyonrails.org/classes/String.html String] primitive object provides convenience methods such as upcase to convert the entire string to upper case, or capitalize, which converts only the first character to upper case.&lt;br /&gt;
* Ease of testing for comparison: With primitive types, the equality testing operators such as == can be used. These essentially compare the values stored in the primitive types. Regular objects also offer the eql? method for testing equality. However, the following are not equivalent:&lt;br /&gt;
  a=10&lt;br /&gt;
  =&amp;gt; 10&lt;br /&gt;
  a==10&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a==10.0&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a.eql?(10.0)&lt;br /&gt;
  =&amp;gt; false&lt;br /&gt;
The reason the .eql? fails is that this operator tests for value and type being the same. 10 is type Fixnum and 10.0 is type Float. &lt;br /&gt;
The eql? can be overridden by == for primitive objects if you wish to compare only the values, but that can have a negative impact on performance [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html].&lt;br /&gt;
&lt;br /&gt;
=== Disadvantages ===&lt;br /&gt;
* Lack of inheritance capability: The primitive data types in languages such as Java cannot be inherited to create further subtypes.&lt;br /&gt;
* Unexpected results due to method overriding: There are certain examples such as [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html], which show that overriding inbuilt methods such as == and eql? can lead to unexpected results.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Object oriented languages have varying levels of support for primitive data types and objects. Whether they are beneficial or not depends on the application to a great deal. If handled correctly, they can make object oriented programs more efficient. However, the user needs to be aware of the underlying representation of these types to handle any unexpected results.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# http://en.wikipedia.org/wiki/Primitive_data_type&lt;br /&gt;
# http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php&lt;br /&gt;
# http://www.jk-technology.com/c/inttypes.html&lt;br /&gt;
# http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html&lt;br /&gt;
# http://newty.de/fpt/intro.html&lt;br /&gt;
# http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html&lt;br /&gt;
# http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx&lt;br /&gt;
# http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html&lt;br /&gt;
# http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html&lt;br /&gt;
# http://www.glenmccl.com/tip_016.htm&lt;br /&gt;
# http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54300</id>
		<title>CSC/ECE 517 Fall 2011/ch3 3h rr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54300"/>
		<updated>2011-10-29T22:01:19Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''3h. Primitive objects.  At the beginning of Lecture 11, we discovered that Fixnums and Bignums are handled differently behind the scenes in Ruby.  Other languages, like Java, have made similar distinctions.  By contrast, languages such as C# and Eiffel try to hide these implementation differences from users.  Answer two questions: (1) How have different o-o languages implemented primitive objects?  E.g., how are they represented in memory, how are they tested for, do comparisons do anything different than for class objects, etc.  (2) What are the advantages and disadvantages of treating primitives differently from class objects in source code?''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Programming languages, whether statically or dynamically typed, have support for certain in-built data types. These data types, known as primitive types, are the basic representation of information in programs and have certain fixed attributes for a specific language[http://en.wikipedia.org/wiki/Primitive_data_type]. Statically typed languages such as C++, Java, Perl etc. support primitive data types, whereas with dynamically typed languages such as Ruby, Smalltalk, Lisp etc. they are actually in the form of primitive objects.  These primitive types are used to store the basic types of information that a computer can store and manipulate, and can also be used as building blocks for creating more complex data types. &lt;br /&gt;
This article explains the way different primitive types are implemented in certain object oriented languages. An analysis of the benefits and drawbacks of such types and the methods used to operate on them is also presented. &lt;br /&gt;
&lt;br /&gt;
== Primitive Types ==&lt;br /&gt;
The primitive types commonly included in most programming languages are:&lt;br /&gt;
* Boolean&lt;br /&gt;
* Character&lt;br /&gt;
* Integer&lt;br /&gt;
* Floating-point number&lt;br /&gt;
* Fixed-point number&lt;br /&gt;
* Reference&lt;br /&gt;
&lt;br /&gt;
=== Boolean ===&lt;br /&gt;
A Boolean is a primitive data type used to store one of two logical types: true or false.  Boolean data types are most commonly used as input paramters to a conditional statement (such as an ‘if’ statement), or as the output of a comparison between two comparable data types.  Booleans can be implemented in languages as either a discrete logical type, or implicitly as a numerical type.  In many languages, booleans can be implicitly converted to and from integer types.  &lt;br /&gt;
&lt;br /&gt;
=== Character ===&lt;br /&gt;
A character is a data type that represents an element of a written language, such as a letter, number, or symbol.  A character can also represent a control character, such as a carriage return or newline, which does not have a written meaning but controls how other characters are stored or displayed.   Characters are commonly stored as integers, and encoded using a character map.  &lt;br /&gt;
&lt;br /&gt;
=== Integer ===&lt;br /&gt;
An integer is a data type that represents one element of a finite subset of mathematical integers.  Integer, or Integral, data types can be either unsigned (able to store only positive whole numbers) or signed (able to store either positive or negative whole numbers).  The range of values that can be represented by an integer depends on the number of bits used to store the integer, whether or not it is a signed integer, and the encoding scheme (if it is signed).  Typically, an integer has a minimum and maximum value, and can store any integer in the range between those values.  The minimum value for unsigned integers is typically 0, and the maximum value is typically determined by the amount of memory used to store the integer.  For example, a un unsigned 8-bit number can store 2^8 (or 256) possible integral values; and would typically store any value from 0 to 255.  More generally, an n-bit unsigned integer can store from 0 to (2^n)-1.  For signed integers, modern computers use the Two’s Complement encoding scheme.  This allows for a range of −2^(n−1) through 2^(n−1)−1.  For example, an 8-bit signed integer could store any whole number in the range from -128 through +127.&lt;br /&gt;
&lt;br /&gt;
=== Floating-Point Number ===&lt;br /&gt;
A floating point number is a data type used to represent real numbers in a large range with varying degrees of precision.  In this representation, numbers are represented with a variable number of significant digits, and a variable number of exponential digits.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed-Point number ===&lt;br /&gt;
A fixed-point number is a data type used to represent real numbers.  Fixed-point numbers are called fixed-point because they have a set number of digits before and after a decimal mark.  In this regard, fixed-point numbers are represented as an integer, but are scaled by a predetermined factor.  &lt;br /&gt;
&lt;br /&gt;
Fixed-point numbers are commonly used in microprocessors that do not have a floating-point unit, or in systems in which computational efficiency is critical.  Fixed-point numbers can be treated as integers by an arithmetic logic unit (ALU) and scaled after a result is obtained, which can significantly lower the amount of time needed for a processor to obtain the result for some algorithms. &lt;br /&gt;
&lt;br /&gt;
Implementing algorithms using fixed-point arithmetic requires great care, because of the potential for information loss.  Fixed-point arithmetic operations -- multiplication in particular, has the potential to cause overflow.  Algorithms must be written with care to ensure that each term of an equation has a similar range and that the result will not cause an overflow.&lt;br /&gt;
&lt;br /&gt;
=== Reference ===&lt;br /&gt;
&lt;br /&gt;
A Reference is a data type that enables a program to access another item in memory.  A reference differs from other primitive data types in that it does not store data itself; instead it stores a value referring to another data object.  References are commonly used to refer to objects of large non-primitive data types.  References commonly store the physical memory address of the data that they are referring to.  Accessing the data referred to by a Reference is called dereferencing.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C++ ==&lt;br /&gt;
&lt;br /&gt;
C++ is a statically-typed object oriented language.  C++ is based on the C programming language, which is procedural, and adds support for object-oriented code.  &lt;br /&gt;
&lt;br /&gt;
These data types are defined in C++: [http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php] &lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! Name &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| void &lt;br /&gt;
| N/A &lt;br /&gt;
| the void data type is used to explicitly identify that a data has no type &lt;br /&gt;
| N/A&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits&lt;br /&gt;
| simple numerical type&lt;br /&gt;
| See [[http://www.jk-technology.com/c/inttypes.html]]&lt;br /&gt;
|-&lt;br /&gt;
| float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 8 bits &lt;br /&gt;
| a char is a single 8-bit character encoded using ASCII &lt;br /&gt;
| Ascii character 0x00 through ascii character 0xFF&lt;br /&gt;
|}&lt;br /&gt;
C++ supports Pointers for all of the types listed in the table above, as well as more complex data types (such as structs).  A Pointer in C++ is a data type that stores the physical address of some other data.  Pointers are created in C++ by using the * operator.  For example, a *Double[] is a pointer to an array of double-precision floating point numbers.  C++ Also supports function pointers -- pointers that reference the beginning address of a function in memory.  They are commonly used to implement callback functions [http://newty.de/fpt/intro.html#what]&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in Java == &lt;br /&gt;
&lt;br /&gt;
Java is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  These data types are defined in Java: [http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html]&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;|Name&lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte&lt;br /&gt;
|8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
|128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
|16 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647 &lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Java also defines a String class, which is used to create objects of many chars.  The String class provides functionality commonly implemented using arrays of chars in other languages, such as C. &lt;br /&gt;
&lt;br /&gt;
Java also defines the 'unsigned' keyword, which can be used to as a modifier to any of the integral types listed in the table above.  If the 'unsigned' keyword is used, the integral type will be unsigned instead of signed, and its range will change correspondingly. &lt;br /&gt;
&lt;br /&gt;
Java is capable of using any two objects of the same primitive data type for comparison.  Java defines a class for each data type, which have the same name but a capitalized first letter (e.g. Float instead of float).  These classes, called wrapper classes provide a series of methods that can manipulate their associated primitive data type, as well as convert to and from other data types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C# == &lt;br /&gt;
&lt;br /&gt;
C# is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  C# has all of the data types that are available in Java, as well as some additional ones.  &lt;br /&gt;
&lt;br /&gt;
Similar to Java, C# defines a String class which is used to create objects of many chars.  These data types are defined in C#: [http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! .NET Class &lt;br /&gt;
! width=&amp;quot;80&amp;quot; | Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte &lt;br /&gt;
| Byte &lt;br /&gt;
| 8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
| -128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| sbyte &lt;br /&gt;
| SByte &lt;br /&gt;
| 8 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -0 to 255&lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
| Int16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| ushort &lt;br /&gt;
| UInt16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 65,535&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| Int32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647&lt;br /&gt;
|-&lt;br /&gt;
| uint &lt;br /&gt;
| UInt32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 4,294,967,295&lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| Int64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|-&lt;br /&gt;
| ulong &lt;br /&gt;
| UInt64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 18,446,744,073,709,551,615&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| Float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| -3.402823e38 to 3.02823e38&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| Double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| -1.79769313486232e308 to 1.79769313486232e308&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| Boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| Char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|-&lt;br /&gt;
| object &lt;br /&gt;
| Object &lt;br /&gt;
| N/A &lt;br /&gt;
| Object is the base type of all other types&lt;br /&gt;
| N/A &lt;br /&gt;
|-&lt;br /&gt;
| string &lt;br /&gt;
| String &lt;br /&gt;
| N/A &lt;br /&gt;
| String is the base type for a sequence of chars&lt;br /&gt;
| N/A &lt;br /&gt;
|-&lt;br /&gt;
| decimal &lt;br /&gt;
| Decimal &lt;br /&gt;
| 128 &lt;br /&gt;
| Decimal is an integral type that can represent a decimal number with 29 significant digits &lt;br /&gt;
| ±1.0 × 10e−28 to ±7.9 × 10e28&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Like Java, each primitive data type in C# also has a class associated with it that.  These classes serve a similar purpose to their associated ones in Java.  They are used for comparison of objects, as well as conversion between other similar types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Objects in Ruby ==&lt;br /&gt;
Ruby is a pure object oriented language as compared to languages such as Java or C#, which use a more hybrid approach. In Ruby, all data types are represented as Objects. There are some [http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html inbuilt classes] that are provided to users in Ruby. However, only some of them are a basic building block for forming other types. This subset shown below gives us a list of primitive objects that can be used for data representation and manipulation:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! Description&lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| TrueClass&lt;br /&gt;
| Singleton instance &amp;quot;true&amp;quot; allowed&lt;br /&gt;
| true&lt;br /&gt;
|-&lt;br /&gt;
| FalseClass&lt;br /&gt;
| Singleton instance &amp;quot;false&amp;quot; allowed&lt;br /&gt;
| false&lt;br /&gt;
|-&lt;br /&gt;
| Integer [http://www.ruby-doc.org/core/Integer.html]&lt;br /&gt;
| Abstract class that forms the basis for Fixnum and Bignum&lt;br /&gt;
| See Fixnum and Bignum&lt;br /&gt;
|-&lt;br /&gt;
| Fixnum [http://www.ruby-doc.org/core-1.8.7/Fixnum.html]&lt;br /&gt;
| Integer representations that fit in native machine word&lt;br /&gt;
| Machine architecture dependent. 2^30-1 to -2^30 on 32-bit machines.&lt;br /&gt;
|-&lt;br /&gt;
| Bignum [http://www.ruby-doc.org/core/Bignum.html]&lt;br /&gt;
| Integer representations that do not fit in Fixnum width&lt;br /&gt;
| Machine architecture dependent. Values above Fixnum range.&lt;br /&gt;
|-&lt;br /&gt;
| Float [http://www.ruby-doc.org/core/Float.html]&lt;br /&gt;
| Real numbers using double precision representation&lt;br /&gt;
| Value after decimal point can be formatted&lt;br /&gt;
|-&lt;br /&gt;
| String [http://corelib.rubyonrails.org/classes/String.html]&lt;br /&gt;
| Contains sequence of characters&lt;br /&gt;
| No physical limit, but can be decided by machine architecture&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
One interesting observation from the above table is that Ruby does not have a Boolean class; instead it has a separate TrueClass and FalseClass [http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby].&lt;br /&gt;
&lt;br /&gt;
  puts true.class &lt;br /&gt;
  =&amp;gt; TrueClass&lt;br /&gt;
  puts false.class&lt;br /&gt;
  =&amp;gt; FalseClass&lt;br /&gt;
&lt;br /&gt;
Although types such as Array, Hash are also in-built types, they can be further composed of elements that are internally represented in one of the primitive types. Hence, they will not be treated by us as primitive objects, in the traditional definition of the term.&lt;br /&gt;
Each of the primitive objects listed above also provide certain convenience methods that are applicable for the underlying type.&lt;br /&gt;
For example, the Fixnum, Bignum and Float types provide support for arithmetic operations such as addition (+), subtraction(--), multiplication(*) and so on.&lt;br /&gt;
As with all other classes in Ruby, users can add functionality to existing primitive objects by reopening classes. The amount of memory required to implement the primitive objects in Ruby is machine dependent in some cases.&lt;br /&gt;
&lt;br /&gt;
== Merit Analysis of Primitive Types ==&lt;br /&gt;
This section deals with a brief analysis of the relative merits and demerits of primitive data types. While we focus on Java or Ruby for this purpose, most of these points are applicable across all object oriented languages.&lt;br /&gt;
&lt;br /&gt;
=== Advantages ===&lt;br /&gt;
Primitive types in object oriented languages have certain advantages over their class object counterparts. &lt;br /&gt;
* Simplicity: Primitive types/objects provide users a simple mechanism of manipulating data without relying on additional objects to achieve the same functionality. Operations on primitive types are more intuitive.&lt;br /&gt;
* Efficiency: This statement is applicable if the underlying primitive object definition is not modified (a feature that languages such as Ruby provide to users). As the representation in memory is designed to be make most efficient use of the underlying datatype, use of primitives can provide a benefit to the user, over the use of class objects to store the same data. &lt;br /&gt;
  Eg. Java provides wrappers [http://www.glenmccl.com/tip_016.htm] for certain primitive types. There is a certain performance and space cost associated with these. &lt;br /&gt;
  So, to maximize efficiency, direct use of the primitive types would provide the most benefit.&lt;br /&gt;
* Ability to use inbuilt methods: Depending on the primitive type, languages such as Ruby provide methods that can be used specifically to probe or manipulate objects. &lt;br /&gt;
  Eg. [http://corelib.rubyonrails.org/classes/String.html String] primitive object provides convenience methods such as upcase to convert the entire string to upper case, or capitalize, which converts only the first character to upper case.&lt;br /&gt;
* Ease of testing for comparison: With primitive types, the equality testing operators such as == can be used. These essentially compare the values stored in the primitive types. Regular objects also offer the eql? method for testing equality. However, the following are not equivalent:&lt;br /&gt;
  a=10&lt;br /&gt;
  =&amp;gt; 10&lt;br /&gt;
  a==10&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a==10.0&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a.eql?(10.0)&lt;br /&gt;
  =&amp;gt; false&lt;br /&gt;
The reason the .eql? fails is that this operator tests for value and type being the same. 10 is type Fixnum and 10.0 is type Float. &lt;br /&gt;
The eql? can be overridden by == for primitive objects if you wish to compare only the values, but that can have a negative impact on performance [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html].&lt;br /&gt;
&lt;br /&gt;
=== Disadvantages ===&lt;br /&gt;
* Lack of inheritance capability: The primitive data types in languages such as Java cannot be inherited to create further subtypes.&lt;br /&gt;
* Unexpected results due to method overriding: There are certain examples such as [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html], which show that overriding inbuilt methods such as == and eql? can lead to unexpected results.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Object oriented languages have varying levels of support for primitive data types and objects. Whether they are beneficial or not depends on the application to a great deal. If handled correctly, they can make object oriented programs more efficient. However, the user needs to be aware of the underlying representation of these types to handle any unexpected results.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# http://en.wikipedia.org/wiki/Primitive_data_type&lt;br /&gt;
# http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php&lt;br /&gt;
# http://www.jk-technology.com/c/inttypes.html&lt;br /&gt;
# http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html&lt;br /&gt;
# http://newty.de/fpt/intro.html&lt;br /&gt;
# http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html&lt;br /&gt;
# http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx&lt;br /&gt;
# http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html&lt;br /&gt;
# http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html&lt;br /&gt;
# http://www.glenmccl.com/tip_016.htm&lt;br /&gt;
# http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54299</id>
		<title>CSC/ECE 517 Fall 2011/ch3 3h rr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54299"/>
		<updated>2011-10-29T22:00:49Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''3h. Primitive objects.  At the beginning of Lecture 11, we discovered that Fixnums and Bignums are handled differently behind the scenes in Ruby.  Other languages, like Java, have made similar distinctions.  By contrast, languages such as C# and Eiffel try to hide these implementation differences from users.  Answer two questions: (1) How have different o-o languages implemented primitive objects?  E.g., how are they represented in memory, how are they tested for, do comparisons do anything different than for class objects, etc.  (2) What are the advantages and disadvantages of treating primitives differently from class objects in source code?''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Programming languages, whether statically or dynamically typed, have support for certain in-built data types. These data types, known as primitive types, are the basic representation of information in programs and have certain fixed attributes for a specific language[http://en.wikipedia.org/wiki/Primitive_data_type]. Statically typed languages such as C++, Java, Perl etc. support primitive data types, whereas with dynamically typed languages such as Ruby, Smalltalk, Lisp etc. they are actually in the form of primitive objects.  These primitive types are used to store the basic types of information that a computer can store and manipulate, and can also be used as building blocks for creating more complex data types. &lt;br /&gt;
This article explains the way different primitive types are implemented in certain object oriented languages. An analysis of the benefits and drawbacks of such types and the methods used to operate on them is also presented. &lt;br /&gt;
&lt;br /&gt;
== Primitive Types ==&lt;br /&gt;
The primitive types commonly included in most programming languages are:&lt;br /&gt;
* Boolean&lt;br /&gt;
* Character&lt;br /&gt;
* Integer&lt;br /&gt;
* Floating-point number&lt;br /&gt;
* Fixed-point number&lt;br /&gt;
* Reference&lt;br /&gt;
&lt;br /&gt;
=== Boolean ===&lt;br /&gt;
A Boolean is a primitive data type used to store one of two logical types: true or false.  Boolean data types are most commonly used as input paramters to a conditional statement (such as an ‘if’ statement), or as the output of a comparison between two comparable data types.  Booleans can be implemented in languages as either a discrete logical type, or implicitly as a numerical type.  In many languages, booleans can be implicitly converted to and from integer types.  &lt;br /&gt;
&lt;br /&gt;
=== Character ===&lt;br /&gt;
A character is a data type that represents an element of a written language, such as a letter, number, or symbol.  A character can also represent a control character, such as a carriage return or newline, which does not have a written meaning but controls how other characters are stored or displayed.   Characters are commonly stored as integers, and encoded using a character map.  &lt;br /&gt;
&lt;br /&gt;
=== Integer ===&lt;br /&gt;
An integer is a data type that represents one element of a finite subset of mathematical integers.  Integer, or Integral, data types can be either unsigned (able to store only positive whole numbers) or signed (able to store either positive or negative whole numbers).  The range of values that can be represented by an integer depends on the number of bits used to store the integer, whether or not it is a signed integer, and the encoding scheme (if it is signed).  Typically, an integer has a minimum and maximum value, and can store any integer in the range between those values.  The minimum value for unsigned integers is typically 0, and the maximum value is typically determined by the amount of memory used to store the integer.  For example, a un unsigned 8-bit number can store 2^8 (or 256) possible integral values; and would typically store any value from 0 to 255.  More generally, an n-bit unsigned integer can store from 0 to (2^n)-1.  For signed integers, modern computers use the Two’s Complement encoding scheme.  This allows for a range of −2^(n−1) through 2^(n−1)−1.  For example, an 8-bit signed integer could store any whole number in the range from -128 through +127.&lt;br /&gt;
&lt;br /&gt;
=== Floating-Point Number ===&lt;br /&gt;
A floating point number is a data type used to represent real numbers in a large range with varying degrees of precision.  In this representation, numbers are represented with a variable number of significant digits, and a variable number of exponential digits.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed-Point number ===&lt;br /&gt;
A fixed-point number is a data type used to represent real numbers.  Fixed-point numbers are called fixed-point because they have a set number of digits before and after a decimal mark.  In this regard, fixed-point numbers are represented as an integer, but are scaled by a predetermined factor.  &lt;br /&gt;
&lt;br /&gt;
Fixed-point numbers are commonly used in microprocessors that do not have a floating-point unit, or in systems in which computational efficiency is critical.  Fixed-point numbers can be treated as integers by an arithmetic logic unit (ALU) and scaled after a result is obtained, which can significantly lower the amount of time needed for a processor to obtain the result for some algorithms. &lt;br /&gt;
&lt;br /&gt;
Implementing algorithms using fixed-point arithmetic requires great care, because of the potential for information loss.  Fixed-point arithmetic operations -- multiplication in particular, has the potential to cause overflow.  Algorithms must be written with care to ensure that each term of an equation has a similar range and that the result will not cause an overflow.&lt;br /&gt;
&lt;br /&gt;
=== Reference ===&lt;br /&gt;
&lt;br /&gt;
A Reference is a data type that enables a program to access another item in memory.  A reference differs from other primitive data types in that it does not store data itself; instead it stores a value referring to another data object.  References are commonly used to refer to objects of large non-primitive data types.  References commonly store the physical memory address of the data that they are referring to.  Accessing the data referred to by a Reference is called dereferencing.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C++ ==&lt;br /&gt;
&lt;br /&gt;
C++ is a statically-typed object oriented language.  C++ is based on the C programming language, which is procedural, and adds support for object-oriented code.  &lt;br /&gt;
&lt;br /&gt;
These data types are defined in C++: [http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php] &lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! Name &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| void &lt;br /&gt;
| N/A &lt;br /&gt;
| the void data type is used to explicitly identify that a data has no type &lt;br /&gt;
| N/A&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits&lt;br /&gt;
| simple numerical type&lt;br /&gt;
| See [[http://www.jk-technology.com/c/inttypes.html]]&lt;br /&gt;
|-&lt;br /&gt;
| float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 8 bits &lt;br /&gt;
| a char is a single 8-bit character encoded using ASCII &lt;br /&gt;
| Ascii character 0x00 through ascii character 0xFF&lt;br /&gt;
|}&lt;br /&gt;
C++ supports Pointers for all of the types listed in the table above, as well as more complex data types (such as structs).  A Pointer in C++ is a data type that stores the physical address of some other data.  Pointers are created in C++ by using the * operator.  For example, a *Double[] is a pointer to an array of double-precision floating point numbers.  C++ Also supports function pointers -- pointers that reference the beginning address of a function in memory.  They are commonly used to implement callback functions [http://newty.de/fpt/intro.html#what]&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in Java == &lt;br /&gt;
&lt;br /&gt;
Java is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  These data types are defined in Java: [http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html]&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;|Name&lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte&lt;br /&gt;
|8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
|128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
|16 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647 &lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Java also defines a String class, which is used to create objects of many chars.  The String class provides functionality commonly implemented using arrays of chars in other languages, such as C. &lt;br /&gt;
&lt;br /&gt;
Java also defines the 'unsigned' keyword, which can be used to as a modifier to any of the integral types listed in the table above.  If the 'unsigned' keyword is used, the integral type will be unsigned instead of signed, and its range will change correspondingly. &lt;br /&gt;
&lt;br /&gt;
Java is capable of using any two objects of the same primitive data type for comparison.  Java defines a class for each data type, which have the same name but a capitalized first letter (e.g. Float instead of float).  These classes, called wrapper classes provide a series of methods that can manipulate their associated primitive data type, as well as convert to and from other data types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C# == &lt;br /&gt;
&lt;br /&gt;
C# is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  C# has all of the data types that are available in Java, as well as some additional ones.  &lt;br /&gt;
&lt;br /&gt;
Similar to Java, C# defines a String class which is used to create objects of many chars.  These data types are defined in C#: [http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! .NET Class &lt;br /&gt;
! width=&amp;quot;40&amp;quot; | Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte &lt;br /&gt;
| Byte &lt;br /&gt;
| 8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
| -128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| sbyte &lt;br /&gt;
| SByte &lt;br /&gt;
| 8 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -0 to 255&lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
| Int16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| ushort &lt;br /&gt;
| UInt16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 65,535&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| Int32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647&lt;br /&gt;
|-&lt;br /&gt;
| uint &lt;br /&gt;
| UInt32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 4,294,967,295&lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| Int64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|-&lt;br /&gt;
| ulong &lt;br /&gt;
| UInt64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 18,446,744,073,709,551,615&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| Float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| -3.402823e38 to 3.02823e38&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| Double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| -1.79769313486232e308 to 1.79769313486232e308&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| Boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| Char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|-&lt;br /&gt;
| object &lt;br /&gt;
| Object &lt;br /&gt;
| N/A &lt;br /&gt;
| Object is the base type of all other types&lt;br /&gt;
| N/A &lt;br /&gt;
|-&lt;br /&gt;
| string &lt;br /&gt;
| String &lt;br /&gt;
| N/A &lt;br /&gt;
| String is the base type for a sequence of chars&lt;br /&gt;
| N/A &lt;br /&gt;
|-&lt;br /&gt;
| decimal &lt;br /&gt;
| Decimal &lt;br /&gt;
| 128 &lt;br /&gt;
| Decimal is an integral type that can represent a decimal number with 29 significant digits &lt;br /&gt;
| ±1.0 × 10e−28 to ±7.9 × 10e28&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Like Java, each primitive data type in C# also has a class associated with it that.  These classes serve a similar purpose to their associated ones in Java.  They are used for comparison of objects, as well as conversion between other similar types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Objects in Ruby ==&lt;br /&gt;
Ruby is a pure object oriented language as compared to languages such as Java or C#, which use a more hybrid approach. In Ruby, all data types are represented as Objects. There are some [http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html inbuilt classes] that are provided to users in Ruby. However, only some of them are a basic building block for forming other types. This subset shown below gives us a list of primitive objects that can be used for data representation and manipulation:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! Description&lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| TrueClass&lt;br /&gt;
| Singleton instance &amp;quot;true&amp;quot; allowed&lt;br /&gt;
| true&lt;br /&gt;
|-&lt;br /&gt;
| FalseClass&lt;br /&gt;
| Singleton instance &amp;quot;false&amp;quot; allowed&lt;br /&gt;
| false&lt;br /&gt;
|-&lt;br /&gt;
| Integer [http://www.ruby-doc.org/core/Integer.html]&lt;br /&gt;
| Abstract class that forms the basis for Fixnum and Bignum&lt;br /&gt;
| See Fixnum and Bignum&lt;br /&gt;
|-&lt;br /&gt;
| Fixnum [http://www.ruby-doc.org/core-1.8.7/Fixnum.html]&lt;br /&gt;
| Integer representations that fit in native machine word&lt;br /&gt;
| Machine architecture dependent. 2^30-1 to -2^30 on 32-bit machines.&lt;br /&gt;
|-&lt;br /&gt;
| Bignum [http://www.ruby-doc.org/core/Bignum.html]&lt;br /&gt;
| Integer representations that do not fit in Fixnum width&lt;br /&gt;
| Machine architecture dependent. Values above Fixnum range.&lt;br /&gt;
|-&lt;br /&gt;
| Float [http://www.ruby-doc.org/core/Float.html]&lt;br /&gt;
| Real numbers using double precision representation&lt;br /&gt;
| Value after decimal point can be formatted&lt;br /&gt;
|-&lt;br /&gt;
| String [http://corelib.rubyonrails.org/classes/String.html]&lt;br /&gt;
| Contains sequence of characters&lt;br /&gt;
| No physical limit, but can be decided by machine architecture&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
One interesting observation from the above table is that Ruby does not have a Boolean class; instead it has a separate TrueClass and FalseClass [http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby].&lt;br /&gt;
&lt;br /&gt;
  puts true.class &lt;br /&gt;
  =&amp;gt; TrueClass&lt;br /&gt;
  puts false.class&lt;br /&gt;
  =&amp;gt; FalseClass&lt;br /&gt;
&lt;br /&gt;
Although types such as Array, Hash are also in-built types, they can be further composed of elements that are internally represented in one of the primitive types. Hence, they will not be treated by us as primitive objects, in the traditional definition of the term.&lt;br /&gt;
Each of the primitive objects listed above also provide certain convenience methods that are applicable for the underlying type.&lt;br /&gt;
For example, the Fixnum, Bignum and Float types provide support for arithmetic operations such as addition (+), subtraction(--), multiplication(*) and so on.&lt;br /&gt;
As with all other classes in Ruby, users can add functionality to existing primitive objects by reopening classes. The amount of memory required to implement the primitive objects in Ruby is machine dependent in some cases.&lt;br /&gt;
&lt;br /&gt;
== Merit Analysis of Primitive Types ==&lt;br /&gt;
This section deals with a brief analysis of the relative merits and demerits of primitive data types. While we focus on Java or Ruby for this purpose, most of these points are applicable across all object oriented languages.&lt;br /&gt;
&lt;br /&gt;
=== Advantages ===&lt;br /&gt;
Primitive types in object oriented languages have certain advantages over their class object counterparts. &lt;br /&gt;
* Simplicity: Primitive types/objects provide users a simple mechanism of manipulating data without relying on additional objects to achieve the same functionality. Operations on primitive types are more intuitive.&lt;br /&gt;
* Efficiency: This statement is applicable if the underlying primitive object definition is not modified (a feature that languages such as Ruby provide to users). As the representation in memory is designed to be make most efficient use of the underlying datatype, use of primitives can provide a benefit to the user, over the use of class objects to store the same data. &lt;br /&gt;
  Eg. Java provides wrappers [http://www.glenmccl.com/tip_016.htm] for certain primitive types. There is a certain performance and space cost associated with these. &lt;br /&gt;
  So, to maximize efficiency, direct use of the primitive types would provide the most benefit.&lt;br /&gt;
* Ability to use inbuilt methods: Depending on the primitive type, languages such as Ruby provide methods that can be used specifically to probe or manipulate objects. &lt;br /&gt;
  Eg. [http://corelib.rubyonrails.org/classes/String.html String] primitive object provides convenience methods such as upcase to convert the entire string to upper case, or capitalize, which converts only the first character to upper case.&lt;br /&gt;
* Ease of testing for comparison: With primitive types, the equality testing operators such as == can be used. These essentially compare the values stored in the primitive types. Regular objects also offer the eql? method for testing equality. However, the following are not equivalent:&lt;br /&gt;
  a=10&lt;br /&gt;
  =&amp;gt; 10&lt;br /&gt;
  a==10&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a==10.0&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a.eql?(10.0)&lt;br /&gt;
  =&amp;gt; false&lt;br /&gt;
The reason the .eql? fails is that this operator tests for value and type being the same. 10 is type Fixnum and 10.0 is type Float. &lt;br /&gt;
The eql? can be overridden by == for primitive objects if you wish to compare only the values, but that can have a negative impact on performance [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html].&lt;br /&gt;
&lt;br /&gt;
=== Disadvantages ===&lt;br /&gt;
* Lack of inheritance capability: The primitive data types in languages such as Java cannot be inherited to create further subtypes.&lt;br /&gt;
* Unexpected results due to method overriding: There are certain examples such as [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html], which show that overriding inbuilt methods such as == and eql? can lead to unexpected results.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Object oriented languages have varying levels of support for primitive data types and objects. Whether they are beneficial or not depends on the application to a great deal. If handled correctly, they can make object oriented programs more efficient. However, the user needs to be aware of the underlying representation of these types to handle any unexpected results.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# http://en.wikipedia.org/wiki/Primitive_data_type&lt;br /&gt;
# http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php&lt;br /&gt;
# http://www.jk-technology.com/c/inttypes.html&lt;br /&gt;
# http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html&lt;br /&gt;
# http://newty.de/fpt/intro.html&lt;br /&gt;
# http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html&lt;br /&gt;
# http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx&lt;br /&gt;
# http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html&lt;br /&gt;
# http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html&lt;br /&gt;
# http://www.glenmccl.com/tip_016.htm&lt;br /&gt;
# http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54298</id>
		<title>CSC/ECE 517 Fall 2011/ch3 3h rr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54298"/>
		<updated>2011-10-29T21:59:54Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''3h. Primitive objects.  At the beginning of Lecture 11, we discovered that Fixnums and Bignums are handled differently behind the scenes in Ruby.  Other languages, like Java, have made similar distinctions.  By contrast, languages such as C# and Eiffel try to hide these implementation differences from users.  Answer two questions: (1) How have different o-o languages implemented primitive objects?  E.g., how are they represented in memory, how are they tested for, do comparisons do anything different than for class objects, etc.  (2) What are the advantages and disadvantages of treating primitives differently from class objects in source code?''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Programming languages, whether statically or dynamically typed, have support for certain in-built data types. These data types, known as primitive types, are the basic representation of information in programs and have certain fixed attributes for a specific language[http://en.wikipedia.org/wiki/Primitive_data_type]. Statically typed languages such as C++, Java, Perl etc. support primitive data types, whereas with dynamically typed languages such as Ruby, Smalltalk, Lisp etc. they are actually in the form of primitive objects.  These primitive types are used to store the basic types of information that a computer can store and manipulate, and can also be used as building blocks for creating more complex data types. &lt;br /&gt;
This article explains the way different primitive types are implemented in certain object oriented languages. An analysis of the benefits and drawbacks of such types and the methods used to operate on them is also presented. &lt;br /&gt;
&lt;br /&gt;
== Primitive Types ==&lt;br /&gt;
The primitive types commonly included in most programming languages are:&lt;br /&gt;
* Boolean&lt;br /&gt;
* Character&lt;br /&gt;
* Integer&lt;br /&gt;
* Floating-point number&lt;br /&gt;
* Fixed-point number&lt;br /&gt;
* Reference&lt;br /&gt;
&lt;br /&gt;
=== Boolean ===&lt;br /&gt;
A Boolean is a primitive data type used to store one of two logical types: true or false.  Boolean data types are most commonly used as input paramters to a conditional statement (such as an ‘if’ statement), or as the output of a comparison between two comparable data types.  Booleans can be implemented in languages as either a discrete logical type, or implicitly as a numerical type.  In many languages, booleans can be implicitly converted to and from integer types.  &lt;br /&gt;
&lt;br /&gt;
=== Character ===&lt;br /&gt;
A character is a data type that represents an element of a written language, such as a letter, number, or symbol.  A character can also represent a control character, such as a carriage return or newline, which does not have a written meaning but controls how other characters are stored or displayed.   Characters are commonly stored as integers, and encoded using a character map.  &lt;br /&gt;
&lt;br /&gt;
=== Integer ===&lt;br /&gt;
An integer is a data type that represents one element of a finite subset of mathematical integers.  Integer, or Integral, data types can be either unsigned (able to store only positive whole numbers) or signed (able to store either positive or negative whole numbers).  The range of values that can be represented by an integer depends on the number of bits used to store the integer, whether or not it is a signed integer, and the encoding scheme (if it is signed).  Typically, an integer has a minimum and maximum value, and can store any integer in the range between those values.  The minimum value for unsigned integers is typically 0, and the maximum value is typically determined by the amount of memory used to store the integer.  For example, a un unsigned 8-bit number can store 2^8 (or 256) possible integral values; and would typically store any value from 0 to 255.  More generally, an n-bit unsigned integer can store from 0 to (2^n)-1.  For signed integers, modern computers use the Two’s Complement encoding scheme.  This allows for a range of −2^(n−1) through 2^(n−1)−1.  For example, an 8-bit signed integer could store any whole number in the range from -128 through +127.&lt;br /&gt;
&lt;br /&gt;
=== Floating-Point Number ===&lt;br /&gt;
A floating point number is a data type used to represent real numbers in a large range with varying degrees of precision.  In this representation, numbers are represented with a variable number of significant digits, and a variable number of exponential digits.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed-Point number ===&lt;br /&gt;
A fixed-point number is a data type used to represent real numbers.  Fixed-point numbers are called fixed-point because they have a set number of digits before and after a decimal mark.  In this regard, fixed-point numbers are represented as an integer, but are scaled by a predetermined factor.  &lt;br /&gt;
&lt;br /&gt;
Fixed-point numbers are commonly used in microprocessors that do not have a floating-point unit, or in systems in which computational efficiency is critical.  Fixed-point numbers can be treated as integers by an arithmetic logic unit (ALU) and scaled after a result is obtained, which can significantly lower the amount of time needed for a processor to obtain the result for some algorithms. &lt;br /&gt;
&lt;br /&gt;
Implementing algorithms using fixed-point arithmetic requires great care, because of the potential for information loss.  Fixed-point arithmetic operations -- multiplication in particular, has the potential to cause overflow.  Algorithms must be written with care to ensure that each term of an equation has a similar range and that the result will not cause an overflow.&lt;br /&gt;
&lt;br /&gt;
=== Reference ===&lt;br /&gt;
&lt;br /&gt;
A Reference is a data type that enables a program to access another item in memory.  A reference differs from other primitive data types in that it does not store data itself; instead it stores a value referring to another data object.  References are commonly used to refer to objects of large non-primitive data types.  References commonly store the physical memory address of the data that they are referring to.  Accessing the data referred to by a Reference is called dereferencing.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C++ ==&lt;br /&gt;
&lt;br /&gt;
C++ is a statically-typed object oriented language.  C++ is based on the C programming language, which is procedural, and adds support for object-oriented code.  &lt;br /&gt;
&lt;br /&gt;
These data types are defined in C++: [http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php] &lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! Name &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| void &lt;br /&gt;
| N/A &lt;br /&gt;
| the void data type is used to explicitly identify that a data has no type &lt;br /&gt;
| N/A&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits&lt;br /&gt;
| simple numerical type&lt;br /&gt;
| See [[http://www.jk-technology.com/c/inttypes.html]]&lt;br /&gt;
|-&lt;br /&gt;
| float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 8 bits &lt;br /&gt;
| a char is a single 8-bit character encoded using ASCII &lt;br /&gt;
| Ascii character 0x00 through ascii character 0xFF&lt;br /&gt;
|}&lt;br /&gt;
C++ supports Pointers for all of the types listed in the table above, as well as more complex data types (such as structs).  A Pointer in C++ is a data type that stores the physical address of some other data.  Pointers are created in C++ by using the * operator.  For example, a *Double[] is a pointer to an array of double-precision floating point numbers.  C++ Also supports function pointers -- pointers that reference the beginning address of a function in memory.  They are commonly used to implement callback functions [http://newty.de/fpt/intro.html#what]&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in Java == &lt;br /&gt;
&lt;br /&gt;
Java is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  These data types are defined in Java: [http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html]&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;|Name&lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte&lt;br /&gt;
|8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
|128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
|16 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647 &lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Java also defines a String class, which is used to create objects of many chars.  The String class provides functionality commonly implemented using arrays of chars in other languages, such as C. &lt;br /&gt;
&lt;br /&gt;
Java also defines the 'unsigned' keyword, which can be used to as a modifier to any of the integral types listed in the table above.  If the 'unsigned' keyword is used, the integral type will be unsigned instead of signed, and its range will change correspondingly. &lt;br /&gt;
&lt;br /&gt;
Java is capable of using any two objects of the same primitive data type for comparison.  Java defines a class for each data type, which have the same name but a capitalized first letter (e.g. Float instead of float).  These classes, called wrapper classes provide a series of methods that can manipulate their associated primitive data type, as well as convert to and from other data types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C# == &lt;br /&gt;
&lt;br /&gt;
C# is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  C# has all of the data types that are available in Java, as well as some additional ones.  &lt;br /&gt;
&lt;br /&gt;
Similar to Java, C# defines a String class which is used to create objects of many chars.  These data types are defined in C#: [http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! .NET Class &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte &lt;br /&gt;
| Byte &lt;br /&gt;
| 8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
| -128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| sbyte &lt;br /&gt;
| SByte &lt;br /&gt;
| 8 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -0 to 255&lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
| Int16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| ushort &lt;br /&gt;
| UInt16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 65,535&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| Int32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647&lt;br /&gt;
|-&lt;br /&gt;
| uint &lt;br /&gt;
| UInt32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 4,294,967,295&lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| Int64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|-&lt;br /&gt;
| ulong &lt;br /&gt;
| UInt64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 18,446,744,073,709,551,615&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| Float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| -3.402823e38 to 3.02823e38&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| Double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| -1.79769313486232e308 to 1.79769313486232e308&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| Boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| Char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|-&lt;br /&gt;
| object &lt;br /&gt;
| Object &lt;br /&gt;
| N/A &lt;br /&gt;
| Object is the base type of all other types&lt;br /&gt;
| N/A &lt;br /&gt;
|-&lt;br /&gt;
| string &lt;br /&gt;
| String &lt;br /&gt;
| N/A &lt;br /&gt;
| String is the base type for a sequence of chars&lt;br /&gt;
| N/A &lt;br /&gt;
|-&lt;br /&gt;
| decimal &lt;br /&gt;
| Decimal &lt;br /&gt;
| 128 &lt;br /&gt;
| Decimal is an integral type that can represent a decimal number with 29 significant digits &lt;br /&gt;
| ±1.0 × 10e−28 to ±7.9 × 10e28&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Like Java, each primitive data type in C# also has a class associated with it that.  These classes serve a similar purpose to their associated ones in Java.  They are used for comparison of objects, as well as conversion between other similar types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Objects in Ruby ==&lt;br /&gt;
Ruby is a pure object oriented language as compared to languages such as Java or C#, which use a more hybrid approach. In Ruby, all data types are represented as Objects. There are some [http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html inbuilt classes] that are provided to users in Ruby. However, only some of them are a basic building block for forming other types. This subset shown below gives us a list of primitive objects that can be used for data representation and manipulation:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! Description&lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| TrueClass&lt;br /&gt;
| Singleton instance &amp;quot;true&amp;quot; allowed&lt;br /&gt;
| true&lt;br /&gt;
|-&lt;br /&gt;
| FalseClass&lt;br /&gt;
| Singleton instance &amp;quot;false&amp;quot; allowed&lt;br /&gt;
| false&lt;br /&gt;
|-&lt;br /&gt;
| Integer [http://www.ruby-doc.org/core/Integer.html]&lt;br /&gt;
| Abstract class that forms the basis for Fixnum and Bignum&lt;br /&gt;
| See Fixnum and Bignum&lt;br /&gt;
|-&lt;br /&gt;
| Fixnum [http://www.ruby-doc.org/core-1.8.7/Fixnum.html]&lt;br /&gt;
| Integer representations that fit in native machine word&lt;br /&gt;
| Machine architecture dependent. 2^30-1 to -2^30 on 32-bit machines.&lt;br /&gt;
|-&lt;br /&gt;
| Bignum [http://www.ruby-doc.org/core/Bignum.html]&lt;br /&gt;
| Integer representations that do not fit in Fixnum width&lt;br /&gt;
| Machine architecture dependent. Values above Fixnum range.&lt;br /&gt;
|-&lt;br /&gt;
| Float [http://www.ruby-doc.org/core/Float.html]&lt;br /&gt;
| Real numbers using double precision representation&lt;br /&gt;
| Value after decimal point can be formatted&lt;br /&gt;
|-&lt;br /&gt;
| String [http://corelib.rubyonrails.org/classes/String.html]&lt;br /&gt;
| Contains sequence of characters&lt;br /&gt;
| No physical limit, but can be decided by machine architecture&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
One interesting observation from the above table is that Ruby does not have a Boolean class; instead it has a separate TrueClass and FalseClass [http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby].&lt;br /&gt;
&lt;br /&gt;
  puts true.class &lt;br /&gt;
  =&amp;gt; TrueClass&lt;br /&gt;
  puts false.class&lt;br /&gt;
  =&amp;gt; FalseClass&lt;br /&gt;
&lt;br /&gt;
Although types such as Array, Hash are also in-built types, they can be further composed of elements that are internally represented in one of the primitive types. Hence, they will not be treated by us as primitive objects, in the traditional definition of the term.&lt;br /&gt;
Each of the primitive objects listed above also provide certain convenience methods that are applicable for the underlying type.&lt;br /&gt;
For example, the Fixnum, Bignum and Float types provide support for arithmetic operations such as addition (+), subtraction(--), multiplication(*) and so on.&lt;br /&gt;
As with all other classes in Ruby, users can add functionality to existing primitive objects by reopening classes. The amount of memory required to implement the primitive objects in Ruby is machine dependent in some cases.&lt;br /&gt;
&lt;br /&gt;
== Merit Analysis of Primitive Types ==&lt;br /&gt;
This section deals with a brief analysis of the relative merits and demerits of primitive data types. While we focus on Java or Ruby for this purpose, most of these points are applicable across all object oriented languages.&lt;br /&gt;
&lt;br /&gt;
=== Advantages ===&lt;br /&gt;
Primitive types in object oriented languages have certain advantages over their class object counterparts. &lt;br /&gt;
* Simplicity: Primitive types/objects provide users a simple mechanism of manipulating data without relying on additional objects to achieve the same functionality. Operations on primitive types are more intuitive.&lt;br /&gt;
* Efficiency: This statement is applicable if the underlying primitive object definition is not modified (a feature that languages such as Ruby provide to users). As the representation in memory is designed to be make most efficient use of the underlying datatype, use of primitives can provide a benefit to the user, over the use of class objects to store the same data. &lt;br /&gt;
  Eg. Java provides wrappers [http://www.glenmccl.com/tip_016.htm] for certain primitive types. There is a certain performance and space cost associated with these. &lt;br /&gt;
  So, to maximize efficiency, direct use of the primitive types would provide the most benefit.&lt;br /&gt;
* Ability to use inbuilt methods: Depending on the primitive type, languages such as Ruby provide methods that can be used specifically to probe or manipulate objects. &lt;br /&gt;
  Eg. [http://corelib.rubyonrails.org/classes/String.html String] primitive object provides convenience methods such as upcase to convert the entire string to upper case, or capitalize, which converts only the first character to upper case.&lt;br /&gt;
* Ease of testing for comparison: With primitive types, the equality testing operators such as == can be used. These essentially compare the values stored in the primitive types. Regular objects also offer the eql? method for testing equality. However, the following are not equivalent:&lt;br /&gt;
  a=10&lt;br /&gt;
  =&amp;gt; 10&lt;br /&gt;
  a==10&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a==10.0&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a.eql?(10.0)&lt;br /&gt;
  =&amp;gt; false&lt;br /&gt;
The reason the .eql? fails is that this operator tests for value and type being the same. 10 is type Fixnum and 10.0 is type Float. &lt;br /&gt;
The eql? can be overridden by == for primitive objects if you wish to compare only the values, but that can have a negative impact on performance [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html].&lt;br /&gt;
&lt;br /&gt;
=== Disadvantages ===&lt;br /&gt;
* Lack of inheritance capability: The primitive data types in languages such as Java cannot be inherited to create further subtypes.&lt;br /&gt;
* Unexpected results due to method overriding: There are certain examples such as [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html], which show that overriding inbuilt methods such as == and eql? can lead to unexpected results.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Object oriented languages have varying levels of support for primitive data types and objects. Whether they are beneficial or not depends on the application to a great deal. If handled correctly, they can make object oriented programs more efficient. However, the user needs to be aware of the underlying representation of these types to handle any unexpected results.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# http://en.wikipedia.org/wiki/Primitive_data_type&lt;br /&gt;
# http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php&lt;br /&gt;
# http://www.jk-technology.com/c/inttypes.html&lt;br /&gt;
# http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html&lt;br /&gt;
# http://newty.de/fpt/intro.html&lt;br /&gt;
# http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html&lt;br /&gt;
# http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx&lt;br /&gt;
# http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html&lt;br /&gt;
# http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html&lt;br /&gt;
# http://www.glenmccl.com/tip_016.htm&lt;br /&gt;
# http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54297</id>
		<title>CSC/ECE 517 Fall 2011/ch3 3h rr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54297"/>
		<updated>2011-10-29T21:59:22Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''3h. Primitive objects.  At the beginning of Lecture 11, we discovered that Fixnums and Bignums are handled differently behind the scenes in Ruby.  Other languages, like Java, have made similar distinctions.  By contrast, languages such as C# and Eiffel try to hide these implementation differences from users.  Answer two questions: (1) How have different o-o languages implemented primitive objects?  E.g., how are they represented in memory, how are they tested for, do comparisons do anything different than for class objects, etc.  (2) What are the advantages and disadvantages of treating primitives differently from class objects in source code?''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Programming languages, whether statically or dynamically typed, have support for certain in-built data types. These data types, known as primitive types, are the basic representation of information in programs and have certain fixed attributes for a specific language[http://en.wikipedia.org/wiki/Primitive_data_type]. Statically typed languages such as C++, Java, Perl etc. support primitive data types, whereas with dynamically typed languages such as Ruby, Smalltalk, Lisp etc. they are actually in the form of primitive objects.  These primitive types are used to store the basic types of information that a computer can store and manipulate, and can also be used as building blocks for creating more complex data types. &lt;br /&gt;
This article explains the way different primitive types are implemented in certain object oriented languages. An analysis of the benefits and drawbacks of such types and the methods used to operate on them is also presented. &lt;br /&gt;
&lt;br /&gt;
== Primitive Types ==&lt;br /&gt;
The primitive types commonly included in most programming languages are:&lt;br /&gt;
* Boolean&lt;br /&gt;
* Character&lt;br /&gt;
* Integer&lt;br /&gt;
* Floating-point number&lt;br /&gt;
* Fixed-point number&lt;br /&gt;
* Reference&lt;br /&gt;
&lt;br /&gt;
=== Boolean ===&lt;br /&gt;
A Boolean is a primitive data type used to store one of two logical types: true or false.  Boolean data types are most commonly used as input paramters to a conditional statement (such as an ‘if’ statement), or as the output of a comparison between two comparable data types.  Booleans can be implemented in languages as either a discrete logical type, or implicitly as a numerical type.  In many languages, booleans can be implicitly converted to and from integer types.  &lt;br /&gt;
&lt;br /&gt;
=== Character ===&lt;br /&gt;
A character is a data type that represents an element of a written language, such as a letter, number, or symbol.  A character can also represent a control character, such as a carriage return or newline, which does not have a written meaning but controls how other characters are stored or displayed.   Characters are commonly stored as integers, and encoded using a character map.  &lt;br /&gt;
&lt;br /&gt;
=== Integer ===&lt;br /&gt;
An integer is a data type that represents one element of a finite subset of mathematical integers.  Integer, or Integral, data types can be either unsigned (able to store only positive whole numbers) or signed (able to store either positive or negative whole numbers).  The range of values that can be represented by an integer depends on the number of bits used to store the integer, whether or not it is a signed integer, and the encoding scheme (if it is signed).  Typically, an integer has a minimum and maximum value, and can store any integer in the range between those values.  The minimum value for unsigned integers is typically 0, and the maximum value is typically determined by the amount of memory used to store the integer.  For example, a un unsigned 8-bit number can store 2^8 (or 256) possible integral values; and would typically store any value from 0 to 255.  More generally, an n-bit unsigned integer can store from 0 to (2^n)-1.  For signed integers, modern computers use the Two’s Complement encoding scheme.  This allows for a range of −2^(n−1) through 2^(n−1)−1.  For example, an 8-bit signed integer could store any whole number in the range from -128 through +127.&lt;br /&gt;
&lt;br /&gt;
=== Floating-Point Number ===&lt;br /&gt;
A floating point number is a data type used to represent real numbers in a large range with varying degrees of precision.  In this representation, numbers are represented with a variable number of significant digits, and a variable number of exponential digits.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed-Point number ===&lt;br /&gt;
A fixed-point number is a data type used to represent real numbers.  Fixed-point numbers are called fixed-point because they have a set number of digits before and after a decimal mark.  In this regard, fixed-point numbers are represented as an integer, but are scaled by a predetermined factor.  &lt;br /&gt;
&lt;br /&gt;
Fixed-point numbers are commonly used in microprocessors that do not have a floating-point unit, or in systems in which computational efficiency is critical.  Fixed-point numbers can be treated as integers by an arithmetic logic unit (ALU) and scaled after a result is obtained, which can significantly lower the amount of time needed for a processor to obtain the result for some algorithms. &lt;br /&gt;
&lt;br /&gt;
Implementing algorithms using fixed-point arithmetic requires great care, because of the potential for information loss.  Fixed-point arithmetic operations -- multiplication in particular, has the potential to cause overflow.  Algorithms must be written with care to ensure that each term of an equation has a similar range and that the result will not cause an overflow.&lt;br /&gt;
&lt;br /&gt;
=== Reference ===&lt;br /&gt;
&lt;br /&gt;
A Reference is a data type that enables a program to access another item in memory.  A reference differs from other primitive data types in that it does not store data itself; instead it stores a value referring to another data object.  References are commonly used to refer to objects of large non-primitive data types.  References commonly store the physical memory address of the data that they are referring to.  Accessing the data referred to by a Reference is called dereferencing.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C++ ==&lt;br /&gt;
&lt;br /&gt;
C++ is a statically-typed object oriented language.  C++ is based on the C programming language, which is procedural, and adds support for object-oriented code.  &lt;br /&gt;
&lt;br /&gt;
These data types are defined in C++: [http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php] &lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;20&amp;quot;&lt;br /&gt;
! Name &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| void &lt;br /&gt;
| N/A &lt;br /&gt;
| the void data type is used to explicitly identify that a data has no type &lt;br /&gt;
| N/A&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits&lt;br /&gt;
| simple numerical type&lt;br /&gt;
| See [[http://www.jk-technology.com/c/inttypes.html]]&lt;br /&gt;
|-&lt;br /&gt;
| float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 8 bits &lt;br /&gt;
| a char is a single 8-bit character encoded using ASCII &lt;br /&gt;
| Ascii character 0x00 through ascii character 0xFF&lt;br /&gt;
|}&lt;br /&gt;
C++ supports Pointers for all of the types listed in the table above, as well as more complex data types (such as structs).  A Pointer in C++ is a data type that stores the physical address of some other data.  Pointers are created in C++ by using the * operator.  For example, a *Double[] is a pointer to an array of double-precision floating point numbers.  C++ Also supports function pointers -- pointers that reference the beginning address of a function in memory.  They are commonly used to implement callback functions [http://newty.de/fpt/intro.html#what]&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in Java == &lt;br /&gt;
&lt;br /&gt;
Java is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  These data types are defined in Java: [http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html]&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;|Name&lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte&lt;br /&gt;
|8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
|128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
|16 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647 &lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Java also defines a String class, which is used to create objects of many chars.  The String class provides functionality commonly implemented using arrays of chars in other languages, such as C. &lt;br /&gt;
&lt;br /&gt;
Java also defines the 'unsigned' keyword, which can be used to as a modifier to any of the integral types listed in the table above.  If the 'unsigned' keyword is used, the integral type will be unsigned instead of signed, and its range will change correspondingly. &lt;br /&gt;
&lt;br /&gt;
Java is capable of using any two objects of the same primitive data type for comparison.  Java defines a class for each data type, which have the same name but a capitalized first letter (e.g. Float instead of float).  These classes, called wrapper classes provide a series of methods that can manipulate their associated primitive data type, as well as convert to and from other data types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C# == &lt;br /&gt;
&lt;br /&gt;
C# is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  C# has all of the data types that are available in Java, as well as some additional ones.  &lt;br /&gt;
&lt;br /&gt;
Similar to Java, C# defines a String class which is used to create objects of many chars.  These data types are defined in C#: [http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! .NET Class &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte &lt;br /&gt;
| Byte &lt;br /&gt;
| 8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
| -128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| sbyte &lt;br /&gt;
| SByte &lt;br /&gt;
| 8 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -0 to 255&lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
| Int16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| ushort &lt;br /&gt;
| UInt16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 65,535&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| Int32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647&lt;br /&gt;
|-&lt;br /&gt;
| uint &lt;br /&gt;
| UInt32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 4,294,967,295&lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| Int64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|-&lt;br /&gt;
| ulong &lt;br /&gt;
| UInt64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 18,446,744,073,709,551,615&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| Float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| -3.402823e38 to 3.02823e38&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| Double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| -1.79769313486232e308 to 1.79769313486232e308&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| Boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| Char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|-&lt;br /&gt;
| object &lt;br /&gt;
| Object &lt;br /&gt;
| N/A &lt;br /&gt;
| Object is the base type of all other types&lt;br /&gt;
| N/A &lt;br /&gt;
|-&lt;br /&gt;
| string &lt;br /&gt;
| String &lt;br /&gt;
| N/A &lt;br /&gt;
| String is the base type for a sequence of chars&lt;br /&gt;
| N/A &lt;br /&gt;
|-&lt;br /&gt;
| decimal &lt;br /&gt;
| Decimal &lt;br /&gt;
| 128 &lt;br /&gt;
| Decimal is an integral type that can represent a decimal number with 29 significant digits &lt;br /&gt;
| ±1.0 × 10e−28 to ±7.9 × 10e28&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Like Java, each primitive data type in C# also has a class associated with it that.  These classes serve a similar purpose to their associated ones in Java.  They are used for comparison of objects, as well as conversion between other similar types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Objects in Ruby ==&lt;br /&gt;
Ruby is a pure object oriented language as compared to languages such as Java or C#, which use a more hybrid approach. In Ruby, all data types are represented as Objects. There are some [http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html inbuilt classes] that are provided to users in Ruby. However, only some of them are a basic building block for forming other types. This subset shown below gives us a list of primitive objects that can be used for data representation and manipulation:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! Description&lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| TrueClass&lt;br /&gt;
| Singleton instance &amp;quot;true&amp;quot; allowed&lt;br /&gt;
| true&lt;br /&gt;
|-&lt;br /&gt;
| FalseClass&lt;br /&gt;
| Singleton instance &amp;quot;false&amp;quot; allowed&lt;br /&gt;
| false&lt;br /&gt;
|-&lt;br /&gt;
| Integer [http://www.ruby-doc.org/core/Integer.html]&lt;br /&gt;
| Abstract class that forms the basis for Fixnum and Bignum&lt;br /&gt;
| See Fixnum and Bignum&lt;br /&gt;
|-&lt;br /&gt;
| Fixnum [http://www.ruby-doc.org/core-1.8.7/Fixnum.html]&lt;br /&gt;
| Integer representations that fit in native machine word&lt;br /&gt;
| Machine architecture dependent. 2^30-1 to -2^30 on 32-bit machines.&lt;br /&gt;
|-&lt;br /&gt;
| Bignum [http://www.ruby-doc.org/core/Bignum.html]&lt;br /&gt;
| Integer representations that do not fit in Fixnum width&lt;br /&gt;
| Machine architecture dependent. Values above Fixnum range.&lt;br /&gt;
|-&lt;br /&gt;
| Float [http://www.ruby-doc.org/core/Float.html]&lt;br /&gt;
| Real numbers using double precision representation&lt;br /&gt;
| Value after decimal point can be formatted&lt;br /&gt;
|-&lt;br /&gt;
| String [http://corelib.rubyonrails.org/classes/String.html]&lt;br /&gt;
| Contains sequence of characters&lt;br /&gt;
| No physical limit, but can be decided by machine architecture&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
One interesting observation from the above table is that Ruby does not have a Boolean class; instead it has a separate TrueClass and FalseClass [http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby].&lt;br /&gt;
&lt;br /&gt;
  puts true.class &lt;br /&gt;
  =&amp;gt; TrueClass&lt;br /&gt;
  puts false.class&lt;br /&gt;
  =&amp;gt; FalseClass&lt;br /&gt;
&lt;br /&gt;
Although types such as Array, Hash are also in-built types, they can be further composed of elements that are internally represented in one of the primitive types. Hence, they will not be treated by us as primitive objects, in the traditional definition of the term.&lt;br /&gt;
Each of the primitive objects listed above also provide certain convenience methods that are applicable for the underlying type.&lt;br /&gt;
For example, the Fixnum, Bignum and Float types provide support for arithmetic operations such as addition (+), subtraction(--), multiplication(*) and so on.&lt;br /&gt;
As with all other classes in Ruby, users can add functionality to existing primitive objects by reopening classes. The amount of memory required to implement the primitive objects in Ruby is machine dependent in some cases.&lt;br /&gt;
&lt;br /&gt;
== Merit Analysis of Primitive Types ==&lt;br /&gt;
This section deals with a brief analysis of the relative merits and demerits of primitive data types. While we focus on Java or Ruby for this purpose, most of these points are applicable across all object oriented languages.&lt;br /&gt;
&lt;br /&gt;
=== Advantages ===&lt;br /&gt;
Primitive types in object oriented languages have certain advantages over their class object counterparts. &lt;br /&gt;
* Simplicity: Primitive types/objects provide users a simple mechanism of manipulating data without relying on additional objects to achieve the same functionality. Operations on primitive types are more intuitive.&lt;br /&gt;
* Efficiency: This statement is applicable if the underlying primitive object definition is not modified (a feature that languages such as Ruby provide to users). As the representation in memory is designed to be make most efficient use of the underlying datatype, use of primitives can provide a benefit to the user, over the use of class objects to store the same data. &lt;br /&gt;
  Eg. Java provides wrappers [http://www.glenmccl.com/tip_016.htm] for certain primitive types. There is a certain performance and space cost associated with these. &lt;br /&gt;
  So, to maximize efficiency, direct use of the primitive types would provide the most benefit.&lt;br /&gt;
* Ability to use inbuilt methods: Depending on the primitive type, languages such as Ruby provide methods that can be used specifically to probe or manipulate objects. &lt;br /&gt;
  Eg. [http://corelib.rubyonrails.org/classes/String.html String] primitive object provides convenience methods such as upcase to convert the entire string to upper case, or capitalize, which converts only the first character to upper case.&lt;br /&gt;
* Ease of testing for comparison: With primitive types, the equality testing operators such as == can be used. These essentially compare the values stored in the primitive types. Regular objects also offer the eql? method for testing equality. However, the following are not equivalent:&lt;br /&gt;
  a=10&lt;br /&gt;
  =&amp;gt; 10&lt;br /&gt;
  a==10&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a==10.0&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a.eql?(10.0)&lt;br /&gt;
  =&amp;gt; false&lt;br /&gt;
The reason the .eql? fails is that this operator tests for value and type being the same. 10 is type Fixnum and 10.0 is type Float. &lt;br /&gt;
The eql? can be overridden by == for primitive objects if you wish to compare only the values, but that can have a negative impact on performance [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html].&lt;br /&gt;
&lt;br /&gt;
=== Disadvantages ===&lt;br /&gt;
* Lack of inheritance capability: The primitive data types in languages such as Java cannot be inherited to create further subtypes.&lt;br /&gt;
* Unexpected results due to method overriding: There are certain examples such as [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html], which show that overriding inbuilt methods such as == and eql? can lead to unexpected results.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Object oriented languages have varying levels of support for primitive data types and objects. Whether they are beneficial or not depends on the application to a great deal. If handled correctly, they can make object oriented programs more efficient. However, the user needs to be aware of the underlying representation of these types to handle any unexpected results.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# http://en.wikipedia.org/wiki/Primitive_data_type&lt;br /&gt;
# http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php&lt;br /&gt;
# http://www.jk-technology.com/c/inttypes.html&lt;br /&gt;
# http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html&lt;br /&gt;
# http://newty.de/fpt/intro.html&lt;br /&gt;
# http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html&lt;br /&gt;
# http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx&lt;br /&gt;
# http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html&lt;br /&gt;
# http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html&lt;br /&gt;
# http://www.glenmccl.com/tip_016.htm&lt;br /&gt;
# http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54296</id>
		<title>CSC/ECE 517 Fall 2011/ch3 3h rr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54296"/>
		<updated>2011-10-29T21:58:57Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''3h. Primitive objects.  At the beginning of Lecture 11, we discovered that Fixnums and Bignums are handled differently behind the scenes in Ruby.  Other languages, like Java, have made similar distinctions.  By contrast, languages such as C# and Eiffel try to hide these implementation differences from users.  Answer two questions: (1) How have different o-o languages implemented primitive objects?  E.g., how are they represented in memory, how are they tested for, do comparisons do anything different than for class objects, etc.  (2) What are the advantages and disadvantages of treating primitives differently from class objects in source code?''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Programming languages, whether statically or dynamically typed, have support for certain in-built data types. These data types, known as primitive types, are the basic representation of information in programs and have certain fixed attributes for a specific language[http://en.wikipedia.org/wiki/Primitive_data_type]. Statically typed languages such as C++, Java, Perl etc. support primitive data types, whereas with dynamically typed languages such as Ruby, Smalltalk, Lisp etc. they are actually in the form of primitive objects.  These primitive types are used to store the basic types of information that a computer can store and manipulate, and can also be used as building blocks for creating more complex data types. &lt;br /&gt;
This article explains the way different primitive types are implemented in certain object oriented languages. An analysis of the benefits and drawbacks of such types and the methods used to operate on them is also presented. &lt;br /&gt;
&lt;br /&gt;
== Primitive Types ==&lt;br /&gt;
The primitive types commonly included in most programming languages are:&lt;br /&gt;
* Boolean&lt;br /&gt;
* Character&lt;br /&gt;
* Integer&lt;br /&gt;
* Floating-point number&lt;br /&gt;
* Fixed-point number&lt;br /&gt;
* Reference&lt;br /&gt;
&lt;br /&gt;
=== Boolean ===&lt;br /&gt;
A Boolean is a primitive data type used to store one of two logical types: true or false.  Boolean data types are most commonly used as input paramters to a conditional statement (such as an ‘if’ statement), or as the output of a comparison between two comparable data types.  Booleans can be implemented in languages as either a discrete logical type, or implicitly as a numerical type.  In many languages, booleans can be implicitly converted to and from integer types.  &lt;br /&gt;
&lt;br /&gt;
=== Character ===&lt;br /&gt;
A character is a data type that represents an element of a written language, such as a letter, number, or symbol.  A character can also represent a control character, such as a carriage return or newline, which does not have a written meaning but controls how other characters are stored or displayed.   Characters are commonly stored as integers, and encoded using a character map.  &lt;br /&gt;
&lt;br /&gt;
=== Integer ===&lt;br /&gt;
An integer is a data type that represents one element of a finite subset of mathematical integers.  Integer, or Integral, data types can be either unsigned (able to store only positive whole numbers) or signed (able to store either positive or negative whole numbers).  The range of values that can be represented by an integer depends on the number of bits used to store the integer, whether or not it is a signed integer, and the encoding scheme (if it is signed).  Typically, an integer has a minimum and maximum value, and can store any integer in the range between those values.  The minimum value for unsigned integers is typically 0, and the maximum value is typically determined by the amount of memory used to store the integer.  For example, a un unsigned 8-bit number can store 2^8 (or 256) possible integral values; and would typically store any value from 0 to 255.  More generally, an n-bit unsigned integer can store from 0 to (2^n)-1.  For signed integers, modern computers use the Two’s Complement encoding scheme.  This allows for a range of −2^(n−1) through 2^(n−1)−1.  For example, an 8-bit signed integer could store any whole number in the range from -128 through +127.&lt;br /&gt;
&lt;br /&gt;
=== Floating-Point Number ===&lt;br /&gt;
A floating point number is a data type used to represent real numbers in a large range with varying degrees of precision.  In this representation, numbers are represented with a variable number of significant digits, and a variable number of exponential digits.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed-Point number ===&lt;br /&gt;
A fixed-point number is a data type used to represent real numbers.  Fixed-point numbers are called fixed-point because they have a set number of digits before and after a decimal mark.  In this regard, fixed-point numbers are represented as an integer, but are scaled by a predetermined factor.  &lt;br /&gt;
&lt;br /&gt;
Fixed-point numbers are commonly used in microprocessors that do not have a floating-point unit, or in systems in which computational efficiency is critical.  Fixed-point numbers can be treated as integers by an arithmetic logic unit (ALU) and scaled after a result is obtained, which can significantly lower the amount of time needed for a processor to obtain the result for some algorithms. &lt;br /&gt;
&lt;br /&gt;
Implementing algorithms using fixed-point arithmetic requires great care, because of the potential for information loss.  Fixed-point arithmetic operations -- multiplication in particular, has the potential to cause overflow.  Algorithms must be written with care to ensure that each term of an equation has a similar range and that the result will not cause an overflow.&lt;br /&gt;
&lt;br /&gt;
=== Reference ===&lt;br /&gt;
&lt;br /&gt;
A Reference is a data type that enables a program to access another item in memory.  A reference differs from other primitive data types in that it does not store data itself; instead it stores a value referring to another data object.  References are commonly used to refer to objects of large non-primitive data types.  References commonly store the physical memory address of the data that they are referring to.  Accessing the data referred to by a Reference is called dereferencing.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C++ ==&lt;br /&gt;
&lt;br /&gt;
C++ is a statically-typed object oriented language.  C++ is based on the C programming language, which is procedural, and adds support for object-oriented code.  &lt;br /&gt;
&lt;br /&gt;
These data types are defined in C++: [http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php] &lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot; cellpadding=&amp;quot;2&amp;quot;&lt;br /&gt;
! Name &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| void &lt;br /&gt;
| N/A &lt;br /&gt;
| the void data type is used to explicitly identify that a data has no type &lt;br /&gt;
| N/A&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits&lt;br /&gt;
| simple numerical type&lt;br /&gt;
| See [[http://www.jk-technology.com/c/inttypes.html]]&lt;br /&gt;
|-&lt;br /&gt;
| float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 8 bits &lt;br /&gt;
| a char is a single 8-bit character encoded using ASCII &lt;br /&gt;
| Ascii character 0x00 through ascii character 0xFF&lt;br /&gt;
|}&lt;br /&gt;
C++ supports Pointers for all of the types listed in the table above, as well as more complex data types (such as structs).  A Pointer in C++ is a data type that stores the physical address of some other data.  Pointers are created in C++ by using the * operator.  For example, a *Double[] is a pointer to an array of double-precision floating point numbers.  C++ Also supports function pointers -- pointers that reference the beginning address of a function in memory.  They are commonly used to implement callback functions [http://newty.de/fpt/intro.html#what]&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in Java == &lt;br /&gt;
&lt;br /&gt;
Java is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  These data types are defined in Java: [http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html]&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;|Name&lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte&lt;br /&gt;
|8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
|128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
|16 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647 &lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Java also defines a String class, which is used to create objects of many chars.  The String class provides functionality commonly implemented using arrays of chars in other languages, such as C. &lt;br /&gt;
&lt;br /&gt;
Java also defines the 'unsigned' keyword, which can be used to as a modifier to any of the integral types listed in the table above.  If the 'unsigned' keyword is used, the integral type will be unsigned instead of signed, and its range will change correspondingly. &lt;br /&gt;
&lt;br /&gt;
Java is capable of using any two objects of the same primitive data type for comparison.  Java defines a class for each data type, which have the same name but a capitalized first letter (e.g. Float instead of float).  These classes, called wrapper classes provide a series of methods that can manipulate their associated primitive data type, as well as convert to and from other data types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C# == &lt;br /&gt;
&lt;br /&gt;
C# is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  C# has all of the data types that are available in Java, as well as some additional ones.  &lt;br /&gt;
&lt;br /&gt;
Similar to Java, C# defines a String class which is used to create objects of many chars.  These data types are defined in C#: [http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! .NET Class &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte &lt;br /&gt;
| Byte &lt;br /&gt;
| 8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
| -128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| sbyte &lt;br /&gt;
| SByte &lt;br /&gt;
| 8 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -0 to 255&lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
| Int16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| ushort &lt;br /&gt;
| UInt16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 65,535&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| Int32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647&lt;br /&gt;
|-&lt;br /&gt;
| uint &lt;br /&gt;
| UInt32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 4,294,967,295&lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| Int64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|-&lt;br /&gt;
| ulong &lt;br /&gt;
| UInt64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 18,446,744,073,709,551,615&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| Float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| -3.402823e38 to 3.02823e38&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| Double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| -1.79769313486232e308 to 1.79769313486232e308&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| Boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| Char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|-&lt;br /&gt;
| object &lt;br /&gt;
| Object &lt;br /&gt;
| N/A &lt;br /&gt;
| Object is the base type of all other types&lt;br /&gt;
| N/A &lt;br /&gt;
|-&lt;br /&gt;
| string &lt;br /&gt;
| String &lt;br /&gt;
| N/A &lt;br /&gt;
| String is the base type for a sequence of chars&lt;br /&gt;
| N/A &lt;br /&gt;
|-&lt;br /&gt;
| decimal &lt;br /&gt;
| Decimal &lt;br /&gt;
| 128 &lt;br /&gt;
| Decimal is an integral type that can represent a decimal number with 29 significant digits &lt;br /&gt;
| ±1.0 × 10e−28 to ±7.9 × 10e28&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Like Java, each primitive data type in C# also has a class associated with it that.  These classes serve a similar purpose to their associated ones in Java.  They are used for comparison of objects, as well as conversion between other similar types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Objects in Ruby ==&lt;br /&gt;
Ruby is a pure object oriented language as compared to languages such as Java or C#, which use a more hybrid approach. In Ruby, all data types are represented as Objects. There are some [http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html inbuilt classes] that are provided to users in Ruby. However, only some of them are a basic building block for forming other types. This subset shown below gives us a list of primitive objects that can be used for data representation and manipulation:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! Description&lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| TrueClass&lt;br /&gt;
| Singleton instance &amp;quot;true&amp;quot; allowed&lt;br /&gt;
| true&lt;br /&gt;
|-&lt;br /&gt;
| FalseClass&lt;br /&gt;
| Singleton instance &amp;quot;false&amp;quot; allowed&lt;br /&gt;
| false&lt;br /&gt;
|-&lt;br /&gt;
| Integer [http://www.ruby-doc.org/core/Integer.html]&lt;br /&gt;
| Abstract class that forms the basis for Fixnum and Bignum&lt;br /&gt;
| See Fixnum and Bignum&lt;br /&gt;
|-&lt;br /&gt;
| Fixnum [http://www.ruby-doc.org/core-1.8.7/Fixnum.html]&lt;br /&gt;
| Integer representations that fit in native machine word&lt;br /&gt;
| Machine architecture dependent. 2^30-1 to -2^30 on 32-bit machines.&lt;br /&gt;
|-&lt;br /&gt;
| Bignum [http://www.ruby-doc.org/core/Bignum.html]&lt;br /&gt;
| Integer representations that do not fit in Fixnum width&lt;br /&gt;
| Machine architecture dependent. Values above Fixnum range.&lt;br /&gt;
|-&lt;br /&gt;
| Float [http://www.ruby-doc.org/core/Float.html]&lt;br /&gt;
| Real numbers using double precision representation&lt;br /&gt;
| Value after decimal point can be formatted&lt;br /&gt;
|-&lt;br /&gt;
| String [http://corelib.rubyonrails.org/classes/String.html]&lt;br /&gt;
| Contains sequence of characters&lt;br /&gt;
| No physical limit, but can be decided by machine architecture&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
One interesting observation from the above table is that Ruby does not have a Boolean class; instead it has a separate TrueClass and FalseClass [http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby].&lt;br /&gt;
&lt;br /&gt;
  puts true.class &lt;br /&gt;
  =&amp;gt; TrueClass&lt;br /&gt;
  puts false.class&lt;br /&gt;
  =&amp;gt; FalseClass&lt;br /&gt;
&lt;br /&gt;
Although types such as Array, Hash are also in-built types, they can be further composed of elements that are internally represented in one of the primitive types. Hence, they will not be treated by us as primitive objects, in the traditional definition of the term.&lt;br /&gt;
Each of the primitive objects listed above also provide certain convenience methods that are applicable for the underlying type.&lt;br /&gt;
For example, the Fixnum, Bignum and Float types provide support for arithmetic operations such as addition (+), subtraction(--), multiplication(*) and so on.&lt;br /&gt;
As with all other classes in Ruby, users can add functionality to existing primitive objects by reopening classes. The amount of memory required to implement the primitive objects in Ruby is machine dependent in some cases.&lt;br /&gt;
&lt;br /&gt;
== Merit Analysis of Primitive Types ==&lt;br /&gt;
This section deals with a brief analysis of the relative merits and demerits of primitive data types. While we focus on Java or Ruby for this purpose, most of these points are applicable across all object oriented languages.&lt;br /&gt;
&lt;br /&gt;
=== Advantages ===&lt;br /&gt;
Primitive types in object oriented languages have certain advantages over their class object counterparts. &lt;br /&gt;
* Simplicity: Primitive types/objects provide users a simple mechanism of manipulating data without relying on additional objects to achieve the same functionality. Operations on primitive types are more intuitive.&lt;br /&gt;
* Efficiency: This statement is applicable if the underlying primitive object definition is not modified (a feature that languages such as Ruby provide to users). As the representation in memory is designed to be make most efficient use of the underlying datatype, use of primitives can provide a benefit to the user, over the use of class objects to store the same data. &lt;br /&gt;
  Eg. Java provides wrappers [http://www.glenmccl.com/tip_016.htm] for certain primitive types. There is a certain performance and space cost associated with these. &lt;br /&gt;
  So, to maximize efficiency, direct use of the primitive types would provide the most benefit.&lt;br /&gt;
* Ability to use inbuilt methods: Depending on the primitive type, languages such as Ruby provide methods that can be used specifically to probe or manipulate objects. &lt;br /&gt;
  Eg. [http://corelib.rubyonrails.org/classes/String.html String] primitive object provides convenience methods such as upcase to convert the entire string to upper case, or capitalize, which converts only the first character to upper case.&lt;br /&gt;
* Ease of testing for comparison: With primitive types, the equality testing operators such as == can be used. These essentially compare the values stored in the primitive types. Regular objects also offer the eql? method for testing equality. However, the following are not equivalent:&lt;br /&gt;
  a=10&lt;br /&gt;
  =&amp;gt; 10&lt;br /&gt;
  a==10&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a==10.0&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a.eql?(10.0)&lt;br /&gt;
  =&amp;gt; false&lt;br /&gt;
The reason the .eql? fails is that this operator tests for value and type being the same. 10 is type Fixnum and 10.0 is type Float. &lt;br /&gt;
The eql? can be overridden by == for primitive objects if you wish to compare only the values, but that can have a negative impact on performance [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html].&lt;br /&gt;
&lt;br /&gt;
=== Disadvantages ===&lt;br /&gt;
* Lack of inheritance capability: The primitive data types in languages such as Java cannot be inherited to create further subtypes.&lt;br /&gt;
* Unexpected results due to method overriding: There are certain examples such as [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html], which show that overriding inbuilt methods such as == and eql? can lead to unexpected results.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Object oriented languages have varying levels of support for primitive data types and objects. Whether they are beneficial or not depends on the application to a great deal. If handled correctly, they can make object oriented programs more efficient. However, the user needs to be aware of the underlying representation of these types to handle any unexpected results.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# http://en.wikipedia.org/wiki/Primitive_data_type&lt;br /&gt;
# http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php&lt;br /&gt;
# http://www.jk-technology.com/c/inttypes.html&lt;br /&gt;
# http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html&lt;br /&gt;
# http://newty.de/fpt/intro.html&lt;br /&gt;
# http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html&lt;br /&gt;
# http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx&lt;br /&gt;
# http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html&lt;br /&gt;
# http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html&lt;br /&gt;
# http://www.glenmccl.com/tip_016.htm&lt;br /&gt;
# http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54295</id>
		<title>CSC/ECE 517 Fall 2011/ch3 3h rr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54295"/>
		<updated>2011-10-29T21:58:17Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''3h. Primitive objects.  At the beginning of Lecture 11, we discovered that Fixnums and Bignums are handled differently behind the scenes in Ruby.  Other languages, like Java, have made similar distinctions.  By contrast, languages such as C# and Eiffel try to hide these implementation differences from users.  Answer two questions: (1) How have different o-o languages implemented primitive objects?  E.g., how are they represented in memory, how are they tested for, do comparisons do anything different than for class objects, etc.  (2) What are the advantages and disadvantages of treating primitives differently from class objects in source code?''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Programming languages, whether statically or dynamically typed, have support for certain in-built data types. These data types, known as primitive types, are the basic representation of information in programs and have certain fixed attributes for a specific language[http://en.wikipedia.org/wiki/Primitive_data_type]. Statically typed languages such as C++, Java, Perl etc. support primitive data types, whereas with dynamically typed languages such as Ruby, Smalltalk, Lisp etc. they are actually in the form of primitive objects.  These primitive types are used to store the basic types of information that a computer can store and manipulate, and can also be used as building blocks for creating more complex data types. &lt;br /&gt;
This article explains the way different primitive types are implemented in certain object oriented languages. An analysis of the benefits and drawbacks of such types and the methods used to operate on them is also presented. &lt;br /&gt;
&lt;br /&gt;
== Primitive Types ==&lt;br /&gt;
The primitive types commonly included in most programming languages are:&lt;br /&gt;
* Boolean&lt;br /&gt;
* Character&lt;br /&gt;
* Integer&lt;br /&gt;
* Floating-point number&lt;br /&gt;
* Fixed-point number&lt;br /&gt;
* Reference&lt;br /&gt;
&lt;br /&gt;
=== Boolean ===&lt;br /&gt;
A Boolean is a primitive data type used to store one of two logical types: true or false.  Boolean data types are most commonly used as input paramters to a conditional statement (such as an ‘if’ statement), or as the output of a comparison between two comparable data types.  Booleans can be implemented in languages as either a discrete logical type, or implicitly as a numerical type.  In many languages, booleans can be implicitly converted to and from integer types.  &lt;br /&gt;
&lt;br /&gt;
=== Character ===&lt;br /&gt;
A character is a data type that represents an element of a written language, such as a letter, number, or symbol.  A character can also represent a control character, such as a carriage return or newline, which does not have a written meaning but controls how other characters are stored or displayed.   Characters are commonly stored as integers, and encoded using a character map.  &lt;br /&gt;
&lt;br /&gt;
=== Integer ===&lt;br /&gt;
An integer is a data type that represents one element of a finite subset of mathematical integers.  Integer, or Integral, data types can be either unsigned (able to store only positive whole numbers) or signed (able to store either positive or negative whole numbers).  The range of values that can be represented by an integer depends on the number of bits used to store the integer, whether or not it is a signed integer, and the encoding scheme (if it is signed).  Typically, an integer has a minimum and maximum value, and can store any integer in the range between those values.  The minimum value for unsigned integers is typically 0, and the maximum value is typically determined by the amount of memory used to store the integer.  For example, a un unsigned 8-bit number can store 2^8 (or 256) possible integral values; and would typically store any value from 0 to 255.  More generally, an n-bit unsigned integer can store from 0 to (2^n)-1.  For signed integers, modern computers use the Two’s Complement encoding scheme.  This allows for a range of −2^(n−1) through 2^(n−1)−1.  For example, an 8-bit signed integer could store any whole number in the range from -128 through +127.&lt;br /&gt;
&lt;br /&gt;
=== Floating-Point Number ===&lt;br /&gt;
A floating point number is a data type used to represent real numbers in a large range with varying degrees of precision.  In this representation, numbers are represented with a variable number of significant digits, and a variable number of exponential digits.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed-Point number ===&lt;br /&gt;
A fixed-point number is a data type used to represent real numbers.  Fixed-point numbers are called fixed-point because they have a set number of digits before and after a decimal mark.  In this regard, fixed-point numbers are represented as an integer, but are scaled by a predetermined factor.  &lt;br /&gt;
&lt;br /&gt;
Fixed-point numbers are commonly used in microprocessors that do not have a floating-point unit, or in systems in which computational efficiency is critical.  Fixed-point numbers can be treated as integers by an arithmetic logic unit (ALU) and scaled after a result is obtained, which can significantly lower the amount of time needed for a processor to obtain the result for some algorithms. &lt;br /&gt;
&lt;br /&gt;
Implementing algorithms using fixed-point arithmetic requires great care, because of the potential for information loss.  Fixed-point arithmetic operations -- multiplication in particular, has the potential to cause overflow.  Algorithms must be written with care to ensure that each term of an equation has a similar range and that the result will not cause an overflow.&lt;br /&gt;
&lt;br /&gt;
=== Reference ===&lt;br /&gt;
&lt;br /&gt;
A Reference is a data type that enables a program to access another item in memory.  A reference differs from other primitive data types in that it does not store data itself; instead it stores a value referring to another data object.  References are commonly used to refer to objects of large non-primitive data types.  References commonly store the physical memory address of the data that they are referring to.  Accessing the data referred to by a Reference is called dereferencing.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C++ ==&lt;br /&gt;
&lt;br /&gt;
C++ is a statically-typed object oriented language.  C++ is based on the C programming language, which is procedural, and adds support for object-oriented code.  &lt;br /&gt;
&lt;br /&gt;
These data types are defined in C++: [http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php] &lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0; cellpadding=2&amp;quot;&lt;br /&gt;
! Name &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| void &lt;br /&gt;
| N/A &lt;br /&gt;
| the void data type is used to explicitly identify that a data has no type &lt;br /&gt;
| N/A&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits&lt;br /&gt;
| simple numerical type&lt;br /&gt;
| See [[http://www.jk-technology.com/c/inttypes.html]]&lt;br /&gt;
|-&lt;br /&gt;
| float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 8 bits &lt;br /&gt;
| a char is a single 8-bit character encoded using ASCII &lt;br /&gt;
| Ascii character 0x00 through ascii character 0xFF&lt;br /&gt;
|}&lt;br /&gt;
C++ supports Pointers for all of the types listed in the table above, as well as more complex data types (such as structs).  A Pointer in C++ is a data type that stores the physical address of some other data.  Pointers are created in C++ by using the * operator.  For example, a *Double[] is a pointer to an array of double-precision floating point numbers.  C++ Also supports function pointers -- pointers that reference the beginning address of a function in memory.  They are commonly used to implement callback functions [http://newty.de/fpt/intro.html#what]&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in Java == &lt;br /&gt;
&lt;br /&gt;
Java is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  These data types are defined in Java: [http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html]&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;|Name&lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte&lt;br /&gt;
|8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
|128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
|16 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647 &lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Java also defines a String class, which is used to create objects of many chars.  The String class provides functionality commonly implemented using arrays of chars in other languages, such as C. &lt;br /&gt;
&lt;br /&gt;
Java also defines the 'unsigned' keyword, which can be used to as a modifier to any of the integral types listed in the table above.  If the 'unsigned' keyword is used, the integral type will be unsigned instead of signed, and its range will change correspondingly. &lt;br /&gt;
&lt;br /&gt;
Java is capable of using any two objects of the same primitive data type for comparison.  Java defines a class for each data type, which have the same name but a capitalized first letter (e.g. Float instead of float).  These classes, called wrapper classes provide a series of methods that can manipulate their associated primitive data type, as well as convert to and from other data types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C# == &lt;br /&gt;
&lt;br /&gt;
C# is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  C# has all of the data types that are available in Java, as well as some additional ones.  &lt;br /&gt;
&lt;br /&gt;
Similar to Java, C# defines a String class which is used to create objects of many chars.  These data types are defined in C#: [http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! .NET Class &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte &lt;br /&gt;
| Byte &lt;br /&gt;
| 8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
| -128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| sbyte &lt;br /&gt;
| SByte &lt;br /&gt;
| 8 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -0 to 255&lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
| Int16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| ushort &lt;br /&gt;
| UInt16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 65,535&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| Int32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647&lt;br /&gt;
|-&lt;br /&gt;
| uint &lt;br /&gt;
| UInt32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 4,294,967,295&lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| Int64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|-&lt;br /&gt;
| ulong &lt;br /&gt;
| UInt64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 18,446,744,073,709,551,615&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| Float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| -3.402823e38 to 3.02823e38&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| Double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| -1.79769313486232e308 to 1.79769313486232e308&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| Boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| Char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|-&lt;br /&gt;
| object &lt;br /&gt;
| Object &lt;br /&gt;
| N/A &lt;br /&gt;
| Object is the base type of all other types&lt;br /&gt;
| N/A &lt;br /&gt;
|-&lt;br /&gt;
| string &lt;br /&gt;
| String &lt;br /&gt;
| N/A &lt;br /&gt;
| String is the base type for a sequence of chars&lt;br /&gt;
| N/A &lt;br /&gt;
|-&lt;br /&gt;
| decimal &lt;br /&gt;
| Decimal &lt;br /&gt;
| 128 &lt;br /&gt;
| Decimal is an integral type that can represent a decimal number with 29 significant digits &lt;br /&gt;
| ±1.0 × 10e−28 to ±7.9 × 10e28&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Like Java, each primitive data type in C# also has a class associated with it that.  These classes serve a similar purpose to their associated ones in Java.  They are used for comparison of objects, as well as conversion between other similar types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Objects in Ruby ==&lt;br /&gt;
Ruby is a pure object oriented language as compared to languages such as Java or C#, which use a more hybrid approach. In Ruby, all data types are represented as Objects. There are some [http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html inbuilt classes] that are provided to users in Ruby. However, only some of them are a basic building block for forming other types. This subset shown below gives us a list of primitive objects that can be used for data representation and manipulation:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! Description&lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| TrueClass&lt;br /&gt;
| Singleton instance &amp;quot;true&amp;quot; allowed&lt;br /&gt;
| true&lt;br /&gt;
|-&lt;br /&gt;
| FalseClass&lt;br /&gt;
| Singleton instance &amp;quot;false&amp;quot; allowed&lt;br /&gt;
| false&lt;br /&gt;
|-&lt;br /&gt;
| Integer [http://www.ruby-doc.org/core/Integer.html]&lt;br /&gt;
| Abstract class that forms the basis for Fixnum and Bignum&lt;br /&gt;
| See Fixnum and Bignum&lt;br /&gt;
|-&lt;br /&gt;
| Fixnum [http://www.ruby-doc.org/core-1.8.7/Fixnum.html]&lt;br /&gt;
| Integer representations that fit in native machine word&lt;br /&gt;
| Machine architecture dependent. 2^30-1 to -2^30 on 32-bit machines.&lt;br /&gt;
|-&lt;br /&gt;
| Bignum [http://www.ruby-doc.org/core/Bignum.html]&lt;br /&gt;
| Integer representations that do not fit in Fixnum width&lt;br /&gt;
| Machine architecture dependent. Values above Fixnum range.&lt;br /&gt;
|-&lt;br /&gt;
| Float [http://www.ruby-doc.org/core/Float.html]&lt;br /&gt;
| Real numbers using double precision representation&lt;br /&gt;
| Value after decimal point can be formatted&lt;br /&gt;
|-&lt;br /&gt;
| String [http://corelib.rubyonrails.org/classes/String.html]&lt;br /&gt;
| Contains sequence of characters&lt;br /&gt;
| No physical limit, but can be decided by machine architecture&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
One interesting observation from the above table is that Ruby does not have a Boolean class; instead it has a separate TrueClass and FalseClass [http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby].&lt;br /&gt;
&lt;br /&gt;
  puts true.class &lt;br /&gt;
  =&amp;gt; TrueClass&lt;br /&gt;
  puts false.class&lt;br /&gt;
  =&amp;gt; FalseClass&lt;br /&gt;
&lt;br /&gt;
Although types such as Array, Hash are also in-built types, they can be further composed of elements that are internally represented in one of the primitive types. Hence, they will not be treated by us as primitive objects, in the traditional definition of the term.&lt;br /&gt;
Each of the primitive objects listed above also provide certain convenience methods that are applicable for the underlying type.&lt;br /&gt;
For example, the Fixnum, Bignum and Float types provide support for arithmetic operations such as addition (+), subtraction(--), multiplication(*) and so on.&lt;br /&gt;
As with all other classes in Ruby, users can add functionality to existing primitive objects by reopening classes. The amount of memory required to implement the primitive objects in Ruby is machine dependent in some cases.&lt;br /&gt;
&lt;br /&gt;
== Merit Analysis of Primitive Types ==&lt;br /&gt;
This section deals with a brief analysis of the relative merits and demerits of primitive data types. While we focus on Java or Ruby for this purpose, most of these points are applicable across all object oriented languages.&lt;br /&gt;
&lt;br /&gt;
=== Advantages ===&lt;br /&gt;
Primitive types in object oriented languages have certain advantages over their class object counterparts. &lt;br /&gt;
* Simplicity: Primitive types/objects provide users a simple mechanism of manipulating data without relying on additional objects to achieve the same functionality. Operations on primitive types are more intuitive.&lt;br /&gt;
* Efficiency: This statement is applicable if the underlying primitive object definition is not modified (a feature that languages such as Ruby provide to users). As the representation in memory is designed to be make most efficient use of the underlying datatype, use of primitives can provide a benefit to the user, over the use of class objects to store the same data. &lt;br /&gt;
  Eg. Java provides wrappers [http://www.glenmccl.com/tip_016.htm] for certain primitive types. There is a certain performance and space cost associated with these. &lt;br /&gt;
  So, to maximize efficiency, direct use of the primitive types would provide the most benefit.&lt;br /&gt;
* Ability to use inbuilt methods: Depending on the primitive type, languages such as Ruby provide methods that can be used specifically to probe or manipulate objects. &lt;br /&gt;
  Eg. [http://corelib.rubyonrails.org/classes/String.html String] primitive object provides convenience methods such as upcase to convert the entire string to upper case, or capitalize, which converts only the first character to upper case.&lt;br /&gt;
* Ease of testing for comparison: With primitive types, the equality testing operators such as == can be used. These essentially compare the values stored in the primitive types. Regular objects also offer the eql? method for testing equality. However, the following are not equivalent:&lt;br /&gt;
  a=10&lt;br /&gt;
  =&amp;gt; 10&lt;br /&gt;
  a==10&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a==10.0&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a.eql?(10.0)&lt;br /&gt;
  =&amp;gt; false&lt;br /&gt;
The reason the .eql? fails is that this operator tests for value and type being the same. 10 is type Fixnum and 10.0 is type Float. &lt;br /&gt;
The eql? can be overridden by == for primitive objects if you wish to compare only the values, but that can have a negative impact on performance [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html].&lt;br /&gt;
&lt;br /&gt;
=== Disadvantages ===&lt;br /&gt;
* Lack of inheritance capability: The primitive data types in languages such as Java cannot be inherited to create further subtypes.&lt;br /&gt;
* Unexpected results due to method overriding: There are certain examples such as [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html], which show that overriding inbuilt methods such as == and eql? can lead to unexpected results.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Object oriented languages have varying levels of support for primitive data types and objects. Whether they are beneficial or not depends on the application to a great deal. If handled correctly, they can make object oriented programs more efficient. However, the user needs to be aware of the underlying representation of these types to handle any unexpected results.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# http://en.wikipedia.org/wiki/Primitive_data_type&lt;br /&gt;
# http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php&lt;br /&gt;
# http://www.jk-technology.com/c/inttypes.html&lt;br /&gt;
# http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html&lt;br /&gt;
# http://newty.de/fpt/intro.html&lt;br /&gt;
# http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html&lt;br /&gt;
# http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx&lt;br /&gt;
# http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html&lt;br /&gt;
# http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html&lt;br /&gt;
# http://www.glenmccl.com/tip_016.htm&lt;br /&gt;
# http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54294</id>
		<title>CSC/ECE 517 Fall 2011/ch3 3h rr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54294"/>
		<updated>2011-10-29T21:55:14Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''3h. Primitive objects.  At the beginning of Lecture 11, we discovered that Fixnums and Bignums are handled differently behind the scenes in Ruby.  Other languages, like Java, have made similar distinctions.  By contrast, languages such as C# and Eiffel try to hide these implementation differences from users.  Answer two questions: (1) How have different o-o languages implemented primitive objects?  E.g., how are they represented in memory, how are they tested for, do comparisons do anything different than for class objects, etc.  (2) What are the advantages and disadvantages of treating primitives differently from class objects in source code?''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Programming languages, whether statically or dynamically typed, have support for certain in-built data types. These data types, known as primitive types, are the basic representation of information in programs and have certain fixed attributes for a specific language[http://en.wikipedia.org/wiki/Primitive_data_type]. Statically typed languages such as C++, Java, Perl etc. support primitive data types, whereas with dynamically typed languages such as Ruby, Smalltalk, Lisp etc. they are actually in the form of primitive objects.  These primitive types are used to store the basic types of information that a computer can store and manipulate, and can also be used as building blocks for creating more complex data types. &lt;br /&gt;
This article explains the way different primitive types are implemented in certain object oriented languages. An analysis of the benefits and drawbacks of such types and the methods used to operate on them is also presented. &lt;br /&gt;
&lt;br /&gt;
== Primitive Types ==&lt;br /&gt;
The primitive types commonly included in most programming languages are:&lt;br /&gt;
* Boolean&lt;br /&gt;
* Character&lt;br /&gt;
* Integer&lt;br /&gt;
* Floating-point number&lt;br /&gt;
* Fixed-point number&lt;br /&gt;
* Reference&lt;br /&gt;
&lt;br /&gt;
=== Boolean ===&lt;br /&gt;
A Boolean is a primitive data type used to store one of two logical types: true or false.  Boolean data types are most commonly used as input paramters to a conditional statement (such as an ‘if’ statement), or as the output of a comparison between two comparable data types.  Booleans can be implemented in languages as either a discrete logical type, or implicitly as a numerical type.  In many languages, booleans can be implicitly converted to and from integer types.  &lt;br /&gt;
&lt;br /&gt;
=== Character ===&lt;br /&gt;
A character is a data type that represents an element of a written language, such as a letter, number, or symbol.  A character can also represent a control character, such as a carriage return or newline, which does not have a written meaning but controls how other characters are stored or displayed.   Characters are commonly stored as integers, and encoded using a character map.  &lt;br /&gt;
&lt;br /&gt;
=== Integer ===&lt;br /&gt;
An integer is a data type that represents one element of a finite subset of mathematical integers.  Integer, or Integral, data types can be either unsigned (able to store only positive whole numbers) or signed (able to store either positive or negative whole numbers).  The range of values that can be represented by an integer depends on the number of bits used to store the integer, whether or not it is a signed integer, and the encoding scheme (if it is signed).  Typically, an integer has a minimum and maximum value, and can store any integer in the range between those values.  The minimum value for unsigned integers is typically 0, and the maximum value is typically determined by the amount of memory used to store the integer.  For example, a un unsigned 8-bit number can store 2^8 (or 256) possible integral values; and would typically store any value from 0 to 255.  More generally, an n-bit unsigned integer can store from 0 to (2^n)-1.  For signed integers, modern computers use the Two’s Complement encoding scheme.  This allows for a range of −2^(n−1) through 2^(n−1)−1.  For example, an 8-bit signed integer could store any whole number in the range from -128 through +127.&lt;br /&gt;
&lt;br /&gt;
=== Floating-Point Number ===&lt;br /&gt;
A floating point number is a data type used to represent real numbers in a large range with varying degrees of precision.  In this representation, numbers are represented with a variable number of significant digits, and a variable number of exponential digits.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed-Point number ===&lt;br /&gt;
A fixed-point number is a data type used to represent real numbers.  Fixed-point numbers are called fixed-point because they have a set number of digits before and after a decimal mark.  In this regard, fixed-point numbers are represented as an integer, but are scaled by a predetermined factor.  &lt;br /&gt;
&lt;br /&gt;
Fixed-point numbers are commonly used in microprocessors that do not have a floating-point unit, or in systems in which computational efficiency is critical.  Fixed-point numbers can be treated as integers by an arithmetic logic unit (ALU) and scaled after a result is obtained, which can significantly lower the amount of time needed for a processor to obtain the result for some algorithms. &lt;br /&gt;
&lt;br /&gt;
Implementing algorithms using fixed-point arithmetic requires great care, because of the potential for information loss.  Fixed-point arithmetic operations -- multiplication in particular, has the potential to cause overflow.  Algorithms must be written with care to ensure that each term of an equation has a similar range and that the result will not cause an overflow.&lt;br /&gt;
&lt;br /&gt;
=== Reference ===&lt;br /&gt;
&lt;br /&gt;
A Reference is a data type that enables a program to access another item in memory.  A reference differs from other primitive data types in that it does not store data itself; instead it stores a value referring to another data object.  References are commonly used to refer to objects of large non-primitive data types.  References commonly store the physical memory address of the data that they are referring to.  Accessing the data referred to by a Reference is called dereferencing.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C++ ==&lt;br /&gt;
&lt;br /&gt;
C++ is a statically-typed object oriented language.  C++ is based on the C programming language, which is procedural, and adds support for object-oriented code.  &lt;br /&gt;
&lt;br /&gt;
These data types are defined in C++: [http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php] &lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! Name &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| void &lt;br /&gt;
| N/A &lt;br /&gt;
| the void data type is used to explicitly identify that a data has no type &lt;br /&gt;
| N/A&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits&lt;br /&gt;
| simple numerical type&lt;br /&gt;
| See [[http://www.jk-technology.com/c/inttypes.html]]&lt;br /&gt;
|-&lt;br /&gt;
| float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 8 bits &lt;br /&gt;
| a char is a single 8-bit character encoded using ASCII &lt;br /&gt;
| Ascii character 0x00 through ascii character 0xFF&lt;br /&gt;
|}&lt;br /&gt;
C++ supports Pointers for all of the types listed in the table above, as well as more complex data types (such as structs).  A Pointer in C++ is a data type that stores the physical address of some other data.  Pointers are created in C++ by using the * operator.  For example, a *Double[] is a pointer to an array of double-precision floating point numbers.  C++ Also supports function pointers -- pointers that reference the beginning address of a function in memory.  They are commonly used to implement callback functions [http://newty.de/fpt/intro.html#what]&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in Java == &lt;br /&gt;
&lt;br /&gt;
Java is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  These data types are defined in Java: [http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html]&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;|Name&lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte&lt;br /&gt;
|8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
|128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
|16 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647 &lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Java also defines a String class, which is used to create objects of many chars.  The String class provides functionality commonly implemented using arrays of chars in other languages, such as C. &lt;br /&gt;
&lt;br /&gt;
Java also defines the 'unsigned' keyword, which can be used to as a modifier to any of the integral types listed in the table above.  If the 'unsigned' keyword is used, the integral type will be unsigned instead of signed, and its range will change correspondingly. &lt;br /&gt;
&lt;br /&gt;
Java is capable of using any two objects of the same primitive data type for comparison.  Java defines a class for each data type, which have the same name but a capitalized first letter (e.g. Float instead of float).  These classes, called wrapper classes provide a series of methods that can manipulate their associated primitive data type, as well as convert to and from other data types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C# == &lt;br /&gt;
&lt;br /&gt;
C# is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  C# has all of the data types that are available in Java, as well as some additional ones.  &lt;br /&gt;
&lt;br /&gt;
Similar to Java, C# defines a String class which is used to create objects of many chars.  These data types are defined in C#: [http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! .NET Class &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte &lt;br /&gt;
| Byte &lt;br /&gt;
| 8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
| -128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| sbyte &lt;br /&gt;
| SByte &lt;br /&gt;
| 8 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -0 to 255&lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
| Int16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| ushort &lt;br /&gt;
| UInt16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 65,535&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| Int32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647&lt;br /&gt;
|-&lt;br /&gt;
| uint &lt;br /&gt;
| UInt32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 4,294,967,295&lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| Int64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|-&lt;br /&gt;
| ulong &lt;br /&gt;
| UInt64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 18,446,744,073,709,551,615&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| Float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| -3.402823e38 to 3.02823e38&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| Double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| -1.79769313486232e308 to 1.79769313486232e308&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| Boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| Char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|-&lt;br /&gt;
| object &lt;br /&gt;
| Object &lt;br /&gt;
| N/A &lt;br /&gt;
| Object is the base type of all other types&lt;br /&gt;
| N/A &lt;br /&gt;
|-&lt;br /&gt;
| string &lt;br /&gt;
| String &lt;br /&gt;
| N/A &lt;br /&gt;
| String is the base type for a sequence of chars&lt;br /&gt;
| N/A &lt;br /&gt;
|-&lt;br /&gt;
| decimal &lt;br /&gt;
| Decimal &lt;br /&gt;
| 128 &lt;br /&gt;
| Decimal is an integral type that can represent a decimal number with 29 significant digits &lt;br /&gt;
| ±1.0 × 10e−28 to ±7.9 × 10e28&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Like Java, each primitive data type in C# also has a class associated with it that.  These classes serve a similar purpose to their associated ones in Java.  They are used for comparison of objects, as well as conversion between other similar types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Objects in Ruby ==&lt;br /&gt;
Ruby is a pure object oriented language as compared to languages such as Java or C#, which use a more hybrid approach. In Ruby, all data types are represented as Objects. There are some [http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html inbuilt classes] that are provided to users in Ruby. However, only some of them are a basic building block for forming other types. This subset shown below gives us a list of primitive objects that can be used for data representation and manipulation:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! Description&lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| TrueClass&lt;br /&gt;
| Singleton instance &amp;quot;true&amp;quot; allowed&lt;br /&gt;
| true&lt;br /&gt;
|-&lt;br /&gt;
| FalseClass&lt;br /&gt;
| Singleton instance &amp;quot;false&amp;quot; allowed&lt;br /&gt;
| false&lt;br /&gt;
|-&lt;br /&gt;
| Integer [http://www.ruby-doc.org/core/Integer.html]&lt;br /&gt;
| Abstract class that forms the basis for Fixnum and Bignum&lt;br /&gt;
| See Fixnum and Bignum&lt;br /&gt;
|-&lt;br /&gt;
| Fixnum [http://www.ruby-doc.org/core-1.8.7/Fixnum.html]&lt;br /&gt;
| Integer representations that fit in native machine word&lt;br /&gt;
| Machine architecture dependent. 2^30-1 to -2^30 on 32-bit machines.&lt;br /&gt;
|-&lt;br /&gt;
| Bignum [http://www.ruby-doc.org/core/Bignum.html]&lt;br /&gt;
| Integer representations that do not fit in Fixnum width&lt;br /&gt;
| Machine architecture dependent. Values above Fixnum range.&lt;br /&gt;
|-&lt;br /&gt;
| Float [http://www.ruby-doc.org/core/Float.html]&lt;br /&gt;
| Real numbers using double precision representation&lt;br /&gt;
| Value after decimal point can be formatted&lt;br /&gt;
|-&lt;br /&gt;
| String [http://corelib.rubyonrails.org/classes/String.html]&lt;br /&gt;
| Contains sequence of characters&lt;br /&gt;
| No physical limit, but can be decided by machine architecture&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
One interesting observation from the above table is that Ruby does not have a Boolean class; instead it has a separate TrueClass and FalseClass [http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby].&lt;br /&gt;
&lt;br /&gt;
  puts true.class &lt;br /&gt;
  =&amp;gt; TrueClass&lt;br /&gt;
  puts false.class&lt;br /&gt;
  =&amp;gt; FalseClass&lt;br /&gt;
&lt;br /&gt;
Although types such as Array, Hash are also in-built types, they can be further composed of elements that are internally represented in one of the primitive types. Hence, they will not be treated by us as primitive objects, in the traditional definition of the term.&lt;br /&gt;
Each of the primitive objects listed above also provide certain convenience methods that are applicable for the underlying type.&lt;br /&gt;
For example, the Fixnum, Bignum and Float types provide support for arithmetic operations such as addition (+), subtraction(--), multiplication(*) and so on.&lt;br /&gt;
As with all other classes in Ruby, users can add functionality to existing primitive objects by reopening classes. The amount of memory required to implement the primitive objects in Ruby is machine dependent in some cases.&lt;br /&gt;
&lt;br /&gt;
== Merit Analysis of Primitive Types ==&lt;br /&gt;
This section deals with a brief analysis of the relative merits and demerits of primitive data types. While we focus on Java or Ruby for this purpose, most of these points are applicable across all object oriented languages.&lt;br /&gt;
&lt;br /&gt;
=== Advantages ===&lt;br /&gt;
Primitive types in object oriented languages have certain advantages over their class object counterparts. &lt;br /&gt;
* Simplicity: Primitive types/objects provide users a simple mechanism of manipulating data without relying on additional objects to achieve the same functionality. Operations on primitive types are more intuitive.&lt;br /&gt;
* Efficiency: This statement is applicable if the underlying primitive object definition is not modified (a feature that languages such as Ruby provide to users). As the representation in memory is designed to be make most efficient use of the underlying datatype, use of primitives can provide a benefit to the user, over the use of class objects to store the same data. &lt;br /&gt;
  Eg. Java provides wrappers [http://www.glenmccl.com/tip_016.htm] for certain primitive types. There is a certain performance and space cost associated with these. &lt;br /&gt;
  So, to maximize efficiency, direct use of the primitive types would provide the most benefit.&lt;br /&gt;
* Ability to use inbuilt methods: Depending on the primitive type, languages such as Ruby provide methods that can be used specifically to probe or manipulate objects. &lt;br /&gt;
  Eg. [http://corelib.rubyonrails.org/classes/String.html String] primitive object provides convenience methods such as upcase to convert the entire string to upper case, or capitalize, which converts only the first character to upper case.&lt;br /&gt;
* Ease of testing for comparison: With primitive types, the equality testing operators such as == can be used. These essentially compare the values stored in the primitive types. Regular objects also offer the eql? method for testing equality. However, the following are not equivalent:&lt;br /&gt;
  a=10&lt;br /&gt;
  =&amp;gt; 10&lt;br /&gt;
  a==10&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a==10.0&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a.eql?(10.0)&lt;br /&gt;
  =&amp;gt; false&lt;br /&gt;
The reason the .eql? fails is that this operator tests for value and type being the same. 10 is type Fixnum and 10.0 is type Float. &lt;br /&gt;
The eql? can be overridden by == for primitive objects if you wish to compare only the values, but that can have a negative impact on performance [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html].&lt;br /&gt;
&lt;br /&gt;
=== Disadvantages ===&lt;br /&gt;
* Lack of inheritance capability: The primitive data types in languages such as Java cannot be inherited to create further subtypes.&lt;br /&gt;
* Unexpected results due to method overriding: There are certain examples such as [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html], which show that overriding inbuilt methods such as == and eql? can lead to unexpected results.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Object oriented languages have varying levels of support for primitive data types and objects. Whether they are beneficial or not depends on the application to a great deal. If handled correctly, they can make object oriented programs more efficient. However, the user needs to be aware of the underlying representation of these types to handle any unexpected results.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# http://en.wikipedia.org/wiki/Primitive_data_type&lt;br /&gt;
# http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php&lt;br /&gt;
# http://www.jk-technology.com/c/inttypes.html&lt;br /&gt;
# http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html&lt;br /&gt;
# http://newty.de/fpt/intro.html&lt;br /&gt;
# http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html&lt;br /&gt;
# http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx&lt;br /&gt;
# http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html&lt;br /&gt;
# http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html&lt;br /&gt;
# http://www.glenmccl.com/tip_016.htm&lt;br /&gt;
# http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54293</id>
		<title>CSC/ECE 517 Fall 2011/ch3 3h rr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54293"/>
		<updated>2011-10-29T21:54:18Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''3h. Primitive objects.  At the beginning of Lecture 11, we discovered that Fixnums and Bignums are handled differently behind the scenes in Ruby.  Other languages, like Java, have made similar distinctions.  By contrast, languages such as C# and Eiffel try to hide these implementation differences from users.  Answer two questions: (1) How have different o-o languages implemented primitive objects?  E.g., how are they represented in memory, how are they tested for, do comparisons do anything different than for class objects, etc.  (2) What are the advantages and disadvantages of treating primitives differently from class objects in source code?''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Programming languages, whether statically or dynamically typed, have support for certain in-built data types. These data types, known as primitive types, are the basic representation of information in programs and have certain fixed attributes for a specific language[http://en.wikipedia.org/wiki/Primitive_data_type]. Statically typed languages such as C++, Java, Perl etc. support primitive data types, whereas with dynamically typed languages such as Ruby, Smalltalk, Lisp etc. they are actually in the form of primitive objects.  These primitive types are used to store the basic types of information that a computer can store and manipulate, and can also be used as building blocks for creating more complex data types. &lt;br /&gt;
This article explains the way different primitive types are implemented in certain object oriented languages. An analysis of the benefits and drawbacks of such types and the methods used to operate on them is also presented. &lt;br /&gt;
&lt;br /&gt;
== Primitive Types ==&lt;br /&gt;
The primitive types commonly included in most programming languages are:&lt;br /&gt;
* Boolean&lt;br /&gt;
* Character&lt;br /&gt;
* Integer&lt;br /&gt;
* Floating-point number&lt;br /&gt;
* Fixed-point number&lt;br /&gt;
* Reference&lt;br /&gt;
&lt;br /&gt;
=== Boolean ===&lt;br /&gt;
A Boolean is a primitive data type used to store one of two logical types: true or false.  Boolean data types are most commonly used as input paramters to a conditional statement (such as an ‘if’ statement), or as the output of a comparison between two comparable data types.  Booleans can be implemented in languages as either a discrete logical type, or implicitly as a numerical type.  In many languages, booleans can be implicitly converted to and from integer types.  &lt;br /&gt;
&lt;br /&gt;
=== Character ===&lt;br /&gt;
A character is a data type that represents an element of a written language, such as a letter, number, or symbol.  A character can also represent a control character, such as a carriage return or newline, which does not have a written meaning but controls how other characters are stored or displayed.   Characters are commonly stored as integers, and encoded using a character map.  &lt;br /&gt;
&lt;br /&gt;
=== Integer ===&lt;br /&gt;
An integer is a data type that represents one element of a finite subset of mathematical integers.  Integer, or Integral, data types can be either unsigned (able to store only positive whole numbers) or signed (able to store either positive or negative whole numbers).  The range of values that can be represented by an integer depends on the number of bits used to store the integer, whether or not it is a signed integer, and the encoding scheme (if it is signed).  Typically, an integer has a minimum and maximum value, and can store any integer in the range between those values.  The minimum value for unsigned integers is typically 0, and the maximum value is typically determined by the amount of memory used to store the integer.  For example, a un unsigned 8-bit number can store 2^8 (or 256) possible integral values; and would typically store any value from 0 to 255.  More generally, an n-bit unsigned integer can store from 0 to (2^n)-1.  For signed integers, modern computers use the Two’s Complement encoding scheme.  This allows for a range of −2^(n−1) through 2^(n−1)−1.  For example, an 8-bit signed integer could store any whole number in the range from -128 through +127.&lt;br /&gt;
&lt;br /&gt;
=== Floating-Point Number ===&lt;br /&gt;
A floating point number is a data type used to represent real numbers in a large range with varying degrees of precision.  In this representation, numbers are represented with a variable number of significant digits, and a variable number of exponential digits.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed-Point number ===&lt;br /&gt;
A fixed-point number is a data type used to represent real numbers.  Fixed-point numbers are called fixed-point because they have a set number of digits before and after a decimal mark.  In this regard, fixed-point numbers are represented as an integer, but are scaled by a predetermined factor.  &lt;br /&gt;
&lt;br /&gt;
Fixed-point numbers are commonly used in microprocessors that do not have a floating-point unit, or in systems in which computational efficiency is critical.  Fixed-point numbers can be treated as integers by an arithmetic logic unit (ALU) and scaled after a result is obtained, which can significantly lower the amount of time needed for a processor to obtain the result for some algorithms. &lt;br /&gt;
&lt;br /&gt;
Implementing algorithms using fixed-point arithmetic requires great care, because of the potential for information loss.  Fixed-point arithmetic operations -- multiplication in particular, has the potential to cause overflow.  Algorithms must be written with care to ensure that each term of an equation has a similar range and that the result will not cause an overflow.&lt;br /&gt;
&lt;br /&gt;
=== Reference ===&lt;br /&gt;
&lt;br /&gt;
A Reference is a data type that enables a program to access another item in memory.  A reference differs from other primitive data types in that it does not store data itself; instead it stores a value referring to another data object.  References are commonly used to refer to objects of large non-primitive data types.  References commonly store the physical memory address of the data that they are referring to.  Accessing the data referred to by a Reference is called dereferencing.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C++ ==&lt;br /&gt;
&lt;br /&gt;
C++ is a statically-typed object oriented language.  C++ is based on the C programming language, which is procedural, and adds support for object-oriented code.  &lt;br /&gt;
&lt;br /&gt;
These data types are defined in C++: [http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php] &lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! Name &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| void &lt;br /&gt;
| N/A &lt;br /&gt;
| the void data type is used to explicitly identify that a data has no type &lt;br /&gt;
| N/A&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits&lt;br /&gt;
| simple numerical type&lt;br /&gt;
| See [[http://www.jk-technology.com/c/inttypes.html]]&lt;br /&gt;
|-&lt;br /&gt;
| float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 8 bits &lt;br /&gt;
| a char is a single 8-bit character encoded using ASCII &lt;br /&gt;
| Ascii character 0x00 through ascii character 0xFF&lt;br /&gt;
|}&lt;br /&gt;
C++ supports Pointers for all of the types listed in the table above, as well as more complex data types (such as structs).  A Pointer in C++ is a data type that stores the physical address of some other data.  Pointers are created in C++ by using the * operator.  For example, a *Double[] is a pointer to an array of double-precision floating point numbers.  C++ Also supports function pointers -- pointers that reference the beginning address of a function in memory.  They are commonly used to implement callback functions [http://newty.de/fpt/intro.html#what]&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in Java == &lt;br /&gt;
&lt;br /&gt;
Java is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  These data types are defined in Java: [http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html]&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;|Name&lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte&lt;br /&gt;
|8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
|128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
|16 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647 &lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Java also defines a String class, which is used to create objects of many chars.  The String class provides functionality commonly implemented using arrays of chars in other languages, such as C. &lt;br /&gt;
&lt;br /&gt;
Java also defines the 'unsigned' keyword, which can be used to as a modifier to any of the integral types listed in the table above.  If the 'unsigned' keyword is used, the integral type will be unsigned instead of signed, and its range will change correspondingly. &lt;br /&gt;
&lt;br /&gt;
Java is capable of using any two objects of the same primitive data type for comparison.  Java defines a class for each data type, which have the same name but a capitalized first letter (e.g. Float instead of float).  These classes, called wrapper classes provide a series of methods that can manipulate their associated primitive data type, as well as convert to and from other data types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C# == &lt;br /&gt;
&lt;br /&gt;
C# is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  C# has all of the data types that are available in Java, as well as some additional ones.  &lt;br /&gt;
&lt;br /&gt;
Similar to Java, C# defines a String class which is used to create objects of many chars.  These data types are defined in C#: [http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! .NET Class &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte &lt;br /&gt;
| Byte &lt;br /&gt;
| 8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
| -128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| sbyte &lt;br /&gt;
| SByte &lt;br /&gt;
| 8 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -0 to 255&lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
| Int16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| ushort &lt;br /&gt;
| UInt16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 65,535&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| Int32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647&lt;br /&gt;
|-&lt;br /&gt;
| uint &lt;br /&gt;
| UInt32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 4,294,967,295&lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| Int64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|-&lt;br /&gt;
| ulong &lt;br /&gt;
| UInt64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 18,446,744,073,709,551,615&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| Float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| -3.402823e38 to 3.02823e38&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| Double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| -1.79769313486232e308 to 1.79769313486232e308&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| Boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| Char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|-&lt;br /&gt;
| object &lt;br /&gt;
| Object &lt;br /&gt;
| N/A &lt;br /&gt;
| Object is the base type of all other types&lt;br /&gt;
|-&lt;br /&gt;
| string &lt;br /&gt;
| String &lt;br /&gt;
| N/A &lt;br /&gt;
| String is the base type for a sequence of chars&lt;br /&gt;
|-&lt;br /&gt;
| decimal &lt;br /&gt;
| Decimal &lt;br /&gt;
| 128 &lt;br /&gt;
| Decimal is an integral type that can represent a decimal number with 29 significant digits ±1.0 × 10e−28 to ±7.9 × 10e28&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Like Java, each primitive data type in C# also has a class associated with it that.  These classes serve a similar purpose to their associated ones in Java.  They are used for comparison of objects, as well as conversion between other similar types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Objects in Ruby ==&lt;br /&gt;
Ruby is a pure object oriented language as compared to languages such as Java or C#, which use a more hybrid approach. In Ruby, all data types are represented as Objects. There are some [http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html inbuilt classes] that are provided to users in Ruby. However, only some of them are a basic building block for forming other types. This subset shown below gives us a list of primitive objects that can be used for data representation and manipulation:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! Description&lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| TrueClass&lt;br /&gt;
| Singleton instance &amp;quot;true&amp;quot; allowed&lt;br /&gt;
| true&lt;br /&gt;
|-&lt;br /&gt;
| FalseClass&lt;br /&gt;
| Singleton instance &amp;quot;false&amp;quot; allowed&lt;br /&gt;
| false&lt;br /&gt;
|-&lt;br /&gt;
| Integer [http://www.ruby-doc.org/core/Integer.html]&lt;br /&gt;
| Abstract class that forms the basis for Fixnum and Bignum&lt;br /&gt;
| See Fixnum and Bignum&lt;br /&gt;
|-&lt;br /&gt;
| Fixnum [http://www.ruby-doc.org/core-1.8.7/Fixnum.html]&lt;br /&gt;
| Integer representations that fit in native machine word&lt;br /&gt;
| Machine architecture dependent. 2^30-1 to -2^30 on 32-bit machines.&lt;br /&gt;
|-&lt;br /&gt;
| Bignum [http://www.ruby-doc.org/core/Bignum.html]&lt;br /&gt;
| Integer representations that do not fit in Fixnum width&lt;br /&gt;
| Machine architecture dependent. Values above Fixnum range.&lt;br /&gt;
|-&lt;br /&gt;
| Float [http://www.ruby-doc.org/core/Float.html]&lt;br /&gt;
| Real numbers using double precision representation&lt;br /&gt;
| Value after decimal point can be formatted&lt;br /&gt;
|-&lt;br /&gt;
| String [http://corelib.rubyonrails.org/classes/String.html]&lt;br /&gt;
| Contains sequence of characters&lt;br /&gt;
| No physical limit, but can be decided by machine architecture&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
One interesting observation from the above table is that Ruby does not have a Boolean class; instead it has a separate TrueClass and FalseClass [http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby].&lt;br /&gt;
&lt;br /&gt;
  puts true.class &lt;br /&gt;
  =&amp;gt; TrueClass&lt;br /&gt;
  puts false.class&lt;br /&gt;
  =&amp;gt; FalseClass&lt;br /&gt;
&lt;br /&gt;
Although types such as Array, Hash are also in-built types, they can be further composed of elements that are internally represented in one of the primitive types. Hence, they will not be treated by us as primitive objects, in the traditional definition of the term.&lt;br /&gt;
Each of the primitive objects listed above also provide certain convenience methods that are applicable for the underlying type.&lt;br /&gt;
For example, the Fixnum, Bignum and Float types provide support for arithmetic operations such as addition (+), subtraction(--), multiplication(*) and so on.&lt;br /&gt;
As with all other classes in Ruby, users can add functionality to existing primitive objects by reopening classes. The amount of memory required to implement the primitive objects in Ruby is machine dependent in some cases.&lt;br /&gt;
&lt;br /&gt;
== Merit Analysis of Primitive Types ==&lt;br /&gt;
This section deals with a brief analysis of the relative merits and demerits of primitive data types. While we focus on Java or Ruby for this purpose, most of these points are applicable across all object oriented languages.&lt;br /&gt;
&lt;br /&gt;
=== Advantages ===&lt;br /&gt;
Primitive types in object oriented languages have certain advantages over their class object counterparts. &lt;br /&gt;
* Simplicity: Primitive types/objects provide users a simple mechanism of manipulating data without relying on additional objects to achieve the same functionality. Operations on primitive types are more intuitive.&lt;br /&gt;
* Efficiency: This statement is applicable if the underlying primitive object definition is not modified (a feature that languages such as Ruby provide to users). As the representation in memory is designed to be make most efficient use of the underlying datatype, use of primitives can provide a benefit to the user, over the use of class objects to store the same data. &lt;br /&gt;
  Eg. Java provides wrappers [http://www.glenmccl.com/tip_016.htm] for certain primitive types. There is a certain performance and space cost associated with these. &lt;br /&gt;
  So, to maximize efficiency, direct use of the primitive types would provide the most benefit.&lt;br /&gt;
* Ability to use inbuilt methods: Depending on the primitive type, languages such as Ruby provide methods that can be used specifically to probe or manipulate objects. &lt;br /&gt;
  Eg. [http://corelib.rubyonrails.org/classes/String.html String] primitive object provides convenience methods such as upcase to convert the entire string to upper case, or capitalize, which converts only the first character to upper case.&lt;br /&gt;
* Ease of testing for comparison: With primitive types, the equality testing operators such as == can be used. These essentially compare the values stored in the primitive types. Regular objects also offer the eql? method for testing equality. However, the following are not equivalent:&lt;br /&gt;
  a=10&lt;br /&gt;
  =&amp;gt; 10&lt;br /&gt;
  a==10&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a==10.0&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a.eql?(10.0)&lt;br /&gt;
  =&amp;gt; false&lt;br /&gt;
The reason the .eql? fails is that this operator tests for value and type being the same. 10 is type Fixnum and 10.0 is type Float. &lt;br /&gt;
The eql? can be overridden by == for primitive objects if you wish to compare only the values, but that can have a negative impact on performance [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html].&lt;br /&gt;
&lt;br /&gt;
=== Disadvantages ===&lt;br /&gt;
* Lack of inheritance capability: The primitive data types in languages such as Java cannot be inherited to create further subtypes.&lt;br /&gt;
* Unexpected results due to method overriding: There are certain examples such as [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html], which show that overriding inbuilt methods such as == and eql? can lead to unexpected results.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Object oriented languages have varying levels of support for primitive data types and objects. Whether they are beneficial or not depends on the application to a great deal. If handled correctly, they can make object oriented programs more efficient. However, the user needs to be aware of the underlying representation of these types to handle any unexpected results.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# http://en.wikipedia.org/wiki/Primitive_data_type&lt;br /&gt;
# http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php&lt;br /&gt;
# http://www.jk-technology.com/c/inttypes.html&lt;br /&gt;
# http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html&lt;br /&gt;
# http://newty.de/fpt/intro.html&lt;br /&gt;
# http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html&lt;br /&gt;
# http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx&lt;br /&gt;
# http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html&lt;br /&gt;
# http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html&lt;br /&gt;
# http://www.glenmccl.com/tip_016.htm&lt;br /&gt;
# http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54292</id>
		<title>CSC/ECE 517 Fall 2011/ch3 3h rr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54292"/>
		<updated>2011-10-29T21:52:33Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''3h. Primitive objects.  At the beginning of Lecture 11, we discovered that Fixnums and Bignums are handled differently behind the scenes in Ruby.  Other languages, like Java, have made similar distinctions.  By contrast, languages such as C# and Eiffel try to hide these implementation differences from users.  Answer two questions: (1) How have different o-o languages implemented primitive objects?  E.g., how are they represented in memory, how are they tested for, do comparisons do anything different than for class objects, etc.  (2) What are the advantages and disadvantages of treating primitives differently from class objects in source code?''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Programming languages, whether statically or dynamically typed, have support for certain in-built data types. These data types, known as primitive types, are the basic representation of information in programs and have certain fixed attributes for a specific language[http://en.wikipedia.org/wiki/Primitive_data_type]. Statically typed languages such as C++, Java, Perl etc. support primitive data types, whereas with dynamically typed languages such as Ruby, Smalltalk, Lisp etc. they are actually in the form of primitive objects.  These primitive types are used to store the basic types of information that a computer can store and manipulate, and can also be used as building blocks for creating more complex data types. &lt;br /&gt;
This article explains the way different primitive types are implemented in certain object oriented languages. An analysis of the benefits and drawbacks of such types and the methods used to operate on them is also presented. &lt;br /&gt;
&lt;br /&gt;
== Primitive Types ==&lt;br /&gt;
The primitive types commonly included in most programming languages are:&lt;br /&gt;
* Boolean&lt;br /&gt;
* Character&lt;br /&gt;
* Integer&lt;br /&gt;
* Floating-point number&lt;br /&gt;
* Fixed-point number&lt;br /&gt;
* Reference&lt;br /&gt;
&lt;br /&gt;
=== Boolean ===&lt;br /&gt;
A Boolean is a primitive data type used to store one of two logical types: true or false.  Boolean data types are most commonly used as input paramters to a conditional statement (such as an ‘if’ statement), or as the output of a comparison between two comparable data types.  Booleans can be implemented in languages as either a discrete logical type, or implicitly as a numerical type.  In many languages, booleans can be implicitly converted to and from integer types.  &lt;br /&gt;
&lt;br /&gt;
=== Character ===&lt;br /&gt;
A character is a data type that represents an element of a written language, such as a letter, number, or symbol.  A character can also represent a control character, such as a carriage return or newline, which does not have a written meaning but controls how other characters are stored or displayed.   Characters are commonly stored as integers, and encoded using a character map.  &lt;br /&gt;
&lt;br /&gt;
=== Integer ===&lt;br /&gt;
An integer is a data type that represents one element of a finite subset of mathematical integers.  Integer, or Integral, data types can be either unsigned (able to store only positive whole numbers) or signed (able to store either positive or negative whole numbers).  The range of values that can be represented by an integer depends on the number of bits used to store the integer, whether or not it is a signed integer, and the encoding scheme (if it is signed).  Typically, an integer has a minimum and maximum value, and can store any integer in the range between those values.  The minimum value for unsigned integers is typically 0, and the maximum value is typically determined by the amount of memory used to store the integer.  For example, a un unsigned 8-bit number can store 2^8 (or 256) possible integral values; and would typically store any value from 0 to 255.  More generally, an n-bit unsigned integer can store from 0 to (2^n)-1.  For signed integers, modern computers use the Two’s Complement encoding scheme.  This allows for a range of −2^(n−1) through 2^(n−1)−1.  For example, an 8-bit signed integer could store any whole number in the range from -128 through +127.&lt;br /&gt;
&lt;br /&gt;
=== Floating-Point Number ===&lt;br /&gt;
A floating point number is a data type used to represent real numbers in a large range with varying degrees of precision.  In this representation, numbers are represented with a variable number of significant digits, and a variable number of exponential digits.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed-Point number ===&lt;br /&gt;
A fixed-point number is a data type used to represent real numbers.  Fixed-point numbers are called fixed-point because they have a set number of digits before and after a decimal mark.  In this regard, fixed-point numbers are represented as an integer, but are scaled by a predetermined factor.  &lt;br /&gt;
&lt;br /&gt;
Fixed-point numbers are commonly used in microprocessors that do not have a floating-point unit, or in systems in which computational efficiency is critical.  Fixed-point numbers can be treated as integers by an arithmetic logic unit (ALU) and scaled after a result is obtained, which can significantly lower the amount of time needed for a processor to obtain the result for some algorithms. &lt;br /&gt;
&lt;br /&gt;
Implementing algorithms using fixed-point arithmetic requires great care, because of the potential for information loss.  Fixed-point arithmetic operations -- multiplication in particular, has the potential to cause overflow.  Algorithms must be written with care to ensure that each term of an equation has a similar range and that the result will not cause an overflow.&lt;br /&gt;
&lt;br /&gt;
=== Reference ===&lt;br /&gt;
&lt;br /&gt;
A Reference is a data type that enables a program to access another item in memory.  A reference differs from other primitive data types in that it does not store data itself; instead it stores a value referring to another data object.  References are commonly used to refer to objects of large non-primitive data types.  References commonly store the physical memory address of the data that they are referring to.  Accessing the data referred to by a Reference is called dereferencing.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C++ ==&lt;br /&gt;
&lt;br /&gt;
C++ is a statically-typed object oriented language.  C++ is based on the C programming language, which is procedural, and adds support for object-oriented code.  &lt;br /&gt;
&lt;br /&gt;
These data types are defined in C++: [http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php] &lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! Name &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| void &lt;br /&gt;
| N/A &lt;br /&gt;
| the void data type is used to explicitly identify that a data has no type &lt;br /&gt;
| N/A&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits&lt;br /&gt;
| simple numerical type&lt;br /&gt;
| See [[http://www.jk-technology.com/c/inttypes.html]]&lt;br /&gt;
|-&lt;br /&gt;
| float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 8 bits &lt;br /&gt;
| a char is a single 8-bit character encoded using ASCII &lt;br /&gt;
| Ascii character 0x00 through ascii character 0xFF&lt;br /&gt;
|}&lt;br /&gt;
C++ supports Pointers for all of the types listed in the table above, as well as more complex data types (such as structs).  A Pointer in C++ is a data type that stores the physical address of some other data.  Pointers are created in C++ by using the * operator.  For example, a *Double[] is a pointer to an array of double-precision floating point numbers.  C++ Also supports function pointers -- pointers that reference the beginning address of a function in memory.  They are commonly used to implement callback functions [http://newty.de/fpt/intro.html#what]&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in Java == &lt;br /&gt;
&lt;br /&gt;
Java is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  These data types are defined in Java: [http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html]&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;|Name&lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte&lt;br /&gt;
|8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
|-128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
|16 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647 &lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Java also defines a String class, which is used to create objects of many chars.  The String class provides functionality commonly implemented using arrays of chars in other languages, such as C. &lt;br /&gt;
&lt;br /&gt;
Java also defines the 'unsigned' keyword, which can be used to as a modifier to any of the integral types listed in the table above.  If the 'unsigned' keyword is used, the integral type will be unsigned instead of signed, and its range will change correspondingly. &lt;br /&gt;
&lt;br /&gt;
Java is capable of using any two objects of the same primitive data type for comparison.  Java defines a class for each data type, which have the same name but a capitalized first letter (e.g. Float instead of float).  These classes, called wrapper classes provide a series of methods that can manipulate their associated primitive data type, as well as convert to and from other data types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C# == &lt;br /&gt;
&lt;br /&gt;
C# is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  C# has all of the data types that are available in Java, as well as some additional ones.  &lt;br /&gt;
&lt;br /&gt;
Similar to Java, C# defines a String class which is used to create objects of many chars.  These data types are defined in C#: [http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! .NET Class &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte &lt;br /&gt;
| Byte &lt;br /&gt;
| 8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
| -128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| sbyte &lt;br /&gt;
| SByte &lt;br /&gt;
| 8 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -0 to 255&lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
| Int16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| ushort &lt;br /&gt;
| UInt16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 65,535&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| Int32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647&lt;br /&gt;
|-&lt;br /&gt;
| uint &lt;br /&gt;
| UInt32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 4,294,967,295&lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| Int64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|-&lt;br /&gt;
| ulong &lt;br /&gt;
| UInt64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 18,446,744,073,709,551,615&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| Float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| -3.402823e38 to 3.02823e38&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| Double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| -1.79769313486232e308 to 1.79769313486232e308&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| Boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| Char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|-&lt;br /&gt;
| object &lt;br /&gt;
| Object &lt;br /&gt;
| N/A &lt;br /&gt;
| Object is the base type of all other types&lt;br /&gt;
|-&lt;br /&gt;
| string &lt;br /&gt;
| String &lt;br /&gt;
| N/A &lt;br /&gt;
| String is the base type for a sequence of chars&lt;br /&gt;
|-&lt;br /&gt;
| decimal &lt;br /&gt;
| Decimal &lt;br /&gt;
| 128 &lt;br /&gt;
| Decimal is an integral type that can represent a decimal number with 29 significant digits ±1.0 × 10e−28 to ±7.9 × 10e28&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Like Java, each primitive data type in C# also has a class associated with it that.  These classes serve a similar purpose to their associated ones in Java.  They are used for comparison of objects, as well as conversion between other similar types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Objects in Ruby ==&lt;br /&gt;
Ruby is a pure object oriented language as compared to languages such as Java or C#, which use a more hybrid approach. In Ruby, all data types are represented as Objects. There are some [http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html inbuilt classes] that are provided to users in Ruby. However, only some of them are a basic building block for forming other types. This subset shown below gives us a list of primitive objects that can be used for data representation and manipulation:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! Description&lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| TrueClass&lt;br /&gt;
| Singleton instance &amp;quot;true&amp;quot; allowed&lt;br /&gt;
| true&lt;br /&gt;
|-&lt;br /&gt;
| FalseClass&lt;br /&gt;
| Singleton instance &amp;quot;false&amp;quot; allowed&lt;br /&gt;
| false&lt;br /&gt;
|-&lt;br /&gt;
| Integer [http://www.ruby-doc.org/core/Integer.html]&lt;br /&gt;
| Abstract class that forms the basis for Fixnum and Bignum&lt;br /&gt;
| See Fixnum and Bignum&lt;br /&gt;
|-&lt;br /&gt;
| Fixnum [http://www.ruby-doc.org/core-1.8.7/Fixnum.html]&lt;br /&gt;
| Integer representations that fit in native machine word&lt;br /&gt;
| Machine architecture dependent. 2^30-1 to -2^30 on 32-bit machines.&lt;br /&gt;
|-&lt;br /&gt;
| Bignum [http://www.ruby-doc.org/core/Bignum.html]&lt;br /&gt;
| Integer representations that do not fit in Fixnum width&lt;br /&gt;
| Machine architecture dependent. Values above Fixnum range.&lt;br /&gt;
|-&lt;br /&gt;
| Float [http://www.ruby-doc.org/core/Float.html]&lt;br /&gt;
| Real numbers using double precision representation&lt;br /&gt;
| Value after decimal point can be formatted&lt;br /&gt;
|-&lt;br /&gt;
| String [http://corelib.rubyonrails.org/classes/String.html]&lt;br /&gt;
| Contains sequence of characters&lt;br /&gt;
| No physical limit, but can be decided by machine architecture&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
One interesting observation from the above table is that Ruby does not have a Boolean class; instead it has a separate TrueClass and FalseClass [http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby].&lt;br /&gt;
&lt;br /&gt;
  puts true.class &lt;br /&gt;
  =&amp;gt; TrueClass&lt;br /&gt;
  puts false.class&lt;br /&gt;
  =&amp;gt; FalseClass&lt;br /&gt;
&lt;br /&gt;
Although types such as Array, Hash are also in-built types, they can be further composed of elements that are internally represented in one of the primitive types. Hence, they will not be treated by us as primitive objects, in the traditional definition of the term.&lt;br /&gt;
Each of the primitive objects listed above also provide certain convenience methods that are applicable for the underlying type.&lt;br /&gt;
For example, the Fixnum, Bignum and Float types provide support for arithmetic operations such as addition (+), subtraction(--), multiplication(*) and so on.&lt;br /&gt;
As with all other classes in Ruby, users can add functionality to existing primitive objects by reopening classes. The amount of memory required to implement the primitive objects in Ruby is machine dependent in some cases.&lt;br /&gt;
&lt;br /&gt;
== Merit Analysis of Primitive Types ==&lt;br /&gt;
This section deals with a brief analysis of the relative merits and demerits of primitive data types. While we focus on Java or Ruby for this purpose, most of these points are applicable across all object oriented languages.&lt;br /&gt;
&lt;br /&gt;
=== Advantages ===&lt;br /&gt;
Primitive types in object oriented languages have certain advantages over their class object counterparts. &lt;br /&gt;
* Simplicity: Primitive types/objects provide users a simple mechanism of manipulating data without relying on additional objects to achieve the same functionality. Operations on primitive types are more intuitive.&lt;br /&gt;
* Efficiency: This statement is applicable if the underlying primitive object definition is not modified (a feature that languages such as Ruby provide to users). As the representation in memory is designed to be make most efficient use of the underlying datatype, use of primitives can provide a benefit to the user, over the use of class objects to store the same data. &lt;br /&gt;
  Eg. Java provides wrappers [http://www.glenmccl.com/tip_016.htm] for certain primitive types. There is a certain performance and space cost associated with these. &lt;br /&gt;
  So, to maximize efficiency, direct use of the primitive types would provide the most benefit.&lt;br /&gt;
* Ability to use inbuilt methods: Depending on the primitive type, languages such as Ruby provide methods that can be used specifically to probe or manipulate objects. &lt;br /&gt;
  Eg. [http://corelib.rubyonrails.org/classes/String.html String] primitive object provides convenience methods such as upcase to convert the entire string to upper case, or capitalize, which converts only the first character to upper case.&lt;br /&gt;
* Ease of testing for comparison: With primitive types, the equality testing operators such as == can be used. These essentially compare the values stored in the primitive types. Regular objects also offer the eql? method for testing equality. However, the following are not equivalent:&lt;br /&gt;
  a=10&lt;br /&gt;
  =&amp;gt; 10&lt;br /&gt;
  a==10&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a==10.0&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a.eql?(10.0)&lt;br /&gt;
  =&amp;gt; false&lt;br /&gt;
The reason the .eql? fails is that this operator tests for value and type being the same. 10 is type Fixnum and 10.0 is type Float. &lt;br /&gt;
The eql? can be overridden by == for primitive objects if you wish to compare only the values, but that can have a negative impact on performance [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html].&lt;br /&gt;
&lt;br /&gt;
=== Disadvantages ===&lt;br /&gt;
* Lack of inheritance capability: The primitive data types in languages such as Java cannot be inherited to create further subtypes.&lt;br /&gt;
* Unexpected results due to method overriding: There are certain examples such as [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html], which show that overriding inbuilt methods such as == and eql? can lead to unexpected results.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Object oriented languages have varying levels of support for primitive data types and objects. Whether they are beneficial or not depends on the application to a great deal. If handled correctly, they can make object oriented programs more efficient. However, the user needs to be aware of the underlying representation of these types to handle any unexpected results.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# http://en.wikipedia.org/wiki/Primitive_data_type&lt;br /&gt;
# http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php&lt;br /&gt;
# http://www.jk-technology.com/c/inttypes.html&lt;br /&gt;
# http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html&lt;br /&gt;
# http://newty.de/fpt/intro.html&lt;br /&gt;
# http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html&lt;br /&gt;
# http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx&lt;br /&gt;
# http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html&lt;br /&gt;
# http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html&lt;br /&gt;
# http://www.glenmccl.com/tip_016.htm&lt;br /&gt;
# http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54291</id>
		<title>CSC/ECE 517 Fall 2011/ch3 3h rr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54291"/>
		<updated>2011-10-29T21:51:47Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''3h. Primitive objects.  At the beginning of Lecture 11, we discovered that Fixnums and Bignums are handled differently behind the scenes in Ruby.  Other languages, like Java, have made similar distinctions.  By contrast, languages such as C# and Eiffel try to hide these implementation differences from users.  Answer two questions: (1) How have different o-o languages implemented primitive objects?  E.g., how are they represented in memory, how are they tested for, do comparisons do anything different than for class objects, etc.  (2) What are the advantages and disadvantages of treating primitives differently from class objects in source code?''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Programming languages, whether statically or dynamically typed, have support for certain in-built data types. These data types, known as primitive types, are the basic representation of information in programs and have certain fixed attributes for a specific language[http://en.wikipedia.org/wiki/Primitive_data_type]. Statically typed languages such as C++, Java, Perl etc. support primitive data types, whereas with dynamically typed languages such as Ruby, Smalltalk, Lisp etc. they are actually in the form of primitive objects.  These primitive types are used to store the basic types of information that a computer can store and manipulate, and can also be used as building blocks for creating more complex data types. &lt;br /&gt;
This article explains the way different primitive types are implemented in certain object oriented languages. An analysis of the benefits and drawbacks of such types and the methods used to operate on them is also presented. &lt;br /&gt;
&lt;br /&gt;
== Primitive Types ==&lt;br /&gt;
The primitive types commonly included in most programming languages are:&lt;br /&gt;
* Boolean&lt;br /&gt;
* Character&lt;br /&gt;
* Integer&lt;br /&gt;
* Floating-point number&lt;br /&gt;
* Fixed-point number&lt;br /&gt;
* Reference&lt;br /&gt;
&lt;br /&gt;
=== Boolean ===&lt;br /&gt;
A Boolean is a primitive data type used to store one of two logical types: true or false.  Boolean data types are most commonly used as input paramters to a conditional statement (such as an ‘if’ statement), or as the output of a comparison between two comparable data types.  Booleans can be implemented in languages as either a discrete logical type, or implicitly as a numerical type.  In many languages, booleans can be implicitly converted to and from integer types.  &lt;br /&gt;
&lt;br /&gt;
=== Character ===&lt;br /&gt;
A character is a data type that represents an element of a written language, such as a letter, number, or symbol.  A character can also represent a control character, such as a carriage return or newline, which does not have a written meaning but controls how other characters are stored or displayed.   Characters are commonly stored as integers, and encoded using a character map.  &lt;br /&gt;
&lt;br /&gt;
=== Integer ===&lt;br /&gt;
An integer is a data type that represents one element of a finite subset of mathematical integers.  Integer, or Integral, data types can be either unsigned (able to store only positive whole numbers) or signed (able to store either positive or negative whole numbers).  The range of values that can be represented by an integer depends on the number of bits used to store the integer, whether or not it is a signed integer, and the encoding scheme (if it is signed).  Typically, an integer has a minimum and maximum value, and can store any integer in the range between those values.  The minimum value for unsigned integers is typically 0, and the maximum value is typically determined by the amount of memory used to store the integer.  For example, a un unsigned 8-bit number can store 2^8 (or 256) possible integral values; and would typically store any value from 0 to 255.  More generally, an n-bit unsigned integer can store from 0 to (2^n)-1.  For signed integers, modern computers use the Two’s Complement encoding scheme.  This allows for a range of −2^(n−1) through 2^(n−1)−1.  For example, an 8-bit signed integer could store any whole number in the range from -128 through +127.&lt;br /&gt;
&lt;br /&gt;
=== Floating-Point Number ===&lt;br /&gt;
A floating point number is a data type used to represent real numbers in a large range with varying degrees of precision.  In this representation, numbers are represented with a variable number of significant digits, and a variable number of exponential digits.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed-Point number ===&lt;br /&gt;
A fixed-point number is a data type used to represent real numbers.  Fixed-point numbers are called fixed-point because they have a set number of digits before and after a decimal mark.  In this regard, fixed-point numbers are represented as an integer, but are scaled by a predetermined factor.  &lt;br /&gt;
&lt;br /&gt;
Fixed-point numbers are commonly used in microprocessors that do not have a floating-point unit, or in systems in which computational efficiency is critical.  Fixed-point numbers can be treated as integers by an arithmetic logic unit (ALU) and scaled after a result is obtained, which can significantly lower the amount of time needed for a processor to obtain the result for some algorithms. &lt;br /&gt;
&lt;br /&gt;
Implementing algorithms using fixed-point arithmetic requires great care, because of the potential for information loss.  Fixed-point arithmetic operations -- multiplication in particular, has the potential to cause overflow.  Algorithms must be written with care to ensure that each term of an equation has a similar range and that the result will not cause an overflow.&lt;br /&gt;
&lt;br /&gt;
=== Reference ===&lt;br /&gt;
&lt;br /&gt;
A Reference is a data type that enables a program to access another item in memory.  A reference differs from other primitive data types in that it does not store data itself; instead it stores a value referring to another data object.  References are commonly used to refer to objects of large non-primitive data types.  References commonly store the physical memory address of the data that they are referring to.  Accessing the data referred to by a Reference is called dereferencing.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C++ ==&lt;br /&gt;
&lt;br /&gt;
C++ is a statically-typed object oriented language.  C++ is based on the C programming language, which is procedural, and adds support for object-oriented code.  &lt;br /&gt;
&lt;br /&gt;
These data types are defined in C++: [http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php] &lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing: 0&amp;quot;&lt;br /&gt;
! Name &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| void &lt;br /&gt;
| N/A &lt;br /&gt;
| the void data type is used to explicitly identify that a data has no type &lt;br /&gt;
| N/A&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits&lt;br /&gt;
| simple numerical type&lt;br /&gt;
| See [[http://www.jk-technology.com/c/inttypes.html]]&lt;br /&gt;
|-&lt;br /&gt;
| float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 8 bits &lt;br /&gt;
| a char is a single 8-bit character encoded using ASCII &lt;br /&gt;
| Ascii character 0x00 through ascii character 0xFF&lt;br /&gt;
|}&lt;br /&gt;
C++ supports Pointers for all of the types listed in the table above, as well as more complex data types (such as structs).  A Pointer in C++ is a data type that stores the physical address of some other data.  Pointers are created in C++ by using the * operator.  For example, a *Double[] is a pointer to an array of double-precision floating point numbers.  C++ Also supports function pointers -- pointers that reference the beginning address of a function in memory.  They are commonly used to implement callback functions [http://newty.de/fpt/intro.html#what]&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in Java == &lt;br /&gt;
&lt;br /&gt;
Java is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  These data types are defined in Java: [http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html]&lt;br /&gt;
{|style=&amp;quot;border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; padding: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;|Name&lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte&lt;br /&gt;
|8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
|-128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
|16 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647 &lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Java also defines a String class, which is used to create objects of many chars.  The String class provides functionality commonly implemented using arrays of chars in other languages, such as C. &lt;br /&gt;
&lt;br /&gt;
Java also defines the 'unsigned' keyword, which can be used to as a modifier to any of the integral types listed in the table above.  If the 'unsigned' keyword is used, the integral type will be unsigned instead of signed, and its range will change correspondingly. &lt;br /&gt;
&lt;br /&gt;
Java is capable of using any two objects of the same primitive data type for comparison.  Java defines a class for each data type, which have the same name but a capitalized first letter (e.g. Float instead of float).  These classes, called wrapper classes provide a series of methods that can manipulate their associated primitive data type, as well as convert to and from other data types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C# == &lt;br /&gt;
&lt;br /&gt;
C# is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  C# has all of the data types that are available in Java, as well as some additional ones.  &lt;br /&gt;
&lt;br /&gt;
Similar to Java, C# defines a String class which is used to create objects of many chars.  These data types are defined in C#: [http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx]&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; padding: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! .NET Class &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte &lt;br /&gt;
| Byte &lt;br /&gt;
| 8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
| -128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| sbyte &lt;br /&gt;
| SByte &lt;br /&gt;
| 8 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -0 to 255&lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
| Int16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| ushort &lt;br /&gt;
| UInt16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 65,535&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| Int32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647&lt;br /&gt;
|-&lt;br /&gt;
| uint &lt;br /&gt;
| UInt32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 4,294,967,295&lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| Int64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|-&lt;br /&gt;
| ulong &lt;br /&gt;
| UInt64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 18,446,744,073,709,551,615&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| Float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| -3.402823e38 to 3.02823e38&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| Double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| -1.79769313486232e308 to 1.79769313486232e308&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| Boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| Char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|-&lt;br /&gt;
| object &lt;br /&gt;
| Object &lt;br /&gt;
| N/A &lt;br /&gt;
| Object is the base type of all other types&lt;br /&gt;
|-&lt;br /&gt;
| string &lt;br /&gt;
| String &lt;br /&gt;
| N/A &lt;br /&gt;
| String is the base type for a sequence of chars&lt;br /&gt;
|-&lt;br /&gt;
| decimal &lt;br /&gt;
| Decimal &lt;br /&gt;
| 128 &lt;br /&gt;
| Decimal is an integral type that can represent a decimal number with 29 significant digits ±1.0 × 10e−28 to ±7.9 × 10e28&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Like Java, each primitive data type in C# also has a class associated with it that.  These classes serve a similar purpose to their associated ones in Java.  They are used for comparison of objects, as well as conversion between other similar types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Objects in Ruby ==&lt;br /&gt;
Ruby is a pure object oriented language as compared to languages such as Java or C#, which use a more hybrid approach. In Ruby, all data types are represented as Objects. There are some [http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html inbuilt classes] that are provided to users in Ruby. However, only some of them are a basic building block for forming other types. This subset shown below gives us a list of primitive objects that can be used for data representation and manipulation:&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; padding: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! Description&lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| TrueClass&lt;br /&gt;
| Singleton instance &amp;quot;true&amp;quot; allowed&lt;br /&gt;
| true&lt;br /&gt;
|-&lt;br /&gt;
| FalseClass&lt;br /&gt;
| Singleton instance &amp;quot;false&amp;quot; allowed&lt;br /&gt;
| false&lt;br /&gt;
|-&lt;br /&gt;
| Integer [http://www.ruby-doc.org/core/Integer.html]&lt;br /&gt;
| Abstract class that forms the basis for Fixnum and Bignum&lt;br /&gt;
| See Fixnum and Bignum&lt;br /&gt;
|-&lt;br /&gt;
| Fixnum [http://www.ruby-doc.org/core-1.8.7/Fixnum.html]&lt;br /&gt;
| Integer representations that fit in native machine word&lt;br /&gt;
| Machine architecture dependent. 2^30-1 to -2^30 on 32-bit machines.&lt;br /&gt;
|-&lt;br /&gt;
| Bignum [http://www.ruby-doc.org/core/Bignum.html]&lt;br /&gt;
| Integer representations that do not fit in Fixnum width&lt;br /&gt;
| Machine architecture dependent. Values above Fixnum range.&lt;br /&gt;
|-&lt;br /&gt;
| Float [http://www.ruby-doc.org/core/Float.html]&lt;br /&gt;
| Real numbers using double precision representation&lt;br /&gt;
| Value after decimal point can be formatted&lt;br /&gt;
|-&lt;br /&gt;
| String [http://corelib.rubyonrails.org/classes/String.html]&lt;br /&gt;
| Contains sequence of characters&lt;br /&gt;
| No physical limit, but can be decided by machine architecture&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
One interesting observation from the above table is that Ruby does not have a Boolean class; instead it has a separate TrueClass and FalseClass [http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby].&lt;br /&gt;
&lt;br /&gt;
  puts true.class &lt;br /&gt;
  =&amp;gt; TrueClass&lt;br /&gt;
  puts false.class&lt;br /&gt;
  =&amp;gt; FalseClass&lt;br /&gt;
&lt;br /&gt;
Although types such as Array, Hash are also in-built types, they can be further composed of elements that are internally represented in one of the primitive types. Hence, they will not be treated by us as primitive objects, in the traditional definition of the term.&lt;br /&gt;
Each of the primitive objects listed above also provide certain convenience methods that are applicable for the underlying type.&lt;br /&gt;
For example, the Fixnum, Bignum and Float types provide support for arithmetic operations such as addition (+), subtraction(--), multiplication(*) and so on.&lt;br /&gt;
As with all other classes in Ruby, users can add functionality to existing primitive objects by reopening classes. The amount of memory required to implement the primitive objects in Ruby is machine dependent in some cases.&lt;br /&gt;
&lt;br /&gt;
== Merit Analysis of Primitive Types ==&lt;br /&gt;
This section deals with a brief analysis of the relative merits and demerits of primitive data types. While we focus on Java or Ruby for this purpose, most of these points are applicable across all object oriented languages.&lt;br /&gt;
&lt;br /&gt;
=== Advantages ===&lt;br /&gt;
Primitive types in object oriented languages have certain advantages over their class object counterparts. &lt;br /&gt;
* Simplicity: Primitive types/objects provide users a simple mechanism of manipulating data without relying on additional objects to achieve the same functionality. Operations on primitive types are more intuitive.&lt;br /&gt;
* Efficiency: This statement is applicable if the underlying primitive object definition is not modified (a feature that languages such as Ruby provide to users). As the representation in memory is designed to be make most efficient use of the underlying datatype, use of primitives can provide a benefit to the user, over the use of class objects to store the same data. &lt;br /&gt;
  Eg. Java provides wrappers [http://www.glenmccl.com/tip_016.htm] for certain primitive types. There is a certain performance and space cost associated with these. &lt;br /&gt;
  So, to maximize efficiency, direct use of the primitive types would provide the most benefit.&lt;br /&gt;
* Ability to use inbuilt methods: Depending on the primitive type, languages such as Ruby provide methods that can be used specifically to probe or manipulate objects. &lt;br /&gt;
  Eg. [http://corelib.rubyonrails.org/classes/String.html String] primitive object provides convenience methods such as upcase to convert the entire string to upper case, or capitalize, which converts only the first character to upper case.&lt;br /&gt;
* Ease of testing for comparison: With primitive types, the equality testing operators such as == can be used. These essentially compare the values stored in the primitive types. Regular objects also offer the eql? method for testing equality. However, the following are not equivalent:&lt;br /&gt;
  a=10&lt;br /&gt;
  =&amp;gt; 10&lt;br /&gt;
  a==10&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a==10.0&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a.eql?(10.0)&lt;br /&gt;
  =&amp;gt; false&lt;br /&gt;
The reason the .eql? fails is that this operator tests for value and type being the same. 10 is type Fixnum and 10.0 is type Float. &lt;br /&gt;
The eql? can be overridden by == for primitive objects if you wish to compare only the values, but that can have a negative impact on performance [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html].&lt;br /&gt;
&lt;br /&gt;
=== Disadvantages ===&lt;br /&gt;
* Lack of inheritance capability: The primitive data types in languages such as Java cannot be inherited to create further subtypes.&lt;br /&gt;
* Unexpected results due to method overriding: There are certain examples such as [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html], which show that overriding inbuilt methods such as == and eql? can lead to unexpected results.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Object oriented languages have varying levels of support for primitive data types and objects. Whether they are beneficial or not depends on the application to a great deal. If handled correctly, they can make object oriented programs more efficient. However, the user needs to be aware of the underlying representation of these types to handle any unexpected results.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# http://en.wikipedia.org/wiki/Primitive_data_type&lt;br /&gt;
# http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php&lt;br /&gt;
# http://www.jk-technology.com/c/inttypes.html&lt;br /&gt;
# http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html&lt;br /&gt;
# http://newty.de/fpt/intro.html&lt;br /&gt;
# http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html&lt;br /&gt;
# http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx&lt;br /&gt;
# http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html&lt;br /&gt;
# http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html&lt;br /&gt;
# http://www.glenmccl.com/tip_016.htm&lt;br /&gt;
# http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54290</id>
		<title>CSC/ECE 517 Fall 2011/ch3 3h rr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54290"/>
		<updated>2011-10-29T21:50:53Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''3h. Primitive objects.  At the beginning of Lecture 11, we discovered that Fixnums and Bignums are handled differently behind the scenes in Ruby.  Other languages, like Java, have made similar distinctions.  By contrast, languages such as C# and Eiffel try to hide these implementation differences from users.  Answer two questions: (1) How have different o-o languages implemented primitive objects?  E.g., how are they represented in memory, how are they tested for, do comparisons do anything different than for class objects, etc.  (2) What are the advantages and disadvantages of treating primitives differently from class objects in source code?''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Programming languages, whether statically or dynamically typed, have support for certain in-built data types. These data types, known as primitive types, are the basic representation of information in programs and have certain fixed attributes for a specific language[http://en.wikipedia.org/wiki/Primitive_data_type]. Statically typed languages such as C++, Java, Perl etc. support primitive data types, whereas with dynamically typed languages such as Ruby, Smalltalk, Lisp etc. they are actually in the form of primitive objects.  These primitive types are used to store the basic types of information that a computer can store and manipulate, and can also be used as building blocks for creating more complex data types. &lt;br /&gt;
This article explains the way different primitive types are implemented in certain object oriented languages. An analysis of the benefits and drawbacks of such types and the methods used to operate on them is also presented. &lt;br /&gt;
&lt;br /&gt;
== Primitive Types ==&lt;br /&gt;
The primitive types commonly included in most programming languages are:&lt;br /&gt;
* Boolean&lt;br /&gt;
* Character&lt;br /&gt;
* Integer&lt;br /&gt;
* Floating-point number&lt;br /&gt;
* Fixed-point number&lt;br /&gt;
* Reference&lt;br /&gt;
&lt;br /&gt;
=== Boolean ===&lt;br /&gt;
A Boolean is a primitive data type used to store one of two logical types: true or false.  Boolean data types are most commonly used as input paramters to a conditional statement (such as an ‘if’ statement), or as the output of a comparison between two comparable data types.  Booleans can be implemented in languages as either a discrete logical type, or implicitly as a numerical type.  In many languages, booleans can be implicitly converted to and from integer types.  &lt;br /&gt;
&lt;br /&gt;
=== Character ===&lt;br /&gt;
A character is a data type that represents an element of a written language, such as a letter, number, or symbol.  A character can also represent a control character, such as a carriage return or newline, which does not have a written meaning but controls how other characters are stored or displayed.   Characters are commonly stored as integers, and encoded using a character map.  &lt;br /&gt;
&lt;br /&gt;
=== Integer ===&lt;br /&gt;
An integer is a data type that represents one element of a finite subset of mathematical integers.  Integer, or Integral, data types can be either unsigned (able to store only positive whole numbers) or signed (able to store either positive or negative whole numbers).  The range of values that can be represented by an integer depends on the number of bits used to store the integer, whether or not it is a signed integer, and the encoding scheme (if it is signed).  Typically, an integer has a minimum and maximum value, and can store any integer in the range between those values.  The minimum value for unsigned integers is typically 0, and the maximum value is typically determined by the amount of memory used to store the integer.  For example, a un unsigned 8-bit number can store 2^8 (or 256) possible integral values; and would typically store any value from 0 to 255.  More generally, an n-bit unsigned integer can store from 0 to (2^n)-1.  For signed integers, modern computers use the Two’s Complement encoding scheme.  This allows for a range of −2^(n−1) through 2^(n−1)−1.  For example, an 8-bit signed integer could store any whole number in the range from -128 through +127.&lt;br /&gt;
&lt;br /&gt;
=== Floating-Point Number ===&lt;br /&gt;
A floating point number is a data type used to represent real numbers in a large range with varying degrees of precision.  In this representation, numbers are represented with a variable number of significant digits, and a variable number of exponential digits.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed-Point number ===&lt;br /&gt;
A fixed-point number is a data type used to represent real numbers.  Fixed-point numbers are called fixed-point because they have a set number of digits before and after a decimal mark.  In this regard, fixed-point numbers are represented as an integer, but are scaled by a predetermined factor.  &lt;br /&gt;
&lt;br /&gt;
Fixed-point numbers are commonly used in microprocessors that do not have a floating-point unit, or in systems in which computational efficiency is critical.  Fixed-point numbers can be treated as integers by an arithmetic logic unit (ALU) and scaled after a result is obtained, which can significantly lower the amount of time needed for a processor to obtain the result for some algorithms. &lt;br /&gt;
&lt;br /&gt;
Implementing algorithms using fixed-point arithmetic requires great care, because of the potential for information loss.  Fixed-point arithmetic operations -- multiplication in particular, has the potential to cause overflow.  Algorithms must be written with care to ensure that each term of an equation has a similar range and that the result will not cause an overflow.&lt;br /&gt;
&lt;br /&gt;
=== Reference ===&lt;br /&gt;
&lt;br /&gt;
A Reference is a data type that enables a program to access another item in memory.  A reference differs from other primitive data types in that it does not store data itself; instead it stores a value referring to another data object.  References are commonly used to refer to objects of large non-primitive data types.  References commonly store the physical memory address of the data that they are referring to.  Accessing the data referred to by a Reference is called dereferencing.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C++ ==&lt;br /&gt;
&lt;br /&gt;
C++ is a statically-typed object oriented language.  C++ is based on the C programming language, which is procedural, and adds support for object-oriented code.  &lt;br /&gt;
&lt;br /&gt;
These data types are defined in C++: [http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php] &lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Name &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| void &lt;br /&gt;
| N/A &lt;br /&gt;
| the void data type is used to explicitly identify that a data has no type &lt;br /&gt;
| N/A&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits&lt;br /&gt;
| simple numerical type&lt;br /&gt;
| See [[http://www.jk-technology.com/c/inttypes.html]]&lt;br /&gt;
|-&lt;br /&gt;
| float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 8 bits &lt;br /&gt;
| a char is a single 8-bit character encoded using ASCII &lt;br /&gt;
| Ascii character 0x00 through ascii character 0xFF&lt;br /&gt;
|}&lt;br /&gt;
C++ supports Pointers for all of the types listed in the table above, as well as more complex data types (such as structs).  A Pointer in C++ is a data type that stores the physical address of some other data.  Pointers are created in C++ by using the * operator.  For example, a *Double[] is a pointer to an array of double-precision floating point numbers.  C++ Also supports function pointers -- pointers that reference the beginning address of a function in memory.  They are commonly used to implement callback functions [http://newty.de/fpt/intro.html#what]&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in Java == &lt;br /&gt;
&lt;br /&gt;
Java is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  These data types are defined in Java: [http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html]&lt;br /&gt;
{|style=&amp;quot;border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; padding: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;|Name&lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte&lt;br /&gt;
|8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
|-128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
|16 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647 &lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Java also defines a String class, which is used to create objects of many chars.  The String class provides functionality commonly implemented using arrays of chars in other languages, such as C. &lt;br /&gt;
&lt;br /&gt;
Java also defines the 'unsigned' keyword, which can be used to as a modifier to any of the integral types listed in the table above.  If the 'unsigned' keyword is used, the integral type will be unsigned instead of signed, and its range will change correspondingly. &lt;br /&gt;
&lt;br /&gt;
Java is capable of using any two objects of the same primitive data type for comparison.  Java defines a class for each data type, which have the same name but a capitalized first letter (e.g. Float instead of float).  These classes, called wrapper classes provide a series of methods that can manipulate their associated primitive data type, as well as convert to and from other data types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C# == &lt;br /&gt;
&lt;br /&gt;
C# is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  C# has all of the data types that are available in Java, as well as some additional ones.  &lt;br /&gt;
&lt;br /&gt;
Similar to Java, C# defines a String class which is used to create objects of many chars.  These data types are defined in C#: [http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx]&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; padding: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! .NET Class &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte &lt;br /&gt;
| Byte &lt;br /&gt;
| 8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
| -128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| sbyte &lt;br /&gt;
| SByte &lt;br /&gt;
| 8 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -0 to 255&lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
| Int16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| ushort &lt;br /&gt;
| UInt16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 65,535&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| Int32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647&lt;br /&gt;
|-&lt;br /&gt;
| uint &lt;br /&gt;
| UInt32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 4,294,967,295&lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| Int64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|-&lt;br /&gt;
| ulong &lt;br /&gt;
| UInt64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 18,446,744,073,709,551,615&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| Float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| -3.402823e38 to 3.02823e38&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| Double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| -1.79769313486232e308 to 1.79769313486232e308&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| Boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| Char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|-&lt;br /&gt;
| object &lt;br /&gt;
| Object &lt;br /&gt;
| N/A &lt;br /&gt;
| Object is the base type of all other types&lt;br /&gt;
|-&lt;br /&gt;
| string &lt;br /&gt;
| String &lt;br /&gt;
| N/A &lt;br /&gt;
| String is the base type for a sequence of chars&lt;br /&gt;
|-&lt;br /&gt;
| decimal &lt;br /&gt;
| Decimal &lt;br /&gt;
| 128 &lt;br /&gt;
| Decimal is an integral type that can represent a decimal number with 29 significant digits ±1.0 × 10e−28 to ±7.9 × 10e28&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Like Java, each primitive data type in C# also has a class associated with it that.  These classes serve a similar purpose to their associated ones in Java.  They are used for comparison of objects, as well as conversion between other similar types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Objects in Ruby ==&lt;br /&gt;
Ruby is a pure object oriented language as compared to languages such as Java or C#, which use a more hybrid approach. In Ruby, all data types are represented as Objects. There are some [http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html inbuilt classes] that are provided to users in Ruby. However, only some of them are a basic building block for forming other types. This subset shown below gives us a list of primitive objects that can be used for data representation and manipulation:&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; padding: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! Description&lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| TrueClass&lt;br /&gt;
| Singleton instance &amp;quot;true&amp;quot; allowed&lt;br /&gt;
| true&lt;br /&gt;
|-&lt;br /&gt;
| FalseClass&lt;br /&gt;
| Singleton instance &amp;quot;false&amp;quot; allowed&lt;br /&gt;
| false&lt;br /&gt;
|-&lt;br /&gt;
| Integer [http://www.ruby-doc.org/core/Integer.html]&lt;br /&gt;
| Abstract class that forms the basis for Fixnum and Bignum&lt;br /&gt;
| See Fixnum and Bignum&lt;br /&gt;
|-&lt;br /&gt;
| Fixnum [http://www.ruby-doc.org/core-1.8.7/Fixnum.html]&lt;br /&gt;
| Integer representations that fit in native machine word&lt;br /&gt;
| Machine architecture dependent. 2^30-1 to -2^30 on 32-bit machines.&lt;br /&gt;
|-&lt;br /&gt;
| Bignum [http://www.ruby-doc.org/core/Bignum.html]&lt;br /&gt;
| Integer representations that do not fit in Fixnum width&lt;br /&gt;
| Machine architecture dependent. Values above Fixnum range.&lt;br /&gt;
|-&lt;br /&gt;
| Float [http://www.ruby-doc.org/core/Float.html]&lt;br /&gt;
| Real numbers using double precision representation&lt;br /&gt;
| Value after decimal point can be formatted&lt;br /&gt;
|-&lt;br /&gt;
| String [http://corelib.rubyonrails.org/classes/String.html]&lt;br /&gt;
| Contains sequence of characters&lt;br /&gt;
| No physical limit, but can be decided by machine architecture&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
One interesting observation from the above table is that Ruby does not have a Boolean class; instead it has a separate TrueClass and FalseClass [http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby].&lt;br /&gt;
&lt;br /&gt;
  puts true.class &lt;br /&gt;
  =&amp;gt; TrueClass&lt;br /&gt;
  puts false.class&lt;br /&gt;
  =&amp;gt; FalseClass&lt;br /&gt;
&lt;br /&gt;
Although types such as Array, Hash are also in-built types, they can be further composed of elements that are internally represented in one of the primitive types. Hence, they will not be treated by us as primitive objects, in the traditional definition of the term.&lt;br /&gt;
Each of the primitive objects listed above also provide certain convenience methods that are applicable for the underlying type.&lt;br /&gt;
For example, the Fixnum, Bignum and Float types provide support for arithmetic operations such as addition (+), subtraction(--), multiplication(*) and so on.&lt;br /&gt;
As with all other classes in Ruby, users can add functionality to existing primitive objects by reopening classes. The amount of memory required to implement the primitive objects in Ruby is machine dependent in some cases.&lt;br /&gt;
&lt;br /&gt;
== Merit Analysis of Primitive Types ==&lt;br /&gt;
This section deals with a brief analysis of the relative merits and demerits of primitive data types. While we focus on Java or Ruby for this purpose, most of these points are applicable across all object oriented languages.&lt;br /&gt;
&lt;br /&gt;
=== Advantages ===&lt;br /&gt;
Primitive types in object oriented languages have certain advantages over their class object counterparts. &lt;br /&gt;
* Simplicity: Primitive types/objects provide users a simple mechanism of manipulating data without relying on additional objects to achieve the same functionality. Operations on primitive types are more intuitive.&lt;br /&gt;
* Efficiency: This statement is applicable if the underlying primitive object definition is not modified (a feature that languages such as Ruby provide to users). As the representation in memory is designed to be make most efficient use of the underlying datatype, use of primitives can provide a benefit to the user, over the use of class objects to store the same data. &lt;br /&gt;
  Eg. Java provides wrappers [http://www.glenmccl.com/tip_016.htm] for certain primitive types. There is a certain performance and space cost associated with these. &lt;br /&gt;
  So, to maximize efficiency, direct use of the primitive types would provide the most benefit.&lt;br /&gt;
* Ability to use inbuilt methods: Depending on the primitive type, languages such as Ruby provide methods that can be used specifically to probe or manipulate objects. &lt;br /&gt;
  Eg. [http://corelib.rubyonrails.org/classes/String.html String] primitive object provides convenience methods such as upcase to convert the entire string to upper case, or capitalize, which converts only the first character to upper case.&lt;br /&gt;
* Ease of testing for comparison: With primitive types, the equality testing operators such as == can be used. These essentially compare the values stored in the primitive types. Regular objects also offer the eql? method for testing equality. However, the following are not equivalent:&lt;br /&gt;
  a=10&lt;br /&gt;
  =&amp;gt; 10&lt;br /&gt;
  a==10&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a==10.0&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a.eql?(10.0)&lt;br /&gt;
  =&amp;gt; false&lt;br /&gt;
The reason the .eql? fails is that this operator tests for value and type being the same. 10 is type Fixnum and 10.0 is type Float. &lt;br /&gt;
The eql? can be overridden by == for primitive objects if you wish to compare only the values, but that can have a negative impact on performance [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html].&lt;br /&gt;
&lt;br /&gt;
=== Disadvantages ===&lt;br /&gt;
* Lack of inheritance capability: The primitive data types in languages such as Java cannot be inherited to create further subtypes.&lt;br /&gt;
* Unexpected results due to method overriding: There are certain examples such as [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html], which show that overriding inbuilt methods such as == and eql? can lead to unexpected results.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Object oriented languages have varying levels of support for primitive data types and objects. Whether they are beneficial or not depends on the application to a great deal. If handled correctly, they can make object oriented programs more efficient. However, the user needs to be aware of the underlying representation of these types to handle any unexpected results.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# http://en.wikipedia.org/wiki/Primitive_data_type&lt;br /&gt;
# http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php&lt;br /&gt;
# http://www.jk-technology.com/c/inttypes.html&lt;br /&gt;
# http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html&lt;br /&gt;
# http://newty.de/fpt/intro.html&lt;br /&gt;
# http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html&lt;br /&gt;
# http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx&lt;br /&gt;
# http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html&lt;br /&gt;
# http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html&lt;br /&gt;
# http://www.glenmccl.com/tip_016.htm&lt;br /&gt;
# http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54289</id>
		<title>CSC/ECE 517 Fall 2011/ch3 3h rr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54289"/>
		<updated>2011-10-29T21:47:56Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''3h. Primitive objects.  At the beginning of Lecture 11, we discovered that Fixnums and Bignums are handled differently behind the scenes in Ruby.  Other languages, like Java, have made similar distinctions.  By contrast, languages such as C# and Eiffel try to hide these implementation differences from users.  Answer two questions: (1) How have different o-o languages implemented primitive objects?  E.g., how are they represented in memory, how are they tested for, do comparisons do anything different than for class objects, etc.  (2) What are the advantages and disadvantages of treating primitives differently from class objects in source code?''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Programming languages, whether statically or dynamically typed, have support for certain in-built data types. These data types, known as primitive types, are the basic representation of information in programs and have certain fixed attributes for a specific language[http://en.wikipedia.org/wiki/Primitive_data_type]. Statically typed languages such as C++, Java, Perl etc. support primitive data types, whereas with dynamically typed languages such as Ruby, Smalltalk, Lisp etc. they are actually in the form of primitive objects.  These primitive types are used to store the basic types of information that a computer can store and manipulate, and can also be used as building blocks for creating more complex data types. &lt;br /&gt;
This article explains the way different primitive types are implemented in certain object oriented languages. An analysis of the benefits and drawbacks of such types and the methods used to operate on them is also presented. &lt;br /&gt;
&lt;br /&gt;
== Primitive Types ==&lt;br /&gt;
The primitive types commonly included in most programming languages are:&lt;br /&gt;
* Boolean&lt;br /&gt;
* Character&lt;br /&gt;
* Integer&lt;br /&gt;
* Floating-point number&lt;br /&gt;
* Fixed-point number&lt;br /&gt;
* Reference&lt;br /&gt;
&lt;br /&gt;
=== Boolean ===&lt;br /&gt;
A Boolean is a primitive data type used to store one of two logical types: true or false.  Boolean data types are most commonly used as input paramters to a conditional statement (such as an ‘if’ statement), or as the output of a comparison between two comparable data types.  Booleans can be implemented in languages as either a discrete logical type, or implicitly as a numerical type.  In many languages, booleans can be implicitly converted to and from integer types.  &lt;br /&gt;
&lt;br /&gt;
=== Character ===&lt;br /&gt;
A character is a data type that represents an element of a written language, such as a letter, number, or symbol.  A character can also represent a control character, such as a carriage return or newline, which does not have a written meaning but controls how other characters are stored or displayed.   Characters are commonly stored as integers, and encoded using a character map.  &lt;br /&gt;
&lt;br /&gt;
=== Integer ===&lt;br /&gt;
An integer is a data type that represents one element of a finite subset of mathematical integers.  Integer, or Integral, data types can be either unsigned (able to store only positive whole numbers) or signed (able to store either positive or negative whole numbers).  The range of values that can be represented by an integer depends on the number of bits used to store the integer, whether or not it is a signed integer, and the encoding scheme (if it is signed).  Typically, an integer has a minimum and maximum value, and can store any integer in the range between those values.  The minimum value for unsigned integers is typically 0, and the maximum value is typically determined by the amount of memory used to store the integer.  For example, a un unsigned 8-bit number can store 2^8 (or 256) possible integral values; and would typically store any value from 0 to 255.  More generally, an n-bit unsigned integer can store from 0 to (2^n)-1.  For signed integers, modern computers use the Two’s Complement encoding scheme.  This allows for a range of −2^(n−1) through 2^(n−1)−1.  For example, an 8-bit signed integer could store any whole number in the range from -128 through +127.&lt;br /&gt;
&lt;br /&gt;
=== Floating-Point Number ===&lt;br /&gt;
A floating point number is a data type used to represent real numbers in a large range with varying degrees of precision.  In this representation, numbers are represented with a variable number of significant digits, and a variable number of exponential digits.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed-Point number ===&lt;br /&gt;
A fixed-point number is a data type used to represent real numbers.  Fixed-point numbers are called fixed-point because they have a set number of digits before and after a decimal mark.  In this regard, fixed-point numbers are represented as an integer, but are scaled by a predetermined factor.  &lt;br /&gt;
&lt;br /&gt;
Fixed-point numbers are commonly used in microprocessors that do not have a floating-point unit, or in systems in which computational efficiency is critical.  Fixed-point numbers can be treated as integers by an arithmetic logic unit (ALU) and scaled after a result is obtained, which can significantly lower the amount of time needed for a processor to obtain the result for some algorithms. &lt;br /&gt;
&lt;br /&gt;
Implementing algorithms using fixed-point arithmetic requires great care, because of the potential for information loss.  Fixed-point arithmetic operations -- multiplication in particular, has the potential to cause overflow.  Algorithms must be written with care to ensure that each term of an equation has a similar range and that the result will not cause an overflow.&lt;br /&gt;
&lt;br /&gt;
=== Reference ===&lt;br /&gt;
&lt;br /&gt;
A Reference is a data type that enables a program to access another item in memory.  A reference differs from other primitive data types in that it does not store data itself; instead it stores a value referring to another data object.  References are commonly used to refer to objects of large non-primitive data types.  References commonly store the physical memory address of the data that they are referring to.  Accessing the data referred to by a Reference is called dereferencing.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C++ ==&lt;br /&gt;
&lt;br /&gt;
C++ is a statically-typed object oriented language.  C++ is based on the C programming language, which is procedural, and adds support for object-oriented code.  &lt;br /&gt;
&lt;br /&gt;
These data types are defined in C++: [http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php] &lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; padding: 0&amp;quot;&lt;br /&gt;
!style=&amp;quot;border-style: solid; border-width: 1px&amp;quot; align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
!style=&amp;quot;border-style: solid; border-width: 1px&amp;quot; align=&amp;quot;left&amp;quot;| Size &lt;br /&gt;
!style=&amp;quot;border-style: solid; border-width: 1px&amp;quot; align=&amp;quot;left&amp;quot;| Description &lt;br /&gt;
!style=&amp;quot;border-style: solid; border-width: 1px&amp;quot; align=&amp;quot;left&amp;quot;| Range&lt;br /&gt;
|-&lt;br /&gt;
| void &lt;br /&gt;
| N/A &lt;br /&gt;
| the void data type is used to explicitly identify that a data has no type &lt;br /&gt;
| N/A&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits&lt;br /&gt;
| simple numerical type&lt;br /&gt;
| See [[http://www.jk-technology.com/c/inttypes.html]]&lt;br /&gt;
|-&lt;br /&gt;
| float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 8 bits &lt;br /&gt;
| a char is a single 8-bit character encoded using ASCII &lt;br /&gt;
| Ascii character 0x00 through ascii character 0xFF&lt;br /&gt;
|}&lt;br /&gt;
C++ supports Pointers for all of the types listed in the table above, as well as more complex data types (such as structs).  A Pointer in C++ is a data type that stores the physical address of some other data.  Pointers are created in C++ by using the * operator.  For example, a *Double[] is a pointer to an array of double-precision floating point numbers.  C++ Also supports function pointers -- pointers that reference the beginning address of a function in memory.  They are commonly used to implement callback functions [http://newty.de/fpt/intro.html#what]&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in Java == &lt;br /&gt;
&lt;br /&gt;
Java is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  These data types are defined in Java: [http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html]&lt;br /&gt;
{|style=&amp;quot;border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; padding: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;|Name&lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte&lt;br /&gt;
|8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
|-128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
|16 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647 &lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Java also defines a String class, which is used to create objects of many chars.  The String class provides functionality commonly implemented using arrays of chars in other languages, such as C. &lt;br /&gt;
&lt;br /&gt;
Java also defines the 'unsigned' keyword, which can be used to as a modifier to any of the integral types listed in the table above.  If the 'unsigned' keyword is used, the integral type will be unsigned instead of signed, and its range will change correspondingly. &lt;br /&gt;
&lt;br /&gt;
Java is capable of using any two objects of the same primitive data type for comparison.  Java defines a class for each data type, which have the same name but a capitalized first letter (e.g. Float instead of float).  These classes, called wrapper classes provide a series of methods that can manipulate their associated primitive data type, as well as convert to and from other data types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C# == &lt;br /&gt;
&lt;br /&gt;
C# is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  C# has all of the data types that are available in Java, as well as some additional ones.  &lt;br /&gt;
&lt;br /&gt;
Similar to Java, C# defines a String class which is used to create objects of many chars.  These data types are defined in C#: [http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx]&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; padding: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! .NET Class &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte &lt;br /&gt;
| Byte &lt;br /&gt;
| 8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
| -128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| sbyte &lt;br /&gt;
| SByte &lt;br /&gt;
| 8 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -0 to 255&lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
| Int16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| ushort &lt;br /&gt;
| UInt16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 65,535&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| Int32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647&lt;br /&gt;
|-&lt;br /&gt;
| uint &lt;br /&gt;
| UInt32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 4,294,967,295&lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| Int64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|-&lt;br /&gt;
| ulong &lt;br /&gt;
| UInt64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 18,446,744,073,709,551,615&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| Float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| -3.402823e38 to 3.02823e38&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| Double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| -1.79769313486232e308 to 1.79769313486232e308&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| Boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| Char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|-&lt;br /&gt;
| object &lt;br /&gt;
| Object &lt;br /&gt;
| N/A &lt;br /&gt;
| Object is the base type of all other types&lt;br /&gt;
|-&lt;br /&gt;
| string &lt;br /&gt;
| String &lt;br /&gt;
| N/A &lt;br /&gt;
| String is the base type for a sequence of chars&lt;br /&gt;
|-&lt;br /&gt;
| decimal &lt;br /&gt;
| Decimal &lt;br /&gt;
| 128 &lt;br /&gt;
| Decimal is an integral type that can represent a decimal number with 29 significant digits ±1.0 × 10e−28 to ±7.9 × 10e28&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Like Java, each primitive data type in C# also has a class associated with it that.  These classes serve a similar purpose to their associated ones in Java.  They are used for comparison of objects, as well as conversion between other similar types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Objects in Ruby ==&lt;br /&gt;
Ruby is a pure object oriented language as compared to languages such as Java or C#, which use a more hybrid approach. In Ruby, all data types are represented as Objects. There are some [http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html inbuilt classes] that are provided to users in Ruby. However, only some of them are a basic building block for forming other types. This subset shown below gives us a list of primitive objects that can be used for data representation and manipulation:&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; padding: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! Description&lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| TrueClass&lt;br /&gt;
| Singleton instance &amp;quot;true&amp;quot; allowed&lt;br /&gt;
| true&lt;br /&gt;
|-&lt;br /&gt;
| FalseClass&lt;br /&gt;
| Singleton instance &amp;quot;false&amp;quot; allowed&lt;br /&gt;
| false&lt;br /&gt;
|-&lt;br /&gt;
| Integer [http://www.ruby-doc.org/core/Integer.html]&lt;br /&gt;
| Abstract class that forms the basis for Fixnum and Bignum&lt;br /&gt;
| See Fixnum and Bignum&lt;br /&gt;
|-&lt;br /&gt;
| Fixnum [http://www.ruby-doc.org/core-1.8.7/Fixnum.html]&lt;br /&gt;
| Integer representations that fit in native machine word&lt;br /&gt;
| Machine architecture dependent. 2^30-1 to -2^30 on 32-bit machines.&lt;br /&gt;
|-&lt;br /&gt;
| Bignum [http://www.ruby-doc.org/core/Bignum.html]&lt;br /&gt;
| Integer representations that do not fit in Fixnum width&lt;br /&gt;
| Machine architecture dependent. Values above Fixnum range.&lt;br /&gt;
|-&lt;br /&gt;
| Float [http://www.ruby-doc.org/core/Float.html]&lt;br /&gt;
| Real numbers using double precision representation&lt;br /&gt;
| Value after decimal point can be formatted&lt;br /&gt;
|-&lt;br /&gt;
| String [http://corelib.rubyonrails.org/classes/String.html]&lt;br /&gt;
| Contains sequence of characters&lt;br /&gt;
| No physical limit, but can be decided by machine architecture&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
One interesting observation from the above table is that Ruby does not have a Boolean class; instead it has a separate TrueClass and FalseClass [http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby].&lt;br /&gt;
&lt;br /&gt;
  puts true.class &lt;br /&gt;
  =&amp;gt; TrueClass&lt;br /&gt;
  puts false.class&lt;br /&gt;
  =&amp;gt; FalseClass&lt;br /&gt;
&lt;br /&gt;
Although types such as Array, Hash are also in-built types, they can be further composed of elements that are internally represented in one of the primitive types. Hence, they will not be treated by us as primitive objects, in the traditional definition of the term.&lt;br /&gt;
Each of the primitive objects listed above also provide certain convenience methods that are applicable for the underlying type.&lt;br /&gt;
For example, the Fixnum, Bignum and Float types provide support for arithmetic operations such as addition (+), subtraction(--), multiplication(*) and so on.&lt;br /&gt;
As with all other classes in Ruby, users can add functionality to existing primitive objects by reopening classes. The amount of memory required to implement the primitive objects in Ruby is machine dependent in some cases.&lt;br /&gt;
&lt;br /&gt;
== Merit Analysis of Primitive Types ==&lt;br /&gt;
This section deals with a brief analysis of the relative merits and demerits of primitive data types. While we focus on Java or Ruby for this purpose, most of these points are applicable across all object oriented languages.&lt;br /&gt;
&lt;br /&gt;
=== Advantages ===&lt;br /&gt;
Primitive types in object oriented languages have certain advantages over their class object counterparts. &lt;br /&gt;
* Simplicity: Primitive types/objects provide users a simple mechanism of manipulating data without relying on additional objects to achieve the same functionality. Operations on primitive types are more intuitive.&lt;br /&gt;
* Efficiency: This statement is applicable if the underlying primitive object definition is not modified (a feature that languages such as Ruby provide to users). As the representation in memory is designed to be make most efficient use of the underlying datatype, use of primitives can provide a benefit to the user, over the use of class objects to store the same data. &lt;br /&gt;
  Eg. Java provides wrappers [http://www.glenmccl.com/tip_016.htm] for certain primitive types. There is a certain performance and space cost associated with these. &lt;br /&gt;
  So, to maximize efficiency, direct use of the primitive types would provide the most benefit.&lt;br /&gt;
* Ability to use inbuilt methods: Depending on the primitive type, languages such as Ruby provide methods that can be used specifically to probe or manipulate objects. &lt;br /&gt;
  Eg. [http://corelib.rubyonrails.org/classes/String.html String] primitive object provides convenience methods such as upcase to convert the entire string to upper case, or capitalize, which converts only the first character to upper case.&lt;br /&gt;
* Ease of testing for comparison: With primitive types, the equality testing operators such as == can be used. These essentially compare the values stored in the primitive types. Regular objects also offer the eql? method for testing equality. However, the following are not equivalent:&lt;br /&gt;
  a=10&lt;br /&gt;
  =&amp;gt; 10&lt;br /&gt;
  a==10&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a==10.0&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a.eql?(10.0)&lt;br /&gt;
  =&amp;gt; false&lt;br /&gt;
The reason the .eql? fails is that this operator tests for value and type being the same. 10 is type Fixnum and 10.0 is type Float. &lt;br /&gt;
The eql? can be overridden by == for primitive objects if you wish to compare only the values, but that can have a negative impact on performance [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html].&lt;br /&gt;
&lt;br /&gt;
=== Disadvantages ===&lt;br /&gt;
* Lack of inheritance capability: The primitive data types in languages such as Java cannot be inherited to create further subtypes.&lt;br /&gt;
* Unexpected results due to method overriding: There are certain examples such as [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html], which show that overriding inbuilt methods such as == and eql? can lead to unexpected results.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Object oriented languages have varying levels of support for primitive data types and objects. Whether they are beneficial or not depends on the application to a great deal. If handled correctly, they can make object oriented programs more efficient. However, the user needs to be aware of the underlying representation of these types to handle any unexpected results.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# http://en.wikipedia.org/wiki/Primitive_data_type&lt;br /&gt;
# http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php&lt;br /&gt;
# http://www.jk-technology.com/c/inttypes.html&lt;br /&gt;
# http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html&lt;br /&gt;
# http://newty.de/fpt/intro.html&lt;br /&gt;
# http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html&lt;br /&gt;
# http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx&lt;br /&gt;
# http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html&lt;br /&gt;
# http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html&lt;br /&gt;
# http://www.glenmccl.com/tip_016.htm&lt;br /&gt;
# http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54288</id>
		<title>CSC/ECE 517 Fall 2011/ch3 3h rr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54288"/>
		<updated>2011-10-29T21:45:44Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''3h. Primitive objects.  At the beginning of Lecture 11, we discovered that Fixnums and Bignums are handled differently behind the scenes in Ruby.  Other languages, like Java, have made similar distinctions.  By contrast, languages such as C# and Eiffel try to hide these implementation differences from users.  Answer two questions: (1) How have different o-o languages implemented primitive objects?  E.g., how are they represented in memory, how are they tested for, do comparisons do anything different than for class objects, etc.  (2) What are the advantages and disadvantages of treating primitives differently from class objects in source code?''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Programming languages, whether statically or dynamically typed, have support for certain in-built data types. These data types, known as primitive types, are the basic representation of information in programs and have certain fixed attributes for a specific language[http://en.wikipedia.org/wiki/Primitive_data_type]. Statically typed languages such as C++, Java, Perl etc. support primitive data types, whereas with dynamically typed languages such as Ruby, Smalltalk, Lisp etc. they are actually in the form of primitive objects.  These primitive types are used to store the basic types of information that a computer can store and manipulate, and can also be used as building blocks for creating more complex data types. &lt;br /&gt;
This article explains the way different primitive types are implemented in certain object oriented languages. An analysis of the benefits and drawbacks of such types and the methods used to operate on them is also presented. &lt;br /&gt;
&lt;br /&gt;
== Primitive Types ==&lt;br /&gt;
The primitive types commonly included in most programming languages are:&lt;br /&gt;
* Boolean&lt;br /&gt;
* Character&lt;br /&gt;
* Integer&lt;br /&gt;
* Floating-point number&lt;br /&gt;
* Fixed-point number&lt;br /&gt;
* Reference&lt;br /&gt;
&lt;br /&gt;
=== Boolean ===&lt;br /&gt;
A Boolean is a primitive data type used to store one of two logical types: true or false.  Boolean data types are most commonly used as input paramters to a conditional statement (such as an ‘if’ statement), or as the output of a comparison between two comparable data types.  Booleans can be implemented in languages as either a discrete logical type, or implicitly as a numerical type.  In many languages, booleans can be implicitly converted to and from integer types.  &lt;br /&gt;
&lt;br /&gt;
=== Character ===&lt;br /&gt;
A character is a data type that represents an element of a written language, such as a letter, number, or symbol.  A character can also represent a control character, such as a carriage return or newline, which does not have a written meaning but controls how other characters are stored or displayed.   Characters are commonly stored as integers, and encoded using a character map.  &lt;br /&gt;
&lt;br /&gt;
=== Integer ===&lt;br /&gt;
An integer is a data type that represents one element of a finite subset of mathematical integers.  Integer, or Integral, data types can be either unsigned (able to store only positive whole numbers) or signed (able to store either positive or negative whole numbers).  The range of values that can be represented by an integer depends on the number of bits used to store the integer, whether or not it is a signed integer, and the encoding scheme (if it is signed).  Typically, an integer has a minimum and maximum value, and can store any integer in the range between those values.  The minimum value for unsigned integers is typically 0, and the maximum value is typically determined by the amount of memory used to store the integer.  For example, a un unsigned 8-bit number can store 2^8 (or 256) possible integral values; and would typically store any value from 0 to 255.  More generally, an n-bit unsigned integer can store from 0 to (2^n)-1.  For signed integers, modern computers use the Two’s Complement encoding scheme.  This allows for a range of −2^(n−1) through 2^(n−1)−1.  For example, an 8-bit signed integer could store any whole number in the range from -128 through +127.&lt;br /&gt;
&lt;br /&gt;
=== Floating-Point Number ===&lt;br /&gt;
A floating point number is a data type used to represent real numbers in a large range with varying degrees of precision.  In this representation, numbers are represented with a variable number of significant digits, and a variable number of exponential digits.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed-Point number ===&lt;br /&gt;
A fixed-point number is a data type used to represent real numbers.  Fixed-point numbers are called fixed-point because they have a set number of digits before and after a decimal mark.  In this regard, fixed-point numbers are represented as an integer, but are scaled by a predetermined factor.  &lt;br /&gt;
&lt;br /&gt;
Fixed-point numbers are commonly used in microprocessors that do not have a floating-point unit, or in systems in which computational efficiency is critical.  Fixed-point numbers can be treated as integers by an arithmetic logic unit (ALU) and scaled after a result is obtained, which can significantly lower the amount of time needed for a processor to obtain the result for some algorithms. &lt;br /&gt;
&lt;br /&gt;
Implementing algorithms using fixed-point arithmetic requires great care, because of the potential for information loss.  Fixed-point arithmetic operations -- multiplication in particular, has the potential to cause overflow.  Algorithms must be written with care to ensure that each term of an equation has a similar range and that the result will not cause an overflow.&lt;br /&gt;
&lt;br /&gt;
=== Reference ===&lt;br /&gt;
&lt;br /&gt;
A Reference is a data type that enables a program to access another item in memory.  A reference differs from other primitive data types in that it does not store data itself; instead it stores a value referring to another data object.  References are commonly used to refer to objects of large non-primitive data types.  References commonly store the physical memory address of the data that they are referring to.  Accessing the data referred to by a Reference is called dereferencing.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C++ ==&lt;br /&gt;
&lt;br /&gt;
C++ is a statically-typed object oriented language.  C++ is based on the C programming language, which is procedural, and adds support for object-oriented code.  &lt;br /&gt;
&lt;br /&gt;
These data types are defined in C++: [http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php] &lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; padding: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;|Name &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| void &lt;br /&gt;
| N/A &lt;br /&gt;
| the void data type is used to explicitly identify that a data has no type &lt;br /&gt;
| N/A&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits&lt;br /&gt;
| simple numerical type&lt;br /&gt;
| See [[http://www.jk-technology.com/c/inttypes.html]]&lt;br /&gt;
|-&lt;br /&gt;
| float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 8 bits &lt;br /&gt;
| a char is a single 8-bit character encoded using ASCII &lt;br /&gt;
| Ascii character 0x00 through ascii character 0xFF&lt;br /&gt;
|}&lt;br /&gt;
C++ supports Pointers for all of the types listed in the table above, as well as more complex data types (such as structs).  A Pointer in C++ is a data type that stores the physical address of some other data.  Pointers are created in C++ by using the * operator.  For example, a *Double[] is a pointer to an array of double-precision floating point numbers.  C++ Also supports function pointers -- pointers that reference the beginning address of a function in memory.  They are commonly used to implement callback functions [http://newty.de/fpt/intro.html#what]&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in Java == &lt;br /&gt;
&lt;br /&gt;
Java is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  These data types are defined in Java: [http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html]&lt;br /&gt;
{|style=&amp;quot;border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; padding: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;|Name&lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte&lt;br /&gt;
|8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
|-128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
|16 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647 &lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Java also defines a String class, which is used to create objects of many chars.  The String class provides functionality commonly implemented using arrays of chars in other languages, such as C. &lt;br /&gt;
&lt;br /&gt;
Java also defines the 'unsigned' keyword, which can be used to as a modifier to any of the integral types listed in the table above.  If the 'unsigned' keyword is used, the integral type will be unsigned instead of signed, and its range will change correspondingly. &lt;br /&gt;
&lt;br /&gt;
Java is capable of using any two objects of the same primitive data type for comparison.  Java defines a class for each data type, which have the same name but a capitalized first letter (e.g. Float instead of float).  These classes, called wrapper classes provide a series of methods that can manipulate their associated primitive data type, as well as convert to and from other data types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C# == &lt;br /&gt;
&lt;br /&gt;
C# is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  C# has all of the data types that are available in Java, as well as some additional ones.  &lt;br /&gt;
&lt;br /&gt;
Similar to Java, C# defines a String class which is used to create objects of many chars.  These data types are defined in C#: [http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx]&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; padding: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! .NET Class &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte &lt;br /&gt;
| Byte &lt;br /&gt;
| 8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
| -128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| sbyte &lt;br /&gt;
| SByte &lt;br /&gt;
| 8 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -0 to 255&lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
| Int16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| ushort &lt;br /&gt;
| UInt16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 65,535&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| Int32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647&lt;br /&gt;
|-&lt;br /&gt;
| uint &lt;br /&gt;
| UInt32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 4,294,967,295&lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| Int64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|-&lt;br /&gt;
| ulong &lt;br /&gt;
| UInt64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 18,446,744,073,709,551,615&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| Float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| -3.402823e38 to 3.02823e38&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| Double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| -1.79769313486232e308 to 1.79769313486232e308&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| Boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| Char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|-&lt;br /&gt;
| object &lt;br /&gt;
| Object &lt;br /&gt;
| N/A &lt;br /&gt;
| Object is the base type of all other types&lt;br /&gt;
|-&lt;br /&gt;
| string &lt;br /&gt;
| String &lt;br /&gt;
| N/A &lt;br /&gt;
| String is the base type for a sequence of chars&lt;br /&gt;
|-&lt;br /&gt;
| decimal &lt;br /&gt;
| Decimal &lt;br /&gt;
| 128 &lt;br /&gt;
| Decimal is an integral type that can represent a decimal number with 29 significant digits ±1.0 × 10e−28 to ±7.9 × 10e28&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Like Java, each primitive data type in C# also has a class associated with it that.  These classes serve a similar purpose to their associated ones in Java.  They are used for comparison of objects, as well as conversion between other similar types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Objects in Ruby ==&lt;br /&gt;
Ruby is a pure object oriented language as compared to languages such as Java or C#, which use a more hybrid approach. In Ruby, all data types are represented as Objects. There are some [http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html inbuilt classes] that are provided to users in Ruby. However, only some of them are a basic building block for forming other types. This subset shown below gives us a list of primitive objects that can be used for data representation and manipulation:&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; padding: 0&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! Description&lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| TrueClass&lt;br /&gt;
| Singleton instance &amp;quot;true&amp;quot; allowed&lt;br /&gt;
| true&lt;br /&gt;
|-&lt;br /&gt;
| FalseClass&lt;br /&gt;
| Singleton instance &amp;quot;false&amp;quot; allowed&lt;br /&gt;
| false&lt;br /&gt;
|-&lt;br /&gt;
| Integer [http://www.ruby-doc.org/core/Integer.html]&lt;br /&gt;
| Abstract class that forms the basis for Fixnum and Bignum&lt;br /&gt;
| See Fixnum and Bignum&lt;br /&gt;
|-&lt;br /&gt;
| Fixnum [http://www.ruby-doc.org/core-1.8.7/Fixnum.html]&lt;br /&gt;
| Integer representations that fit in native machine word&lt;br /&gt;
| Machine architecture dependent. 2^30-1 to -2^30 on 32-bit machines.&lt;br /&gt;
|-&lt;br /&gt;
| Bignum [http://www.ruby-doc.org/core/Bignum.html]&lt;br /&gt;
| Integer representations that do not fit in Fixnum width&lt;br /&gt;
| Machine architecture dependent. Values above Fixnum range.&lt;br /&gt;
|-&lt;br /&gt;
| Float [http://www.ruby-doc.org/core/Float.html]&lt;br /&gt;
| Real numbers using double precision representation&lt;br /&gt;
| Value after decimal point can be formatted&lt;br /&gt;
|-&lt;br /&gt;
| String [http://corelib.rubyonrails.org/classes/String.html]&lt;br /&gt;
| Contains sequence of characters&lt;br /&gt;
| No physical limit, but can be decided by machine architecture&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
One interesting observation from the above table is that Ruby does not have a Boolean class; instead it has a separate TrueClass and FalseClass [http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby].&lt;br /&gt;
&lt;br /&gt;
  puts true.class &lt;br /&gt;
  =&amp;gt; TrueClass&lt;br /&gt;
  puts false.class&lt;br /&gt;
  =&amp;gt; FalseClass&lt;br /&gt;
&lt;br /&gt;
Although types such as Array, Hash are also in-built types, they can be further composed of elements that are internally represented in one of the primitive types. Hence, they will not be treated by us as primitive objects, in the traditional definition of the term.&lt;br /&gt;
Each of the primitive objects listed above also provide certain convenience methods that are applicable for the underlying type.&lt;br /&gt;
For example, the Fixnum, Bignum and Float types provide support for arithmetic operations such as addition (+), subtraction(--), multiplication(*) and so on.&lt;br /&gt;
As with all other classes in Ruby, users can add functionality to existing primitive objects by reopening classes. The amount of memory required to implement the primitive objects in Ruby is machine dependent in some cases.&lt;br /&gt;
&lt;br /&gt;
== Merit Analysis of Primitive Types ==&lt;br /&gt;
This section deals with a brief analysis of the relative merits and demerits of primitive data types. While we focus on Java or Ruby for this purpose, most of these points are applicable across all object oriented languages.&lt;br /&gt;
&lt;br /&gt;
=== Advantages ===&lt;br /&gt;
Primitive types in object oriented languages have certain advantages over their class object counterparts. &lt;br /&gt;
* Simplicity: Primitive types/objects provide users a simple mechanism of manipulating data without relying on additional objects to achieve the same functionality. Operations on primitive types are more intuitive.&lt;br /&gt;
* Efficiency: This statement is applicable if the underlying primitive object definition is not modified (a feature that languages such as Ruby provide to users). As the representation in memory is designed to be make most efficient use of the underlying datatype, use of primitives can provide a benefit to the user, over the use of class objects to store the same data. &lt;br /&gt;
  Eg. Java provides wrappers [http://www.glenmccl.com/tip_016.htm] for certain primitive types. There is a certain performance and space cost associated with these. &lt;br /&gt;
  So, to maximize efficiency, direct use of the primitive types would provide the most benefit.&lt;br /&gt;
* Ability to use inbuilt methods: Depending on the primitive type, languages such as Ruby provide methods that can be used specifically to probe or manipulate objects. &lt;br /&gt;
  Eg. [http://corelib.rubyonrails.org/classes/String.html String] primitive object provides convenience methods such as upcase to convert the entire string to upper case, or capitalize, which converts only the first character to upper case.&lt;br /&gt;
* Ease of testing for comparison: With primitive types, the equality testing operators such as == can be used. These essentially compare the values stored in the primitive types. Regular objects also offer the eql? method for testing equality. However, the following are not equivalent:&lt;br /&gt;
  a=10&lt;br /&gt;
  =&amp;gt; 10&lt;br /&gt;
  a==10&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a==10.0&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a.eql?(10.0)&lt;br /&gt;
  =&amp;gt; false&lt;br /&gt;
The reason the .eql? fails is that this operator tests for value and type being the same. 10 is type Fixnum and 10.0 is type Float. &lt;br /&gt;
The eql? can be overridden by == for primitive objects if you wish to compare only the values, but that can have a negative impact on performance [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html].&lt;br /&gt;
&lt;br /&gt;
=== Disadvantages ===&lt;br /&gt;
* Lack of inheritance capability: The primitive data types in languages such as Java cannot be inherited to create further subtypes.&lt;br /&gt;
* Unexpected results due to method overriding: There are certain examples such as [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html], which show that overriding inbuilt methods such as == and eql? can lead to unexpected results.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Object oriented languages have varying levels of support for primitive data types and objects. Whether they are beneficial or not depends on the application to a great deal. If handled correctly, they can make object oriented programs more efficient. However, the user needs to be aware of the underlying representation of these types to handle any unexpected results.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# http://en.wikipedia.org/wiki/Primitive_data_type&lt;br /&gt;
# http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php&lt;br /&gt;
# http://www.jk-technology.com/c/inttypes.html&lt;br /&gt;
# http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html&lt;br /&gt;
# http://newty.de/fpt/intro.html&lt;br /&gt;
# http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html&lt;br /&gt;
# http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx&lt;br /&gt;
# http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html&lt;br /&gt;
# http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html&lt;br /&gt;
# http://www.glenmccl.com/tip_016.htm&lt;br /&gt;
# http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54287</id>
		<title>CSC/ECE 517 Fall 2011/ch3 3h rr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch3_3h_rr&amp;diff=54287"/>
		<updated>2011-10-29T21:43:16Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''3h. Primitive objects.  At the beginning of Lecture 11, we discovered that Fixnums and Bignums are handled differently behind the scenes in Ruby.  Other languages, like Java, have made similar distinctions.  By contrast, languages such as C# and Eiffel try to hide these implementation differences from users.  Answer two questions: (1) How have different o-o languages implemented primitive objects?  E.g., how are they represented in memory, how are they tested for, do comparisons do anything different than for class objects, etc.  (2) What are the advantages and disadvantages of treating primitives differently from class objects in source code?''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Programming languages, whether statically or dynamically typed, have support for certain in-built data types. These data types, known as primitive types, are the basic representation of information in programs and have certain fixed attributes for a specific language[http://en.wikipedia.org/wiki/Primitive_data_type]. Statically typed languages such as C++, Java, Perl etc. support primitive data types, whereas with dynamically typed languages such as Ruby, Smalltalk, Lisp etc. they are actually in the form of primitive objects.  These primitive types are used to store the basic types of information that a computer can store and manipulate, and can also be used as building blocks for creating more complex data types. &lt;br /&gt;
This article explains the way different primitive types are implemented in certain object oriented languages. An analysis of the benefits and drawbacks of such types and the methods used to operate on them is also presented. &lt;br /&gt;
&lt;br /&gt;
== Primitive Types ==&lt;br /&gt;
The primitive types commonly included in most programming languages are:&lt;br /&gt;
* Boolean&lt;br /&gt;
* Character&lt;br /&gt;
* Integer&lt;br /&gt;
* Floating-point number&lt;br /&gt;
* Fixed-point number&lt;br /&gt;
* Reference&lt;br /&gt;
&lt;br /&gt;
=== Boolean ===&lt;br /&gt;
A Boolean is a primitive data type used to store one of two logical types: true or false.  Boolean data types are most commonly used as input paramters to a conditional statement (such as an ‘if’ statement), or as the output of a comparison between two comparable data types.  Booleans can be implemented in languages as either a discrete logical type, or implicitly as a numerical type.  In many languages, booleans can be implicitly converted to and from integer types.  &lt;br /&gt;
&lt;br /&gt;
=== Character ===&lt;br /&gt;
A character is a data type that represents an element of a written language, such as a letter, number, or symbol.  A character can also represent a control character, such as a carriage return or newline, which does not have a written meaning but controls how other characters are stored or displayed.   Characters are commonly stored as integers, and encoded using a character map.  &lt;br /&gt;
&lt;br /&gt;
=== Integer ===&lt;br /&gt;
An integer is a data type that represents one element of a finite subset of mathematical integers.  Integer, or Integral, data types can be either unsigned (able to store only positive whole numbers) or signed (able to store either positive or negative whole numbers).  The range of values that can be represented by an integer depends on the number of bits used to store the integer, whether or not it is a signed integer, and the encoding scheme (if it is signed).  Typically, an integer has a minimum and maximum value, and can store any integer in the range between those values.  The minimum value for unsigned integers is typically 0, and the maximum value is typically determined by the amount of memory used to store the integer.  For example, a un unsigned 8-bit number can store 2^8 (or 256) possible integral values; and would typically store any value from 0 to 255.  More generally, an n-bit unsigned integer can store from 0 to (2^n)-1.  For signed integers, modern computers use the Two’s Complement encoding scheme.  This allows for a range of −2^(n−1) through 2^(n−1)−1.  For example, an 8-bit signed integer could store any whole number in the range from -128 through +127.&lt;br /&gt;
&lt;br /&gt;
=== Floating-Point Number ===&lt;br /&gt;
A floating point number is a data type used to represent real numbers in a large range with varying degrees of precision.  In this representation, numbers are represented with a variable number of significant digits, and a variable number of exponential digits.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed-Point number ===&lt;br /&gt;
A fixed-point number is a data type used to represent real numbers.  Fixed-point numbers are called fixed-point because they have a set number of digits before and after a decimal mark.  In this regard, fixed-point numbers are represented as an integer, but are scaled by a predetermined factor.  &lt;br /&gt;
&lt;br /&gt;
Fixed-point numbers are commonly used in microprocessors that do not have a floating-point unit, or in systems in which computational efficiency is critical.  Fixed-point numbers can be treated as integers by an arithmetic logic unit (ALU) and scaled after a result is obtained, which can significantly lower the amount of time needed for a processor to obtain the result for some algorithms. &lt;br /&gt;
&lt;br /&gt;
Implementing algorithms using fixed-point arithmetic requires great care, because of the potential for information loss.  Fixed-point arithmetic operations -- multiplication in particular, has the potential to cause overflow.  Algorithms must be written with care to ensure that each term of an equation has a similar range and that the result will not cause an overflow.&lt;br /&gt;
&lt;br /&gt;
=== Reference ===&lt;br /&gt;
&lt;br /&gt;
A Reference is a data type that enables a program to access another item in memory.  A reference differs from other primitive data types in that it does not store data itself; instead it stores a value referring to another data object.  References are commonly used to refer to objects of large non-primitive data types.  References commonly store the physical memory address of the data that they are referring to.  Accessing the data referred to by a Reference is called dereferencing.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C++ ==&lt;br /&gt;
&lt;br /&gt;
C++ is a statically-typed object oriented language.  C++ is based on the C programming language, which is procedural, and adds support for object-oriented code.  &lt;br /&gt;
&lt;br /&gt;
These data types are defined in C++: [http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php] &lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; style=&amp;quot;border: 1px solid darkgray;&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;|Name &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| void &lt;br /&gt;
| N/A &lt;br /&gt;
| the void data type is used to explicitly identify that a data has no type &lt;br /&gt;
| N/A&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits&lt;br /&gt;
| simple numerical type&lt;br /&gt;
| See [[http://www.jk-technology.com/c/inttypes.html]]&lt;br /&gt;
|-&lt;br /&gt;
| float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 8 bits &lt;br /&gt;
| a char is a single 8-bit character encoded using ASCII &lt;br /&gt;
| Ascii character 0x00 through ascii character 0xFF&lt;br /&gt;
|}&lt;br /&gt;
C++ supports Pointers for all of the types listed in the table above, as well as more complex data types (such as structs).  A Pointer in C++ is a data type that stores the physical address of some other data.  Pointers are created in C++ by using the * operator.  For example, a *Double[] is a pointer to an array of double-precision floating point numbers.  C++ Also supports function pointers -- pointers that reference the beginning address of a function in memory.  They are commonly used to implement callback functions [http://newty.de/fpt/intro.html#what]&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in Java == &lt;br /&gt;
&lt;br /&gt;
Java is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  These data types are defined in Java: [http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html]&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; style=&amp;quot;border: 1px solid darkgray;&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;|Name&lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte&lt;br /&gt;
|8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
|-128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
|16 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647 &lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| See [[http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]]&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Java also defines a String class, which is used to create objects of many chars.  The String class provides functionality commonly implemented using arrays of chars in other languages, such as C. &lt;br /&gt;
&lt;br /&gt;
Java also defines the 'unsigned' keyword, which can be used to as a modifier to any of the integral types listed in the table above.  If the 'unsigned' keyword is used, the integral type will be unsigned instead of signed, and its range will change correspondingly. &lt;br /&gt;
&lt;br /&gt;
Java is capable of using any two objects of the same primitive data type for comparison.  Java defines a class for each data type, which have the same name but a capitalized first letter (e.g. Float instead of float).  These classes, called wrapper classes provide a series of methods that can manipulate their associated primitive data type, as well as convert to and from other data types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Data Types in C# == &lt;br /&gt;
&lt;br /&gt;
C# is a statically-typed object oriented programming language.  Primitive types are defined in the language, and conversion between them must be explicitly performed.  Primitive data types are created using a keyword, which is also the name of the data type.  C# has all of the data types that are available in Java, as well as some additional ones.  &lt;br /&gt;
&lt;br /&gt;
Similar to Java, C# defines a String class which is used to create objects of many chars.  These data types are defined in C#: [http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx]&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; style=&amp;quot;border: 1px solid darkgray;&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! .NET Class &lt;br /&gt;
! Size &lt;br /&gt;
! Description &lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
|byte &lt;br /&gt;
| Byte &lt;br /&gt;
| 8 bits &lt;br /&gt;
|signed two's complement integer &lt;br /&gt;
| -128 to 127 &lt;br /&gt;
|-&lt;br /&gt;
| sbyte &lt;br /&gt;
| SByte &lt;br /&gt;
| 8 bits&lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -0 to 255&lt;br /&gt;
|-&lt;br /&gt;
| short &lt;br /&gt;
| Int16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -32,768 to 32,767&lt;br /&gt;
|-&lt;br /&gt;
| ushort &lt;br /&gt;
| UInt16 &lt;br /&gt;
| 16 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 65,535&lt;br /&gt;
|-&lt;br /&gt;
| int &lt;br /&gt;
| Int32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -2,147,483,648 to 2,147,483,647&lt;br /&gt;
|-&lt;br /&gt;
| uint &lt;br /&gt;
| UInt32 &lt;br /&gt;
| 32 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 4,294,967,295&lt;br /&gt;
|-&lt;br /&gt;
| long &lt;br /&gt;
| Int64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| signed two's complement integer &lt;br /&gt;
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807&lt;br /&gt;
|-&lt;br /&gt;
| ulong &lt;br /&gt;
| UInt64 &lt;br /&gt;
| 64 bits &lt;br /&gt;
| unsigned integer &lt;br /&gt;
| 0 to 18,446,744,073,709,551,615&lt;br /&gt;
|- &lt;br /&gt;
|float &lt;br /&gt;
| Float &lt;br /&gt;
| 32 bits &lt;br /&gt;
| single-precision IEEE 754 floating point &lt;br /&gt;
| -3.402823e38 to 3.02823e38&lt;br /&gt;
|-&lt;br /&gt;
| double &lt;br /&gt;
| Double &lt;br /&gt;
| 64 bits &lt;br /&gt;
| double-precision IEEE 754 floating point&lt;br /&gt;
| -1.79769313486232e308 to 1.79769313486232e308&lt;br /&gt;
|- &lt;br /&gt;
| boolean &lt;br /&gt;
| Boolean &lt;br /&gt;
| 1 bit &lt;br /&gt;
| boolean &lt;br /&gt;
| false, true&lt;br /&gt;
|-&lt;br /&gt;
| char &lt;br /&gt;
| Char &lt;br /&gt;
| 16 bits &lt;br /&gt;
| a char is a single 16-bit character encoded using Unicode &lt;br /&gt;
| Unicode character \u0000 through unicode character \uffff&lt;br /&gt;
|-&lt;br /&gt;
| object &lt;br /&gt;
| Object &lt;br /&gt;
| N/A &lt;br /&gt;
| Object is the base type of all other types&lt;br /&gt;
|-&lt;br /&gt;
| string &lt;br /&gt;
| String &lt;br /&gt;
| N/A &lt;br /&gt;
| String is the base type for a sequence of chars&lt;br /&gt;
|-&lt;br /&gt;
| decimal &lt;br /&gt;
| Decimal &lt;br /&gt;
| 128 &lt;br /&gt;
| Decimal is an integral type that can represent a decimal number with 29 significant digits ±1.0 × 10e−28 to ±7.9 × 10e28&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Like Java, each primitive data type in C# also has a class associated with it that.  These classes serve a similar purpose to their associated ones in Java.  They are used for comparison of objects, as well as conversion between other similar types.&lt;br /&gt;
&lt;br /&gt;
== Primitive Objects in Ruby ==&lt;br /&gt;
Ruby is a pure object oriented language as compared to languages such as Java or C#, which use a more hybrid approach. In Ruby, all data types are represented as Objects. There are some [http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html inbuilt classes] that are provided to users in Ruby. However, only some of them are a basic building block for forming other types. This subset shown below gives us a list of primitive objects that can be used for data representation and manipulation:&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; style=&amp;quot;border: 1px solid darkgray;&amp;quot;&lt;br /&gt;
! align=&amp;quot;left&amp;quot;| Name &lt;br /&gt;
! Description&lt;br /&gt;
! Range&lt;br /&gt;
|-&lt;br /&gt;
| TrueClass&lt;br /&gt;
| Singleton instance &amp;quot;true&amp;quot; allowed&lt;br /&gt;
| true&lt;br /&gt;
|-&lt;br /&gt;
| FalseClass&lt;br /&gt;
| Singleton instance &amp;quot;false&amp;quot; allowed&lt;br /&gt;
| false&lt;br /&gt;
|-&lt;br /&gt;
| Integer [http://www.ruby-doc.org/core/Integer.html]&lt;br /&gt;
| Abstract class that forms the basis for Fixnum and Bignum&lt;br /&gt;
| See Fixnum and Bignum&lt;br /&gt;
|-&lt;br /&gt;
| Fixnum [http://www.ruby-doc.org/core-1.8.7/Fixnum.html]&lt;br /&gt;
| Integer representations that fit in native machine word&lt;br /&gt;
| Machine architecture dependent. 2^30-1 to -2^30 on 32-bit machines.&lt;br /&gt;
|-&lt;br /&gt;
| Bignum [http://www.ruby-doc.org/core/Bignum.html]&lt;br /&gt;
| Integer representations that do not fit in Fixnum width&lt;br /&gt;
| Machine architecture dependent. Values above Fixnum range.&lt;br /&gt;
|-&lt;br /&gt;
| Float [http://www.ruby-doc.org/core/Float.html]&lt;br /&gt;
| Real numbers using double precision representation&lt;br /&gt;
| Value after decimal point can be formatted&lt;br /&gt;
|-&lt;br /&gt;
| String [http://corelib.rubyonrails.org/classes/String.html]&lt;br /&gt;
| Contains sequence of characters&lt;br /&gt;
| No physical limit, but can be decided by machine architecture&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
One interesting observation from the above table is that Ruby does not have a Boolean class; instead it has a separate TrueClass and FalseClass [http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby].&lt;br /&gt;
&lt;br /&gt;
  puts true.class &lt;br /&gt;
  =&amp;gt; TrueClass&lt;br /&gt;
  puts false.class&lt;br /&gt;
  =&amp;gt; FalseClass&lt;br /&gt;
&lt;br /&gt;
Although types such as Array, Hash are also in-built types, they can be further composed of elements that are internally represented in one of the primitive types. Hence, they will not be treated by us as primitive objects, in the traditional definition of the term.&lt;br /&gt;
Each of the primitive objects listed above also provide certain convenience methods that are applicable for the underlying type.&lt;br /&gt;
For example, the Fixnum, Bignum and Float types provide support for arithmetic operations such as addition (+), subtraction(--), multiplication(*) and so on.&lt;br /&gt;
As with all other classes in Ruby, users can add functionality to existing primitive objects by reopening classes. The amount of memory required to implement the primitive objects in Ruby is machine dependent in some cases.&lt;br /&gt;
&lt;br /&gt;
== Merit Analysis of Primitive Types ==&lt;br /&gt;
This section deals with a brief analysis of the relative merits and demerits of primitive data types. While we focus on Java or Ruby for this purpose, most of these points are applicable across all object oriented languages.&lt;br /&gt;
&lt;br /&gt;
=== Advantages ===&lt;br /&gt;
Primitive types in object oriented languages have certain advantages over their class object counterparts. &lt;br /&gt;
* Simplicity: Primitive types/objects provide users a simple mechanism of manipulating data without relying on additional objects to achieve the same functionality. Operations on primitive types are more intuitive.&lt;br /&gt;
* Efficiency: This statement is applicable if the underlying primitive object definition is not modified (a feature that languages such as Ruby provide to users). As the representation in memory is designed to be make most efficient use of the underlying datatype, use of primitives can provide a benefit to the user, over the use of class objects to store the same data. &lt;br /&gt;
  Eg. Java provides wrappers [http://www.glenmccl.com/tip_016.htm] for certain primitive types. There is a certain performance and space cost associated with these. &lt;br /&gt;
  So, to maximize efficiency, direct use of the primitive types would provide the most benefit.&lt;br /&gt;
* Ability to use inbuilt methods: Depending on the primitive type, languages such as Ruby provide methods that can be used specifically to probe or manipulate objects. &lt;br /&gt;
  Eg. [http://corelib.rubyonrails.org/classes/String.html String] primitive object provides convenience methods such as upcase to convert the entire string to upper case, or capitalize, which converts only the first character to upper case.&lt;br /&gt;
* Ease of testing for comparison: With primitive types, the equality testing operators such as == can be used. These essentially compare the values stored in the primitive types. Regular objects also offer the eql? method for testing equality. However, the following are not equivalent:&lt;br /&gt;
  a=10&lt;br /&gt;
  =&amp;gt; 10&lt;br /&gt;
  a==10&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a==10.0&lt;br /&gt;
  =&amp;gt; true&lt;br /&gt;
  a.eql?(10.0)&lt;br /&gt;
  =&amp;gt; false&lt;br /&gt;
The reason the .eql? fails is that this operator tests for value and type being the same. 10 is type Fixnum and 10.0 is type Float. &lt;br /&gt;
The eql? can be overridden by == for primitive objects if you wish to compare only the values, but that can have a negative impact on performance [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html].&lt;br /&gt;
&lt;br /&gt;
=== Disadvantages ===&lt;br /&gt;
* Lack of inheritance capability: The primitive data types in languages such as Java cannot be inherited to create further subtypes.&lt;br /&gt;
* Unexpected results due to method overriding: There are certain examples such as [http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html], which show that overriding inbuilt methods such as == and eql? can lead to unexpected results.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Object oriented languages have varying levels of support for primitive data types and objects. Whether they are beneficial or not depends on the application to a great deal. If handled correctly, they can make object oriented programs more efficient. However, the user needs to be aware of the underlying representation of these types to handle any unexpected results.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# http://en.wikipedia.org/wiki/Primitive_data_type&lt;br /&gt;
# http://sparkcharts.sparknotes.com/cs/cplusplus/section2.php&lt;br /&gt;
# http://www.jk-technology.com/c/inttypes.html&lt;br /&gt;
# http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html&lt;br /&gt;
# http://newty.de/fpt/intro.html&lt;br /&gt;
# http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html&lt;br /&gt;
# http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx&lt;br /&gt;
# http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html&lt;br /&gt;
# http://blog.vishnuiyengar.com/2009/09/primitive-obsession-in-ruby-aka-not.html&lt;br /&gt;
# http://www.glenmccl.com/tip_016.htm&lt;br /&gt;
# http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011&amp;diff=51737</id>
		<title>CSC/ECE 517 Fall 2011</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011&amp;diff=51737"/>
		<updated>2011-10-06T14:19:14Z</updated>

		<summary type="html">&lt;p&gt;Rbjeffer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Link title]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1a ms]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1a cs]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1a ri]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1a lj]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1b sa]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1b ds]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1b tj]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1c cm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1c sj]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1c ka]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1d sr]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e vs]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e aa]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1a sc]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e dm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e an]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e sa]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e lm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1g vn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1f rs]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1f sv]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1g jn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1h ps]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e sm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1i zf]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1g rn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1i cl]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1d ss]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1i lj]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1h hs]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1d gs]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 2b ns]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 2b jp]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 2a av]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch2 2f jm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch2 2e ad]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch2 2e kt]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch2 2e gp]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 2b qu]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch2 2c bs]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 2c rs]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 2a ca]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 2b rv]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch2 2c ds]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch2 2b sa]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch2 2f vh]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch2 2e ps]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch3 3h rr]]&lt;br /&gt;
&lt;br /&gt;
*[[trial]]&lt;/div&gt;</summary>
		<author><name>Rbjeffer</name></author>
	</entry>
</feed>