<?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=Yliu63</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=Yliu63"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Yliu63"/>
	<updated>2026-10-05T14:06:33Z</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_2012/ch2a_2w14_bb&amp;diff=69220</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69220"/>
		<updated>2012-10-28T03:30:27Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* A mixed example using Singleton Factory and Command */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses classes and their methods in an object-oriented language. Developers often start thinking about design after learning a programming language and writing code for a while. You might notice that someone else’s code seems simpler and works better than yours does, and you might wonder how that developer achieves such simplicity. Design patterns are a level up from code and typically show how to achieve a goal using a few classes. A pattern represents an idea, not a particular implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Intent !! Patterns&lt;br /&gt;
|-&lt;br /&gt;
| Interfaces || ADAPTER, FACADE, COMPOSITE, BRIDGE&lt;br /&gt;
|-&lt;br /&gt;
| Responsibility || SINGLETON, OBSERVER, MEDIATOR, PROXY, CHAIN OF RESPONSIBILITY, FLYWEIGHT&lt;br /&gt;
|-&lt;br /&gt;
| Construction || BUILDER, FACTORY METHOD, ABSTRACT FACTORY, PROTOTYPE, MEMENTO&lt;br /&gt;
|-&lt;br /&gt;
| Operations|| TEMPLATE METHOD, STATE, STRATEGY, COMMAND, INTERPRETER&lt;br /&gt;
|-&lt;br /&gt;
| Extensions || DECORATOR, ITERATOR, VISITOR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
Design patterns provide a way of encapsulating the experience of software developers in a form that can be communicated to other developers. They provide a higher level of abstraction than single classes and objects thus providing bigger building blocks in the construction of software designs. &lt;br /&gt;
&lt;br /&gt;
The main benefits of design patterns are:&lt;br /&gt;
&lt;br /&gt;
*They encapsulate and codify design experience.&lt;br /&gt;
*Provide a common vocabulary for software designers to use when communicating with their peers.&lt;br /&gt;
*Enhance maintainability of software systems whose designs are documented with patterns.&lt;br /&gt;
*Provide robustness to the design by copying or imitating proven design techniques.&lt;br /&gt;
*Reuse at the design level.&lt;br /&gt;
&lt;br /&gt;
At first glance some of these benefits may not seem very powerful, but upon further inspection maybe we can gain new insight into the true nature of their value. Let us just consider the fact that we have given a design pattern a common name. We can now communicate an entire design principle or concept with other software developers by just using the simple name of the pattern. In one fell swoop we have drastically reduced the effort and time needed for a developer to discuss a concept with another developer. Taken one step further we can discuss the patterns and their interactions in the system and illustrate the system architecture in few sentences. Grouping design concepts with common names facilitates communication among developers and raises the conversation to a higher level of abstraction.&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
There are four primary symptoms that tell us that our designs are rotting. They are not orthogonal, but are related to each other in ways that will become obvious. &lt;br /&gt;
&lt;br /&gt;
The four symptoms are:&lt;br /&gt;
*Rigidity -- the tendency for software to be difficult to change, even in simple ways.&lt;br /&gt;
*Fragility -- the tendency of the software to break in many places every time it is changed. &lt;br /&gt;
*Immobility -- the inability to reuse software from other projects or from parts of the same project.&lt;br /&gt;
*Viscosity -- viscosity comes in two forms: viscosity of the design, and viscosity of the environment.&lt;br /&gt;
&lt;br /&gt;
In following passage of this wiki page, we will discuss over 'Fragility' with some examples.&lt;br /&gt;
&lt;br /&gt;
== Definition of Pattern Fragility ==&lt;br /&gt;
Fragility is the tendency of the &lt;br /&gt;
software to break in many places every time it is changed. Often the breakage occurs &lt;br /&gt;
in areas that have no conceptual relationship with the area that was changed. Such &lt;br /&gt;
errors fill the hearts of managers with foreboding. Every time they authorize a fix, &lt;br /&gt;
they fear that the software will break in some unexpected way.&lt;br /&gt;
As the fragility becomes worse, the probability of breakage increases with time, &lt;br /&gt;
asymptotically approaching 1. Such software is impossible to maintain. Every fix &lt;br /&gt;
makes it worse, introducing more problems than are solved.&lt;br /&gt;
Such software causes managers and customers to suspect that the developers have lost &lt;br /&gt;
control of their software. Distrust reigns, and credibility is lost.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton -- the most overused pattern ===&lt;br /&gt;
&lt;br /&gt;
Sometimes it's important to have only one instance for a class. For example, in a system there should be only one window manager (or only a file system). Usually singletons are used for centralized management of internal or external resources and they provide a global point of access to themselves. The primary purpose of the singleton is to guarantee that at anytime there is only one instance for a given class and provide a global reference to it.&lt;br /&gt;
&lt;br /&gt;
The singleton pattern is one of the simplest design patterns: it involves only one class which is responsible to instantiate itself, to make sure it creates not more than one instance; in the same time it provides a global point of access to that instance. In this case the same instance can be used from everywhere, being impossible to invoke directly the constructor each time.&lt;br /&gt;
&lt;br /&gt;
Well, the question is, is it safe to use a singleton class when it might be very tempting to do so? Obviously, the answer is negative. &lt;br /&gt;
&lt;br /&gt;
==== Problem 1 of abusing Singleton ====&lt;br /&gt;
There is a general misconception about how Singletons should be used. Some people see the Singleton as a justification for global state, along the lines of &amp;quot;If there's a pattern for it, it must be good&amp;quot;. Possibly, because it is true, that for having global state, it is better using Singletons, than just plainly global variables or class objects. Well no, it isn’t. Global state is considered harmful. For a number of reasons, that even Singleton-misuse won't make go away, simply because: '''Singletons are NOT intended to provide global state!'''&lt;br /&gt;
&lt;br /&gt;
The Singleton is a creational pattern. It is used to enforce, that a class be instantiated only once. Create a singleton, and you have just made it possible for widely separated bits of your program to use that singleton as a secret channel to communicate with each other and, in the process, tightly couple themselves to each other. The horrible consequences of this coupling are why software engineering got out of the global variable business in the first place.&lt;br /&gt;
&lt;br /&gt;
There is only one solution to this problem: Don’t do that. Properly applied, singletons are not global variables. Rather, they are meant to model things that occur&lt;br /&gt;
exactly once. Yes, because it occurs only once, you can use a singleton as a unique communications conduit between bits of your program. But don’t do that. Singletons are like every other pattern and programming technique—which means you can really screw things up if you abuse them. I can only repeat: Don’t do that.&lt;br /&gt;
&lt;br /&gt;
=== Factory ===&lt;br /&gt;
Create an interface for building an object, but let subclasses decide which class to instantiate. It allows a class to defer instantiation of subclasses.&lt;br /&gt;
Factory pattern is one of the patterns that have being heavily abused. With as long as if --- else, go to the factory model, as long as the object involved in the creation of selective, go to the factory model. Factory pattern seems to have become the panacea to solve all.&lt;br /&gt;
But let us look at some of the above contrast with the factory pattern, you simple code it? Wrong! The contrary, no increase in the scalability of the code at the same time, it increased the number of types of calls, an increase of the number of categories. This is not what we want to see!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
One example is there is only one object to be instantiate. There was no concept of abstraction or extended classes,just plain old ClassX &amp;amp; ClassXFactory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class A {&lt;br /&gt;
       public String str;&lt;br /&gt;
       public String getStr() {&lt;br /&gt;
              return str;&lt;br /&gt;
       }&lt;br /&gt;
}// End of class&lt;br /&gt;
&lt;br /&gt;
public class ChildA extends A {&lt;br /&gt;
       public ChildA(String str) {&lt;br /&gt;
       System.out.println(&amp;quot;Hello &amp;quot;+str);&lt;br /&gt;
       }&lt;br /&gt;
}// End of class&lt;br /&gt;
&lt;br /&gt;
public class AFactory {&lt;br /&gt;
       public static void main(String args[]) {&lt;br /&gt;
              AFactory factory = new AFactory();&lt;br /&gt;
              factory.getA(args[0]);&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
       public A getA(String str) {&lt;br /&gt;
              if(str!=NULL)&lt;br /&gt;
                     return new A(str);&lt;br /&gt;
              else&lt;br /&gt;
                     return null;&lt;br /&gt;
       }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When to use a Factory Pattern?&lt;br /&gt;
The Factory patterns can be used in following cases:&lt;br /&gt;
&lt;br /&gt;
1. When a class does not know which class of objects it must create.&lt;br /&gt;
&lt;br /&gt;
2. A class specifies its sub-classes to specify which objects to create.&lt;br /&gt;
&lt;br /&gt;
3. In programmer’s language (very raw form), you can use factory pattern where you have to create an object of any one of sub-classes depending on the data provided.&lt;br /&gt;
&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
Visitor pattern represent an operation to be performed on the elements of an object structure. In GoF's word, &amp;quot;It let you define a new operation changing the classes of the elements on which it operates.&amp;quot;&lt;br /&gt;
However, It's also the one that GoF most worried about. It's not a &amp;quot;necessary evil&amp;quot; - but is often over used and the need for it often reveals a more fundamental flaw in your design.&lt;br /&gt;
&lt;br /&gt;
Following is a classic example being that you have the intersection between two shapes, but there's an even simpler case that's often overlooked: comparing the equality of two heterogeneous objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface IShape&lt;br /&gt;
{&lt;br /&gt;
    double intersectWith(Triangle t);&lt;br /&gt;
    double intersectWith(Rectangle r);&lt;br /&gt;
    double intersectWith(Circle c);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The problem with this is that you have coupled together all of your implementations of &amp;quot;IShape&amp;quot;. You've implied that whenever you wish to add a new shape to the hierarchy you will need to change all the other &amp;quot;Shape&amp;quot; implementations too.&lt;br /&gt;
&lt;br /&gt;
Sometimes, this is the correct minimal design - but think it through. Does your design really mandate that you need to dispatch on two types? Are you willing to write each of the combinatorial explosion of multi-methods?&lt;br /&gt;
&lt;br /&gt;
Often, by introducing another concept you can reduce the number of combinations that you're actually going to have to write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface IShape&lt;br /&gt;
{&lt;br /&gt;
    Area getArea();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Area&lt;br /&gt;
{&lt;br /&gt;
    public double intersectWith(Area otherArea);&lt;br /&gt;
    ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Command ===&lt;br /&gt;
The Command design pattern encapsulates commands (method calls) in objects allowing us to issue requests without knowing the requested operation or the requesting object. Command design pattern provides the options to queue commands, undo/redo actions and other manipulations.&lt;br /&gt;
&lt;br /&gt;
There are two extremes that a programmer must avoid when using this pattern: &lt;br /&gt;
&lt;br /&gt;
1. The command is just a link between the receiver and the actions that carry out the request&lt;br /&gt;
2. The command implements everything itself, without sending anything to the receiver.&lt;br /&gt;
&lt;br /&gt;
We must always keep in mind the fact that the receiver is the one who knows how to perform the operations needed, the purpose of the command being to help the client to delegate its request quickly and to make sure the command ends up where it should.&lt;br /&gt;
&lt;br /&gt;
One example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class FileDeleteCommand&lt;br /&gt;
   def initialize(path)&lt;br /&gt;
     @path = path&lt;br /&gt;
   end&lt;br /&gt;
   def execute&lt;br /&gt;
     File.delete(@path)&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 fdc = FileDeleteCommand.new('foo.dat')&lt;br /&gt;
 fdc.execute&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
there is nothing simpler than just getting on with it:&lt;br /&gt;
File.delete('foo.dat')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== A mixed example using Singleton Factory and Command ===&lt;br /&gt;
&lt;br /&gt;
The final goal of the program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
System.out.println(&amp;quot;hello world&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using Singleton, Factory and Command&lt;br /&gt;
&lt;br /&gt;
First we define two interfaces Subject and Observer to add Observer.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public interface Subject {&lt;br /&gt;
    public void attach(Observer observer);&lt;br /&gt;
    public void detach(Observer observer);&lt;br /&gt;
    public void notifyObservers();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public interface Observer {&lt;br /&gt;
    public void update(Subject subject);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then we define two classes HelloWorldSubject and HelloWorldObserver that implements them.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class HelloWorldSubject implements Subject {&lt;br /&gt;
    &lt;br /&gt;
    private ArrayList&amp;lt;Observer&amp;gt; observers;&lt;br /&gt;
    private String str;&lt;br /&gt;
    &lt;br /&gt;
    public HelloWorldSubject() {&lt;br /&gt;
        super();&lt;br /&gt;
&lt;br /&gt;
        observers = new ArrayList&amp;lt;Observer&amp;gt;();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void attach(Observer observer) {&lt;br /&gt;
        observers.add(observer);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void detach(Observer observer) {&lt;br /&gt;
        observers.remove(observer);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void notifyObservers() {&lt;br /&gt;
        Iterator&amp;lt;Observer&amp;gt; iter = observers.iterator();&lt;br /&gt;
        &lt;br /&gt;
        while (iter.hasNext()) {&lt;br /&gt;
            Observer observer = iter.next();&lt;br /&gt;
            observer.update(this);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public String getStr() {&lt;br /&gt;
        return str;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void setStr(String str) {&lt;br /&gt;
        this.str = str;&lt;br /&gt;
        notifyObservers();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class HelloWorldObserver implements Observer {&lt;br /&gt;
&lt;br /&gt;
    public void update(Subject subject) {&lt;br /&gt;
        HelloWorldSubject sub = (HelloWorldSubject)subject;&lt;br /&gt;
        System.out.println(sub.getStr());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then we add a Command.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public interface Command {&lt;br /&gt;
    void execute();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class HelloWorldCommand implements Command {&lt;br /&gt;
&lt;br /&gt;
    private HelloWorldSubject subject;&lt;br /&gt;
    &lt;br /&gt;
    public HelloWorldCommand(Subject subject) {&lt;br /&gt;
        super();&lt;br /&gt;
    &lt;br /&gt;
        this.subject = (HelloWorldSubject)subject;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public void execute() {&lt;br /&gt;
        subject.setStr(&amp;quot;hello world&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then We add a Factory&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public interface AbstractFactory {&lt;br /&gt;
    public Subject createSubject();&lt;br /&gt;
    public Observer createObserver();&lt;br /&gt;
    public Command createCommand(Subject subject);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class HelloWorldFactory implements AbstractFactory {&lt;br /&gt;
&lt;br /&gt;
    public Subject createSubject() {&lt;br /&gt;
        return new HelloWorldSubject();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public Observer createObserver() {&lt;br /&gt;
        return new HelloWorldObserver(); &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public Command createCommand(Subject subject) {&lt;br /&gt;
        return new HelloWorldCommand(subject);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And a Singleton&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class FactoryMakerSingleton {&lt;br /&gt;
    &lt;br /&gt;
    private static FactoryMakerSingleton instance = null;&lt;br /&gt;
    private AbstractFactory factory;&lt;br /&gt;
&lt;br /&gt;
    private FactoryMakerSingleton() {&lt;br /&gt;
        factory = new HelloWorldFactory();&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public static synchronized FactoryMakerSingleton getInstance() {&lt;br /&gt;
        if (instance == null) {&lt;br /&gt;
            instance = new FactoryMakerSingleton();&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return instance;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public AbstractFactory getFactory() {&lt;br /&gt;
        return factory;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And finally the main class&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class AbuseDesignPatterns {&lt;br /&gt;
&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
        AbstractFactory factory = FactoryMakerSingleton.getInstance().getFactory();&lt;br /&gt;
        &lt;br /&gt;
        Subject subject = factory.createSubject();&lt;br /&gt;
        subject.attach(factory.createObserver());&lt;br /&gt;
        &lt;br /&gt;
        Command command = factory.createCommand(subject);&lt;br /&gt;
        &lt;br /&gt;
        command.execute();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
And the output is: Hello World&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69218</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69218"/>
		<updated>2012-10-28T03:29:35Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* A mixed example using Singleton Factory and Command */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses classes and their methods in an object-oriented language. Developers often start thinking about design after learning a programming language and writing code for a while. You might notice that someone else’s code seems simpler and works better than yours does, and you might wonder how that developer achieves such simplicity. Design patterns are a level up from code and typically show how to achieve a goal using a few classes. A pattern represents an idea, not a particular implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Intent !! Patterns&lt;br /&gt;
|-&lt;br /&gt;
| Interfaces || ADAPTER, FACADE, COMPOSITE, BRIDGE&lt;br /&gt;
|-&lt;br /&gt;
| Responsibility || SINGLETON, OBSERVER, MEDIATOR, PROXY, CHAIN OF RESPONSIBILITY, FLYWEIGHT&lt;br /&gt;
|-&lt;br /&gt;
| Construction || BUILDER, FACTORY METHOD, ABSTRACT FACTORY, PROTOTYPE, MEMENTO&lt;br /&gt;
|-&lt;br /&gt;
| Operations|| TEMPLATE METHOD, STATE, STRATEGY, COMMAND, INTERPRETER&lt;br /&gt;
|-&lt;br /&gt;
| Extensions || DECORATOR, ITERATOR, VISITOR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
Design patterns provide a way of encapsulating the experience of software developers in a form that can be communicated to other developers. They provide a higher level of abstraction than single classes and objects thus providing bigger building blocks in the construction of software designs. &lt;br /&gt;
&lt;br /&gt;
The main benefits of design patterns are:&lt;br /&gt;
&lt;br /&gt;
*They encapsulate and codify design experience.&lt;br /&gt;
*Provide a common vocabulary for software designers to use when communicating with their peers.&lt;br /&gt;
*Enhance maintainability of software systems whose designs are documented with patterns.&lt;br /&gt;
*Provide robustness to the design by copying or imitating proven design techniques.&lt;br /&gt;
*Reuse at the design level.&lt;br /&gt;
&lt;br /&gt;
At first glance some of these benefits may not seem very powerful, but upon further inspection maybe we can gain new insight into the true nature of their value. Let us just consider the fact that we have given a design pattern a common name. We can now communicate an entire design principle or concept with other software developers by just using the simple name of the pattern. In one fell swoop we have drastically reduced the effort and time needed for a developer to discuss a concept with another developer. Taken one step further we can discuss the patterns and their interactions in the system and illustrate the system architecture in few sentences. Grouping design concepts with common names facilitates communication among developers and raises the conversation to a higher level of abstraction.&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
There are four primary symptoms that tell us that our designs are rotting. They are not orthogonal, but are related to each other in ways that will become obvious. &lt;br /&gt;
&lt;br /&gt;
The four symptoms are:&lt;br /&gt;
*Rigidity -- the tendency for software to be difficult to change, even in simple ways.&lt;br /&gt;
*Fragility -- the tendency of the software to break in many places every time it is changed. &lt;br /&gt;
*Immobility -- the inability to reuse software from other projects or from parts of the same project.&lt;br /&gt;
*Viscosity -- viscosity comes in two forms: viscosity of the design, and viscosity of the environment.&lt;br /&gt;
&lt;br /&gt;
In following passage of this wiki page, we will discuss over 'Fragility' with some examples.&lt;br /&gt;
&lt;br /&gt;
== Definition of Pattern Fragility ==&lt;br /&gt;
Fragility is the tendency of the &lt;br /&gt;
software to break in many places every time it is changed. Often the breakage occurs &lt;br /&gt;
in areas that have no conceptual relationship with the area that was changed. Such &lt;br /&gt;
errors fill the hearts of managers with foreboding. Every time they authorize a fix, &lt;br /&gt;
they fear that the software will break in some unexpected way.&lt;br /&gt;
As the fragility becomes worse, the probability of breakage increases with time, &lt;br /&gt;
asymptotically approaching 1. Such software is impossible to maintain. Every fix &lt;br /&gt;
makes it worse, introducing more problems than are solved.&lt;br /&gt;
Such software causes managers and customers to suspect that the developers have lost &lt;br /&gt;
control of their software. Distrust reigns, and credibility is lost.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton -- the most overused pattern ===&lt;br /&gt;
&lt;br /&gt;
Sometimes it's important to have only one instance for a class. For example, in a system there should be only one window manager (or only a file system). Usually singletons are used for centralized management of internal or external resources and they provide a global point of access to themselves. The primary purpose of the singleton is to guarantee that at anytime there is only one instance for a given class and provide a global reference to it.&lt;br /&gt;
&lt;br /&gt;
The singleton pattern is one of the simplest design patterns: it involves only one class which is responsible to instantiate itself, to make sure it creates not more than one instance; in the same time it provides a global point of access to that instance. In this case the same instance can be used from everywhere, being impossible to invoke directly the constructor each time.&lt;br /&gt;
&lt;br /&gt;
Well, the question is, is it safe to use a singleton class when it might be very tempting to do so? Obviously, the answer is negative. &lt;br /&gt;
&lt;br /&gt;
==== Problem 1 of abusing Singleton ====&lt;br /&gt;
There is a general misconception about how Singletons should be used. Some people see the Singleton as a justification for global state, along the lines of &amp;quot;If there's a pattern for it, it must be good&amp;quot;. Possibly, because it is true, that for having global state, it is better using Singletons, than just plainly global variables or class objects. Well no, it isn’t. Global state is considered harmful. For a number of reasons, that even Singleton-misuse won't make go away, simply because: '''Singletons are NOT intended to provide global state!'''&lt;br /&gt;
&lt;br /&gt;
The Singleton is a creational pattern. It is used to enforce, that a class be instantiated only once. Create a singleton, and you have just made it possible for widely separated bits of your program to use that singleton as a secret channel to communicate with each other and, in the process, tightly couple themselves to each other. The horrible consequences of this coupling are why software engineering got out of the global variable business in the first place.&lt;br /&gt;
&lt;br /&gt;
There is only one solution to this problem: Don’t do that. Properly applied, singletons are not global variables. Rather, they are meant to model things that occur&lt;br /&gt;
exactly once. Yes, because it occurs only once, you can use a singleton as a unique communications conduit between bits of your program. But don’t do that. Singletons are like every other pattern and programming technique—which means you can really screw things up if you abuse them. I can only repeat: Don’t do that.&lt;br /&gt;
&lt;br /&gt;
=== Factory ===&lt;br /&gt;
Create an interface for building an object, but let subclasses decide which class to instantiate. It allows a class to defer instantiation of subclasses.&lt;br /&gt;
Factory pattern is one of the patterns that have being heavily abused. With as long as if --- else, go to the factory model, as long as the object involved in the creation of selective, go to the factory model. Factory pattern seems to have become the panacea to solve all.&lt;br /&gt;
But let us look at some of the above contrast with the factory pattern, you simple code it? Wrong! The contrary, no increase in the scalability of the code at the same time, it increased the number of types of calls, an increase of the number of categories. This is not what we want to see!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
One example is there is only one object to be instantiate. There was no concept of abstraction or extended classes,just plain old ClassX &amp;amp; ClassXFactory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class A {&lt;br /&gt;
       public String str;&lt;br /&gt;
       public String getStr() {&lt;br /&gt;
              return str;&lt;br /&gt;
       }&lt;br /&gt;
}// End of class&lt;br /&gt;
&lt;br /&gt;
public class ChildA extends A {&lt;br /&gt;
       public ChildA(String str) {&lt;br /&gt;
       System.out.println(&amp;quot;Hello &amp;quot;+str);&lt;br /&gt;
       }&lt;br /&gt;
}// End of class&lt;br /&gt;
&lt;br /&gt;
public class AFactory {&lt;br /&gt;
       public static void main(String args[]) {&lt;br /&gt;
              AFactory factory = new AFactory();&lt;br /&gt;
              factory.getA(args[0]);&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
       public A getA(String str) {&lt;br /&gt;
              if(str!=NULL)&lt;br /&gt;
                     return new A(str);&lt;br /&gt;
              else&lt;br /&gt;
                     return null;&lt;br /&gt;
       }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When to use a Factory Pattern?&lt;br /&gt;
The Factory patterns can be used in following cases:&lt;br /&gt;
&lt;br /&gt;
1. When a class does not know which class of objects it must create.&lt;br /&gt;
&lt;br /&gt;
2. A class specifies its sub-classes to specify which objects to create.&lt;br /&gt;
&lt;br /&gt;
3. In programmer’s language (very raw form), you can use factory pattern where you have to create an object of any one of sub-classes depending on the data provided.&lt;br /&gt;
&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
Visitor pattern represent an operation to be performed on the elements of an object structure. In GoF's word, &amp;quot;It let you define a new operation changing the classes of the elements on which it operates.&amp;quot;&lt;br /&gt;
However, It's also the one that GoF most worried about. It's not a &amp;quot;necessary evil&amp;quot; - but is often over used and the need for it often reveals a more fundamental flaw in your design.&lt;br /&gt;
&lt;br /&gt;
Following is a classic example being that you have the intersection between two shapes, but there's an even simpler case that's often overlooked: comparing the equality of two heterogeneous objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface IShape&lt;br /&gt;
{&lt;br /&gt;
    double intersectWith(Triangle t);&lt;br /&gt;
    double intersectWith(Rectangle r);&lt;br /&gt;
    double intersectWith(Circle c);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The problem with this is that you have coupled together all of your implementations of &amp;quot;IShape&amp;quot;. You've implied that whenever you wish to add a new shape to the hierarchy you will need to change all the other &amp;quot;Shape&amp;quot; implementations too.&lt;br /&gt;
&lt;br /&gt;
Sometimes, this is the correct minimal design - but think it through. Does your design really mandate that you need to dispatch on two types? Are you willing to write each of the combinatorial explosion of multi-methods?&lt;br /&gt;
&lt;br /&gt;
Often, by introducing another concept you can reduce the number of combinations that you're actually going to have to write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface IShape&lt;br /&gt;
{&lt;br /&gt;
    Area getArea();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Area&lt;br /&gt;
{&lt;br /&gt;
    public double intersectWith(Area otherArea);&lt;br /&gt;
    ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Command ===&lt;br /&gt;
The Command design pattern encapsulates commands (method calls) in objects allowing us to issue requests without knowing the requested operation or the requesting object. Command design pattern provides the options to queue commands, undo/redo actions and other manipulations.&lt;br /&gt;
&lt;br /&gt;
There are two extremes that a programmer must avoid when using this pattern: &lt;br /&gt;
&lt;br /&gt;
1. The command is just a link between the receiver and the actions that carry out the request&lt;br /&gt;
2. The command implements everything itself, without sending anything to the receiver.&lt;br /&gt;
&lt;br /&gt;
We must always keep in mind the fact that the receiver is the one who knows how to perform the operations needed, the purpose of the command being to help the client to delegate its request quickly and to make sure the command ends up where it should.&lt;br /&gt;
&lt;br /&gt;
One example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class FileDeleteCommand&lt;br /&gt;
   def initialize(path)&lt;br /&gt;
     @path = path&lt;br /&gt;
   end&lt;br /&gt;
   def execute&lt;br /&gt;
     File.delete(@path)&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 fdc = FileDeleteCommand.new('foo.dat')&lt;br /&gt;
 fdc.execute&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
there is nothing simpler than just getting on with it:&lt;br /&gt;
File.delete('foo.dat')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== A mixed example using Singleton Factory and Command ===&lt;br /&gt;
&lt;br /&gt;
The final goal of the program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
System.out.println(&amp;quot;hello world&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using Singleton, Factory and Command&lt;br /&gt;
&lt;br /&gt;
First we define two interfaces Subject and Observer to add Observer.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public interface Subject {&lt;br /&gt;
    public void attach(Observer observer);&lt;br /&gt;
    public void detach(Observer observer);&lt;br /&gt;
    public void notifyObservers();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public interface Observer {&lt;br /&gt;
    public void update(Subject subject);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then we define two classes HelloWorldSubject and HelloWorldObserver that implements them.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class HelloWorldSubject implements Subject {&lt;br /&gt;
    &lt;br /&gt;
    private ArrayList&amp;lt;Observer&amp;gt; observers;&lt;br /&gt;
    private String str;&lt;br /&gt;
    &lt;br /&gt;
    public HelloWorldSubject() {&lt;br /&gt;
        super();&lt;br /&gt;
&lt;br /&gt;
        observers = new ArrayList&amp;lt;Observer&amp;gt;();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void attach(Observer observer) {&lt;br /&gt;
        observers.add(observer);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void detach(Observer observer) {&lt;br /&gt;
        observers.remove(observer);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void notifyObservers() {&lt;br /&gt;
        Iterator&amp;lt;Observer&amp;gt; iter = observers.iterator();&lt;br /&gt;
        &lt;br /&gt;
        while (iter.hasNext()) {&lt;br /&gt;
            Observer observer = iter.next();&lt;br /&gt;
            observer.update(this);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public String getStr() {&lt;br /&gt;
        return str;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void setStr(String str) {&lt;br /&gt;
        this.str = str;&lt;br /&gt;
        notifyObservers();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class HelloWorldObserver implements Observer {&lt;br /&gt;
&lt;br /&gt;
    public void update(Subject subject) {&lt;br /&gt;
        HelloWorldSubject sub = (HelloWorldSubject)subject;&lt;br /&gt;
        System.out.println(sub.getStr());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then we add a Command.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public interface Command {&lt;br /&gt;
    void execute();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class HelloWorldCommand implements Command {&lt;br /&gt;
&lt;br /&gt;
    private HelloWorldSubject subject;&lt;br /&gt;
    &lt;br /&gt;
    public HelloWorldCommand(Subject subject) {&lt;br /&gt;
        super();&lt;br /&gt;
    &lt;br /&gt;
        this.subject = (HelloWorldSubject)subject;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public void execute() {&lt;br /&gt;
        subject.setStr(&amp;quot;hello world&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then We add a Factory&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public interface AbstractFactory {&lt;br /&gt;
    public Subject createSubject();&lt;br /&gt;
    public Observer createObserver();&lt;br /&gt;
    public Command createCommand(Subject subject);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class HelloWorldFactory implements AbstractFactory {&lt;br /&gt;
&lt;br /&gt;
    public Subject createSubject() {&lt;br /&gt;
        return new HelloWorldSubject();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public Observer createObserver() {&lt;br /&gt;
        return new HelloWorldObserver(); &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public Command createCommand(Subject subject) {&lt;br /&gt;
        return new HelloWorldCommand(subject);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And finally a Singleton&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class FactoryMakerSingleton {&lt;br /&gt;
    &lt;br /&gt;
    private static FactoryMakerSingleton instance = null;&lt;br /&gt;
    private AbstractFactory factory;&lt;br /&gt;
&lt;br /&gt;
    private FactoryMakerSingleton() {&lt;br /&gt;
        factory = new HelloWorldFactory();&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public static synchronized FactoryMakerSingleton getInstance() {&lt;br /&gt;
        if (instance == null) {&lt;br /&gt;
            instance = new FactoryMakerSingleton();&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return instance;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public AbstractFactory getFactory() {&lt;br /&gt;
        return factory;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the main class&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class AbuseDesignPatterns {&lt;br /&gt;
&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
        AbstractFactory factory = FactoryMakerSingleton.getInstance().getFactory();&lt;br /&gt;
        &lt;br /&gt;
        Subject subject = factory.createSubject();&lt;br /&gt;
        subject.attach(factory.createObserver());&lt;br /&gt;
        &lt;br /&gt;
        Command command = factory.createCommand(subject);&lt;br /&gt;
        &lt;br /&gt;
        command.execute();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
And the output is: Hello World&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69214</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69214"/>
		<updated>2012-10-28T03:27:37Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* A mixed example using Singleton Factory and Command */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses classes and their methods in an object-oriented language. Developers often start thinking about design after learning a programming language and writing code for a while. You might notice that someone else’s code seems simpler and works better than yours does, and you might wonder how that developer achieves such simplicity. Design patterns are a level up from code and typically show how to achieve a goal using a few classes. A pattern represents an idea, not a particular implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Intent !! Patterns&lt;br /&gt;
|-&lt;br /&gt;
| Interfaces || ADAPTER, FACADE, COMPOSITE, BRIDGE&lt;br /&gt;
|-&lt;br /&gt;
| Responsibility || SINGLETON, OBSERVER, MEDIATOR, PROXY, CHAIN OF RESPONSIBILITY, FLYWEIGHT&lt;br /&gt;
|-&lt;br /&gt;
| Construction || BUILDER, FACTORY METHOD, ABSTRACT FACTORY, PROTOTYPE, MEMENTO&lt;br /&gt;
|-&lt;br /&gt;
| Operations|| TEMPLATE METHOD, STATE, STRATEGY, COMMAND, INTERPRETER&lt;br /&gt;
|-&lt;br /&gt;
| Extensions || DECORATOR, ITERATOR, VISITOR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
Design patterns provide a way of encapsulating the experience of software developers in a form that can be communicated to other developers. They provide a higher level of abstraction than single classes and objects thus providing bigger building blocks in the construction of software designs. &lt;br /&gt;
&lt;br /&gt;
The main benefits of design patterns are:&lt;br /&gt;
&lt;br /&gt;
*They encapsulate and codify design experience.&lt;br /&gt;
*Provide a common vocabulary for software designers to use when communicating with their peers.&lt;br /&gt;
*Enhance maintainability of software systems whose designs are documented with patterns.&lt;br /&gt;
*Provide robustness to the design by copying or imitating proven design techniques.&lt;br /&gt;
*Reuse at the design level.&lt;br /&gt;
&lt;br /&gt;
At first glance some of these benefits may not seem very powerful, but upon further inspection maybe we can gain new insight into the true nature of their value. Let us just consider the fact that we have given a design pattern a common name. We can now communicate an entire design principle or concept with other software developers by just using the simple name of the pattern. In one fell swoop we have drastically reduced the effort and time needed for a developer to discuss a concept with another developer. Taken one step further we can discuss the patterns and their interactions in the system and illustrate the system architecture in few sentences. Grouping design concepts with common names facilitates communication among developers and raises the conversation to a higher level of abstraction.&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
There are four primary symptoms that tell us that our designs are rotting. They are not orthogonal, but are related to each other in ways that will become obvious. &lt;br /&gt;
&lt;br /&gt;
The four symptoms are:&lt;br /&gt;
*Rigidity -- the tendency for software to be difficult to change, even in simple ways.&lt;br /&gt;
*Fragility -- the tendency of the software to break in many places every time it is changed. &lt;br /&gt;
*Immobility -- the inability to reuse software from other projects or from parts of the same project.&lt;br /&gt;
*Viscosity -- viscosity comes in two forms: viscosity of the design, and viscosity of the environment.&lt;br /&gt;
&lt;br /&gt;
In following passage of this wiki page, we will discuss over 'Fragility' with some examples.&lt;br /&gt;
&lt;br /&gt;
== Definition of Pattern Fragility ==&lt;br /&gt;
Fragility is the tendency of the &lt;br /&gt;
software to break in many places every time it is changed. Often the breakage occurs &lt;br /&gt;
in areas that have no conceptual relationship with the area that was changed. Such &lt;br /&gt;
errors fill the hearts of managers with foreboding. Every time they authorize a fix, &lt;br /&gt;
they fear that the software will break in some unexpected way.&lt;br /&gt;
As the fragility becomes worse, the probability of breakage increases with time, &lt;br /&gt;
asymptotically approaching 1. Such software is impossible to maintain. Every fix &lt;br /&gt;
makes it worse, introducing more problems than are solved.&lt;br /&gt;
Such software causes managers and customers to suspect that the developers have lost &lt;br /&gt;
control of their software. Distrust reigns, and credibility is lost.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton -- the most overused pattern ===&lt;br /&gt;
&lt;br /&gt;
Sometimes it's important to have only one instance for a class. For example, in a system there should be only one window manager (or only a file system). Usually singletons are used for centralized management of internal or external resources and they provide a global point of access to themselves. The primary purpose of the singleton is to guarantee that at anytime there is only one instance for a given class and provide a global reference to it.&lt;br /&gt;
&lt;br /&gt;
The singleton pattern is one of the simplest design patterns: it involves only one class which is responsible to instantiate itself, to make sure it creates not more than one instance; in the same time it provides a global point of access to that instance. In this case the same instance can be used from everywhere, being impossible to invoke directly the constructor each time.&lt;br /&gt;
&lt;br /&gt;
Well, the question is, is it safe to use a singleton class when it might be very tempting to do so? Obviously, the answer is negative. &lt;br /&gt;
&lt;br /&gt;
==== Problem 1 of abusing Singleton ====&lt;br /&gt;
There is a general misconception about how Singletons should be used. Some people see the Singleton as a justification for global state, along the lines of &amp;quot;If there's a pattern for it, it must be good&amp;quot;. Possibly, because it is true, that for having global state, it is better using Singletons, than just plainly global variables or class objects. Well no, it isn’t. Global state is considered harmful. For a number of reasons, that even Singleton-misuse won't make go away, simply because: '''Singletons are NOT intended to provide global state!'''&lt;br /&gt;
&lt;br /&gt;
The Singleton is a creational pattern. It is used to enforce, that a class be instantiated only once. Create a singleton, and you have just made it possible for widely separated bits of your program to use that singleton as a secret channel to communicate with each other and, in the process, tightly couple themselves to each other. The horrible consequences of this coupling are why software engineering got out of the global variable business in the first place.&lt;br /&gt;
&lt;br /&gt;
There is only one solution to this problem: Don’t do that. Properly applied, singletons are not global variables. Rather, they are meant to model things that occur&lt;br /&gt;
exactly once. Yes, because it occurs only once, you can use a singleton as a unique communications conduit between bits of your program. But don’t do that. Singletons are like every other pattern and programming technique—which means you can really screw things up if you abuse them. I can only repeat: Don’t do that.&lt;br /&gt;
&lt;br /&gt;
=== Factory ===&lt;br /&gt;
Create an interface for building an object, but let subclasses decide which class to instantiate. It allows a class to defer instantiation of subclasses.&lt;br /&gt;
Factory pattern is one of the patterns that have being heavily abused. With as long as if --- else, go to the factory model, as long as the object involved in the creation of selective, go to the factory model. Factory pattern seems to have become the panacea to solve all.&lt;br /&gt;
But let us look at some of the above contrast with the factory pattern, you simple code it? Wrong! The contrary, no increase in the scalability of the code at the same time, it increased the number of types of calls, an increase of the number of categories. This is not what we want to see!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
One example is there is only one object to be instantiate. There was no concept of abstraction or extended classes,just plain old ClassX &amp;amp; ClassXFactory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class A {&lt;br /&gt;
       public String str;&lt;br /&gt;
       public String getStr() {&lt;br /&gt;
              return str;&lt;br /&gt;
       }&lt;br /&gt;
}// End of class&lt;br /&gt;
&lt;br /&gt;
public class ChildA extends A {&lt;br /&gt;
       public ChildA(String str) {&lt;br /&gt;
       System.out.println(&amp;quot;Hello &amp;quot;+str);&lt;br /&gt;
       }&lt;br /&gt;
}// End of class&lt;br /&gt;
&lt;br /&gt;
public class AFactory {&lt;br /&gt;
       public static void main(String args[]) {&lt;br /&gt;
              AFactory factory = new AFactory();&lt;br /&gt;
              factory.getA(args[0]);&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
       public A getA(String str) {&lt;br /&gt;
              if(str!=NULL)&lt;br /&gt;
                     return new A(str);&lt;br /&gt;
              else&lt;br /&gt;
                     return null;&lt;br /&gt;
       }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When to use a Factory Pattern?&lt;br /&gt;
The Factory patterns can be used in following cases:&lt;br /&gt;
&lt;br /&gt;
1. When a class does not know which class of objects it must create.&lt;br /&gt;
&lt;br /&gt;
2. A class specifies its sub-classes to specify which objects to create.&lt;br /&gt;
&lt;br /&gt;
3. In programmer’s language (very raw form), you can use factory pattern where you have to create an object of any one of sub-classes depending on the data provided.&lt;br /&gt;
&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
Visitor pattern represent an operation to be performed on the elements of an object structure. In GoF's word, &amp;quot;It let you define a new operation changing the classes of the elements on which it operates.&amp;quot;&lt;br /&gt;
However, It's also the one that GoF most worried about. It's not a &amp;quot;necessary evil&amp;quot; - but is often over used and the need for it often reveals a more fundamental flaw in your design.&lt;br /&gt;
&lt;br /&gt;
Following is a classic example being that you have the intersection between two shapes, but there's an even simpler case that's often overlooked: comparing the equality of two heterogeneous objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface IShape&lt;br /&gt;
{&lt;br /&gt;
    double intersectWith(Triangle t);&lt;br /&gt;
    double intersectWith(Rectangle r);&lt;br /&gt;
    double intersectWith(Circle c);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The problem with this is that you have coupled together all of your implementations of &amp;quot;IShape&amp;quot;. You've implied that whenever you wish to add a new shape to the hierarchy you will need to change all the other &amp;quot;Shape&amp;quot; implementations too.&lt;br /&gt;
&lt;br /&gt;
Sometimes, this is the correct minimal design - but think it through. Does your design really mandate that you need to dispatch on two types? Are you willing to write each of the combinatorial explosion of multi-methods?&lt;br /&gt;
&lt;br /&gt;
Often, by introducing another concept you can reduce the number of combinations that you're actually going to have to write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface IShape&lt;br /&gt;
{&lt;br /&gt;
    Area getArea();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Area&lt;br /&gt;
{&lt;br /&gt;
    public double intersectWith(Area otherArea);&lt;br /&gt;
    ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Command ===&lt;br /&gt;
The Command design pattern encapsulates commands (method calls) in objects allowing us to issue requests without knowing the requested operation or the requesting object. Command design pattern provides the options to queue commands, undo/redo actions and other manipulations.&lt;br /&gt;
&lt;br /&gt;
There are two extremes that a programmer must avoid when using this pattern: &lt;br /&gt;
&lt;br /&gt;
1. The command is just a link between the receiver and the actions that carry out the request&lt;br /&gt;
2. The command implements everything itself, without sending anything to the receiver.&lt;br /&gt;
&lt;br /&gt;
We must always keep in mind the fact that the receiver is the one who knows how to perform the operations needed, the purpose of the command being to help the client to delegate its request quickly and to make sure the command ends up where it should.&lt;br /&gt;
&lt;br /&gt;
One example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class FileDeleteCommand&lt;br /&gt;
   def initialize(path)&lt;br /&gt;
     @path = path&lt;br /&gt;
   end&lt;br /&gt;
   def execute&lt;br /&gt;
     File.delete(@path)&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 fdc = FileDeleteCommand.new('foo.dat')&lt;br /&gt;
 fdc.execute&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
there is nothing simpler than just getting on with it:&lt;br /&gt;
File.delete('foo.dat')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== A mixed example using Singleton Factory and Command ===&lt;br /&gt;
&lt;br /&gt;
The final goal of the program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
System.out.println(&amp;quot;hello world&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After using Singleton, Factory and Command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public interface Subject {&lt;br /&gt;
    public void attach(Observer observer);&lt;br /&gt;
    public void detach(Observer observer);&lt;br /&gt;
    public void notifyObservers();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public interface Observer {&lt;br /&gt;
    public void update(Subject subject);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public class HelloWorldSubject implements Subject {&lt;br /&gt;
    &lt;br /&gt;
    private ArrayList&amp;lt;Observer&amp;gt; observers;&lt;br /&gt;
    private String str;&lt;br /&gt;
    &lt;br /&gt;
    public HelloWorldSubject() {&lt;br /&gt;
        super();&lt;br /&gt;
&lt;br /&gt;
        observers = new ArrayList&amp;lt;Observer&amp;gt;();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void attach(Observer observer) {&lt;br /&gt;
        observers.add(observer);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void detach(Observer observer) {&lt;br /&gt;
        observers.remove(observer);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void notifyObservers() {&lt;br /&gt;
        Iterator&amp;lt;Observer&amp;gt; iter = observers.iterator();&lt;br /&gt;
        &lt;br /&gt;
        while (iter.hasNext()) {&lt;br /&gt;
            Observer observer = iter.next();&lt;br /&gt;
            observer.update(this);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public String getStr() {&lt;br /&gt;
        return str;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void setStr(String str) {&lt;br /&gt;
        this.str = str;&lt;br /&gt;
        notifyObservers();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class HelloWorldObserver implements Observer {&lt;br /&gt;
&lt;br /&gt;
    public void update(Subject subject) {&lt;br /&gt;
        HelloWorldSubject sub = (HelloWorldSubject)subject;&lt;br /&gt;
        System.out.println(sub.getStr());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then we add a Command.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public interface Command {&lt;br /&gt;
    void execute();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class HelloWorldCommand implements Command {&lt;br /&gt;
&lt;br /&gt;
    private HelloWorldSubject subject;&lt;br /&gt;
    &lt;br /&gt;
    public HelloWorldCommand(Subject subject) {&lt;br /&gt;
        super();&lt;br /&gt;
    &lt;br /&gt;
        this.subject = (HelloWorldSubject)subject;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public void execute() {&lt;br /&gt;
        subject.setStr(&amp;quot;hello world&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then We add a Factory&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public interface AbstractFactory {&lt;br /&gt;
    public Subject createSubject();&lt;br /&gt;
    public Observer createObserver();&lt;br /&gt;
    public Command createCommand(Subject subject);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class HelloWorldFactory implements AbstractFactory {&lt;br /&gt;
&lt;br /&gt;
    public Subject createSubject() {&lt;br /&gt;
        return new HelloWorldSubject();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public Observer createObserver() {&lt;br /&gt;
        return new HelloWorldObserver(); &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public Command createCommand(Subject subject) {&lt;br /&gt;
        return new HelloWorldCommand(subject);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And finally a Singleton&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class FactoryMakerSingleton {&lt;br /&gt;
    &lt;br /&gt;
    private static FactoryMakerSingleton instance = null;&lt;br /&gt;
    private AbstractFactory factory;&lt;br /&gt;
&lt;br /&gt;
    private FactoryMakerSingleton() {&lt;br /&gt;
        factory = new HelloWorldFactory();&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public static synchronized FactoryMakerSingleton getInstance() {&lt;br /&gt;
        if (instance == null) {&lt;br /&gt;
            instance = new FactoryMakerSingleton();&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return instance;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public AbstractFactory getFactory() {&lt;br /&gt;
        return factory;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the main class&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class AbuseDesignPatterns {&lt;br /&gt;
&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
        AbstractFactory factory = FactoryMakerSingleton.getInstance().getFactory();&lt;br /&gt;
        &lt;br /&gt;
        Subject subject = factory.createSubject();&lt;br /&gt;
        subject.attach(factory.createObserver());&lt;br /&gt;
        &lt;br /&gt;
        Command command = factory.createCommand(subject);&lt;br /&gt;
        &lt;br /&gt;
        command.execute();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
And the output is: Hello World&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69212</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69212"/>
		<updated>2012-10-28T03:23:54Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Command */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses classes and their methods in an object-oriented language. Developers often start thinking about design after learning a programming language and writing code for a while. You might notice that someone else’s code seems simpler and works better than yours does, and you might wonder how that developer achieves such simplicity. Design patterns are a level up from code and typically show how to achieve a goal using a few classes. A pattern represents an idea, not a particular implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Intent !! Patterns&lt;br /&gt;
|-&lt;br /&gt;
| Interfaces || ADAPTER, FACADE, COMPOSITE, BRIDGE&lt;br /&gt;
|-&lt;br /&gt;
| Responsibility || SINGLETON, OBSERVER, MEDIATOR, PROXY, CHAIN OF RESPONSIBILITY, FLYWEIGHT&lt;br /&gt;
|-&lt;br /&gt;
| Construction || BUILDER, FACTORY METHOD, ABSTRACT FACTORY, PROTOTYPE, MEMENTO&lt;br /&gt;
|-&lt;br /&gt;
| Operations|| TEMPLATE METHOD, STATE, STRATEGY, COMMAND, INTERPRETER&lt;br /&gt;
|-&lt;br /&gt;
| Extensions || DECORATOR, ITERATOR, VISITOR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
Design patterns provide a way of encapsulating the experience of software developers in a form that can be communicated to other developers. They provide a higher level of abstraction than single classes and objects thus providing bigger building blocks in the construction of software designs. &lt;br /&gt;
&lt;br /&gt;
The main benefits of design patterns are:&lt;br /&gt;
&lt;br /&gt;
*They encapsulate and codify design experience.&lt;br /&gt;
*Provide a common vocabulary for software designers to use when communicating with their peers.&lt;br /&gt;
*Enhance maintainability of software systems whose designs are documented with patterns.&lt;br /&gt;
*Provide robustness to the design by copying or imitating proven design techniques.&lt;br /&gt;
*Reuse at the design level.&lt;br /&gt;
&lt;br /&gt;
At first glance some of these benefits may not seem very powerful, but upon further inspection maybe we can gain new insight into the true nature of their value. Let us just consider the fact that we have given a design pattern a common name. We can now communicate an entire design principle or concept with other software developers by just using the simple name of the pattern. In one fell swoop we have drastically reduced the effort and time needed for a developer to discuss a concept with another developer. Taken one step further we can discuss the patterns and their interactions in the system and illustrate the system architecture in few sentences. Grouping design concepts with common names facilitates communication among developers and raises the conversation to a higher level of abstraction.&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
There are four primary symptoms that tell us that our designs are rotting. They are not orthogonal, but are related to each other in ways that will become obvious. &lt;br /&gt;
&lt;br /&gt;
The four symptoms are:&lt;br /&gt;
*Rigidity -- the tendency for software to be difficult to change, even in simple ways.&lt;br /&gt;
*Fragility -- the tendency of the software to break in many places every time it is changed. &lt;br /&gt;
*Immobility -- the inability to reuse software from other projects or from parts of the same project.&lt;br /&gt;
*Viscosity -- viscosity comes in two forms: viscosity of the design, and viscosity of the environment.&lt;br /&gt;
&lt;br /&gt;
In following passage of this wiki page, we will discuss over 'Fragility' with some examples.&lt;br /&gt;
&lt;br /&gt;
== Definition of Pattern Fragility ==&lt;br /&gt;
Fragility is the tendency of the &lt;br /&gt;
software to break in many places every time it is changed. Often the breakage occurs &lt;br /&gt;
in areas that have no conceptual relationship with the area that was changed. Such &lt;br /&gt;
errors fill the hearts of managers with foreboding. Every time they authorize a fix, &lt;br /&gt;
they fear that the software will break in some unexpected way.&lt;br /&gt;
As the fragility becomes worse, the probability of breakage increases with time, &lt;br /&gt;
asymptotically approaching 1. Such software is impossible to maintain. Every fix &lt;br /&gt;
makes it worse, introducing more problems than are solved.&lt;br /&gt;
Such software causes managers and customers to suspect that the developers have lost &lt;br /&gt;
control of their software. Distrust reigns, and credibility is lost.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton -- the most overused pattern ===&lt;br /&gt;
&lt;br /&gt;
Sometimes it's important to have only one instance for a class. For example, in a system there should be only one window manager (or only a file system). Usually singletons are used for centralized management of internal or external resources and they provide a global point of access to themselves. The primary purpose of the singleton is to guarantee that at anytime there is only one instance for a given class and provide a global reference to it.&lt;br /&gt;
&lt;br /&gt;
The singleton pattern is one of the simplest design patterns: it involves only one class which is responsible to instantiate itself, to make sure it creates not more than one instance; in the same time it provides a global point of access to that instance. In this case the same instance can be used from everywhere, being impossible to invoke directly the constructor each time.&lt;br /&gt;
&lt;br /&gt;
Well, the question is, is it safe to use a singleton class when it might be very tempting to do so? Obviously, the answer is negative. &lt;br /&gt;
&lt;br /&gt;
==== Problem 1 ====&lt;br /&gt;
There is a general misconception about how Singletons should be used. Some people see the Singleton as a justification for global state, along the lines of &amp;quot;If there's a pattern for it, it must be good&amp;quot;. Possibly, because it is true, that for having global state, it is better using Singletons, than just plainly global variables or class objects. Well no, it isn’t. Global state is considered harmful. For a number of reasons, that even Singleton-misuse won't make go away, simply because: '''Singletons are NOT intended to provide global state!'''&lt;br /&gt;
&lt;br /&gt;
The Singleton is a creational pattern. It is used to enforce, that a class be instantiated only once. What it basically does is, to give control over instantiation back to the programmer. This is what you sometimes need in languages with classical constructors (Java, C++ and such).&lt;br /&gt;
&lt;br /&gt;
=== Factory ===&lt;br /&gt;
Create an interface for building an object, but let subclasses decide which class to instantiate. It allows a class to defer instantiation of subclasses.&lt;br /&gt;
Factory pattern is one of the patterns that have being heavily abused. With as long as if --- else, go to the factory model, as long as the object involved in the creation of selective, go to the factory model. Factory pattern seems to have become the panacea to solve all.&lt;br /&gt;
But let us look at some of the above contrast with the factory pattern, you simple code it? Wrong! The contrary, no increase in the scalability of the code at the same time, it increased the number of types of calls, an increase of the number of categories. This is not what we want to see!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
One example is there is only one object to be instantiate. There was no concept of abstraction or extended classes,just plain old ClassX &amp;amp; ClassXFactory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class A {&lt;br /&gt;
       public String str;&lt;br /&gt;
       public String getStr() {&lt;br /&gt;
              return str;&lt;br /&gt;
       }&lt;br /&gt;
}// End of class&lt;br /&gt;
&lt;br /&gt;
public class ChildA extends A {&lt;br /&gt;
       public ChildA(String str) {&lt;br /&gt;
       System.out.println(&amp;quot;Hello &amp;quot;+str);&lt;br /&gt;
       }&lt;br /&gt;
}// End of class&lt;br /&gt;
&lt;br /&gt;
public class AFactory {&lt;br /&gt;
       public static void main(String args[]) {&lt;br /&gt;
              AFactory factory = new AFactory();&lt;br /&gt;
              factory.getA(args[0]);&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
       public A getA(String str) {&lt;br /&gt;
              if(str!=NULL)&lt;br /&gt;
                     return new A(str);&lt;br /&gt;
              else&lt;br /&gt;
                     return null;&lt;br /&gt;
       }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When to use a Factory Pattern?&lt;br /&gt;
The Factory patterns can be used in following cases:&lt;br /&gt;
&lt;br /&gt;
1. When a class does not know which class of objects it must create.&lt;br /&gt;
&lt;br /&gt;
2. A class specifies its sub-classes to specify which objects to create.&lt;br /&gt;
&lt;br /&gt;
3. In programmer’s language (very raw form), you can use factory pattern where you have to create an object of any one of sub-classes depending on the data provided.&lt;br /&gt;
&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
Visitor pattern represent an operation to be performed on the elements of an object structure. In GoF's word, &amp;quot;It let you define a new operation changing the classes of the elements on which it operates.&amp;quot;&lt;br /&gt;
However, It's also the one that GoF most worried about. It's not a &amp;quot;necessary evil&amp;quot; - but is often over used and the need for it often reveals a more fundamental flaw in your design.&lt;br /&gt;
&lt;br /&gt;
Following is a classic example being that you have the intersection between two shapes, but there's an even simpler case that's often overlooked: comparing the equality of two heterogeneous objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface IShape&lt;br /&gt;
{&lt;br /&gt;
    double intersectWith(Triangle t);&lt;br /&gt;
    double intersectWith(Rectangle r);&lt;br /&gt;
    double intersectWith(Circle c);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The problem with this is that you have coupled together all of your implementations of &amp;quot;IShape&amp;quot;. You've implied that whenever you wish to add a new shape to the hierarchy you will need to change all the other &amp;quot;Shape&amp;quot; implementations too.&lt;br /&gt;
&lt;br /&gt;
Sometimes, this is the correct minimal design - but think it through. Does your design really mandate that you need to dispatch on two types? Are you willing to write each of the combinatorial explosion of multi-methods?&lt;br /&gt;
&lt;br /&gt;
Often, by introducing another concept you can reduce the number of combinations that you're actually going to have to write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface IShape&lt;br /&gt;
{&lt;br /&gt;
    Area getArea();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Area&lt;br /&gt;
{&lt;br /&gt;
    public double intersectWith(Area otherArea);&lt;br /&gt;
    ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Command ===&lt;br /&gt;
The Command design pattern encapsulates commands (method calls) in objects allowing us to issue requests without knowing the requested operation or the requesting object. Command design pattern provides the options to queue commands, undo/redo actions and other manipulations.&lt;br /&gt;
&lt;br /&gt;
There are two extremes that a programmer must avoid when using this pattern: &lt;br /&gt;
&lt;br /&gt;
1. The command is just a link between the receiver and the actions that carry out the request&lt;br /&gt;
2. The command implements everything itself, without sending anything to the receiver.&lt;br /&gt;
&lt;br /&gt;
We must always keep in mind the fact that the receiver is the one who knows how to perform the operations needed, the purpose of the command being to help the client to delegate its request quickly and to make sure the command ends up where it should.&lt;br /&gt;
&lt;br /&gt;
One example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class FileDeleteCommand&lt;br /&gt;
   def initialize(path)&lt;br /&gt;
     @path = path&lt;br /&gt;
   end&lt;br /&gt;
   def execute&lt;br /&gt;
     File.delete(@path)&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 fdc = FileDeleteCommand.new('foo.dat')&lt;br /&gt;
 fdc.execute&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
there is nothing simpler than just getting on with it:&lt;br /&gt;
File.delete('foo.dat')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== A mixed example using Singleton Factory and Command ===&lt;br /&gt;
&lt;br /&gt;
The final goal of the program&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
System.out.println(&amp;quot;hello world&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After using Singleton, Factory and Command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public interface Subject {&lt;br /&gt;
    public void attach(Observer observer);&lt;br /&gt;
    public void detach(Observer observer);&lt;br /&gt;
    public void notifyObservers();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public interface Observer {&lt;br /&gt;
    public void update(Subject subject);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public class HelloWorldSubject implements Subject {&lt;br /&gt;
    &lt;br /&gt;
    private ArrayList&amp;lt;Observer&amp;gt; observers;&lt;br /&gt;
    private String str;&lt;br /&gt;
    &lt;br /&gt;
    public HelloWorldSubject() {&lt;br /&gt;
        super();&lt;br /&gt;
&lt;br /&gt;
        observers = new ArrayList&amp;lt;Observer&amp;gt;();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void attach(Observer observer) {&lt;br /&gt;
        observers.add(observer);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void detach(Observer observer) {&lt;br /&gt;
        observers.remove(observer);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void notifyObservers() {&lt;br /&gt;
        Iterator&amp;lt;Observer&amp;gt; iter = observers.iterator();&lt;br /&gt;
        &lt;br /&gt;
        while (iter.hasNext()) {&lt;br /&gt;
            Observer observer = iter.next();&lt;br /&gt;
            observer.update(this);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public String getStr() {&lt;br /&gt;
        return str;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void setStr(String str) {&lt;br /&gt;
        this.str = str;&lt;br /&gt;
        notifyObservers();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class HelloWorldObserver implements Observer {&lt;br /&gt;
&lt;br /&gt;
    public void update(Subject subject) {&lt;br /&gt;
        HelloWorldSubject sub = (HelloWorldSubject)subject;&lt;br /&gt;
        System.out.println(sub.getStr());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public interface Command {&lt;br /&gt;
    void execute();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class HelloWorldCommand implements Command {&lt;br /&gt;
&lt;br /&gt;
    private HelloWorldSubject subject;&lt;br /&gt;
    &lt;br /&gt;
    public HelloWorldCommand(Subject subject) {&lt;br /&gt;
        super();&lt;br /&gt;
    &lt;br /&gt;
        this.subject = (HelloWorldSubject)subject;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public void execute() {&lt;br /&gt;
        subject.setStr(&amp;quot;hello world&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Then We add a Factory&lt;br /&gt;
public interface AbstractFactory {&lt;br /&gt;
    public Subject createSubject();&lt;br /&gt;
    public Observer createObserver();&lt;br /&gt;
    public Command createCommand(Subject subject);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class HelloWorldFactory implements AbstractFactory {&lt;br /&gt;
&lt;br /&gt;
    public Subject createSubject() {&lt;br /&gt;
        return new HelloWorldSubject();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public Observer createObserver() {&lt;br /&gt;
        return new HelloWorldObserver(); &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public Command createCommand(Subject subject) {&lt;br /&gt;
        return new HelloWorldCommand(subject);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
And finally a Singleton&lt;br /&gt;
public class FactoryMakerSingleton {&lt;br /&gt;
    &lt;br /&gt;
    private static FactoryMakerSingleton instance = null;&lt;br /&gt;
    private AbstractFactory factory;&lt;br /&gt;
&lt;br /&gt;
    private FactoryMakerSingleton() {&lt;br /&gt;
        factory = new HelloWorldFactory();&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public static synchronized FactoryMakerSingleton getInstance() {&lt;br /&gt;
        if (instance == null) {&lt;br /&gt;
            instance = new FactoryMakerSingleton();&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return instance;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public AbstractFactory getFactory() {&lt;br /&gt;
        return factory;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
And the main class&lt;br /&gt;
public class AbuseDesignPatterns {&lt;br /&gt;
&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
        AbstractFactory factory = FactoryMakerSingleton.getInstance().getFactory();&lt;br /&gt;
        &lt;br /&gt;
        Subject subject = factory.createSubject();&lt;br /&gt;
        subject.attach(factory.createObserver());&lt;br /&gt;
        &lt;br /&gt;
        Command command = factory.createCommand(subject);&lt;br /&gt;
        &lt;br /&gt;
        command.execute();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
And the output is: Hello World&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69198</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69198"/>
		<updated>2012-10-28T03:09:08Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Visitor */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses classes and their methods in an object-oriented language. Developers often start thinking about design after learning a programming language and writing code for a while. You might notice that someone else’s code seems simpler and works better than yours does, and you might wonder how that developer achieves such simplicity. Design patterns are a level up from code and typically show how to achieve a goal using a few classes. A pattern represents an idea, not a particular implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Intent !! Patterns&lt;br /&gt;
|-&lt;br /&gt;
| Interfaces || ADAPTER, FACADE, COMPOSITE, BRIDGE&lt;br /&gt;
|-&lt;br /&gt;
| Responsibility || SINGLETON, OBSERVER, MEDIATOR, PROXY, CHAIN OF RESPONSIBILITY, FLYWEIGHT&lt;br /&gt;
|-&lt;br /&gt;
| Construction || BUILDER, FACTORY METHOD, ABSTRACT FACTORY, PROTOTYPE, MEMENTO&lt;br /&gt;
|-&lt;br /&gt;
| Operations|| TEMPLATE METHOD, STATE, STRATEGY, COMMAND, INTERPRETER&lt;br /&gt;
|-&lt;br /&gt;
| Extensions || DECORATOR, ITERATOR, VISITOR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
Design patterns provide a way of encapsulating the experience of software developers in a form that can be communicated to other developers. They provide a higher level of abstraction than single classes and objects thus providing bigger building blocks in the construction of software designs. &lt;br /&gt;
&lt;br /&gt;
The main benefits of design patterns are:&lt;br /&gt;
&lt;br /&gt;
*They encapsulate and codify design experience.&lt;br /&gt;
*Provide a common vocabulary for software designers to use when communicating with their peers.&lt;br /&gt;
*Enhance maintainability of software systems whose designs are documented with patterns.&lt;br /&gt;
*Provide robustness to the design by copying or imitating proven design techniques.&lt;br /&gt;
*Reuse at the design level.&lt;br /&gt;
&lt;br /&gt;
At first glance some of these benefits may not seem very powerful, but upon further inspection maybe we can gain new insight into the true nature of their value. Let us just consider the fact that we have given a design pattern a common name. We can now communicate an entire design principle or concept with other software developers by just using the simple name of the pattern. In one fell swoop we have drastically reduced the effort and time needed for a developer to discuss a concept with another developer. Taken one step further we can discuss the patterns and their interactions in the system and illustrate the system architecture in few sentences. Grouping design concepts with common names facilitates communication among developers and raises the conversation to a higher level of abstraction.&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
There are four primary symptoms that tell us that our designs are rotting. They are not orthogonal, but are related to each other in ways that will become obvious. &lt;br /&gt;
&lt;br /&gt;
The four symptoms are:&lt;br /&gt;
*Rigidity -- the tendency for software to be difficult to change, even in simple ways.&lt;br /&gt;
*Fragility -- the tendency of the software to break in many places every time it is changed. &lt;br /&gt;
*Immobility -- the inability to reuse software from other projects or from parts of the same project.&lt;br /&gt;
*Viscosity -- viscosity comes in two forms: viscosity of the design, and viscosity of the environment.&lt;br /&gt;
&lt;br /&gt;
In following passage of this wiki page, we will discuss over 'Fragility' with some examples.&lt;br /&gt;
&lt;br /&gt;
== Definition of Pattern Fragility ==&lt;br /&gt;
Fragility is the tendency of the &lt;br /&gt;
software to break in many places every time it is changed. Often the breakage occurs &lt;br /&gt;
in areas that have no conceptual relationship with the area that was changed. Such &lt;br /&gt;
errors fill the hearts of managers with foreboding. Every time they authorize a fix, &lt;br /&gt;
they fear that the software will break in some unexpected way.&lt;br /&gt;
As the fragility becomes worse, the probability of breakage increases with time, &lt;br /&gt;
asymptotically approaching 1. Such software is impossible to maintain. Every fix &lt;br /&gt;
makes it worse, introducing more problems than are solved.&lt;br /&gt;
Such software causes managers and customers to suspect that the developers have lost &lt;br /&gt;
control of their software. Distrust reigns, and credibility is lost.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton -- the most overused pattern ===&lt;br /&gt;
&lt;br /&gt;
Sometimes it's important to have only one instance for a class. For example, in a system there should be only one window manager (or only a file system). Usually singletons are used for centralized management of internal or external resources and they provide a global point of access to themselves. The primary purpose of the singleton is to guarantee that at anytime there is only one instance for a given class and provide a global reference to it.&lt;br /&gt;
&lt;br /&gt;
The singleton pattern is one of the simplest design patterns: it involves only one class which is responsible to instantiate itself, to make sure it creates not more than one instance; in the same time it provides a global point of access to that instance. In this case the same instance can be used from everywhere, being impossible to invoke directly the constructor each time.&lt;br /&gt;
&lt;br /&gt;
Well, the question is, is it safe to use a singleton class when it might be very tempting to do so? Obviously, the answer is negative. &lt;br /&gt;
&lt;br /&gt;
==== Problem 1 ====&lt;br /&gt;
There is a general misconception about how Singletons should be used. Some people see the Singleton as a justification for global state, along the lines of &amp;quot;If there's a pattern for it, it must be good&amp;quot;. Possibly, because it is true, that for having global state, it is better using Singletons, than just plainly global variables or class objects. Well no, it isn’t. Global state is considered harmful. For a number of reasons, that even Singleton-misuse won't make go away, simply because: '''Singletons are NOT intended to provide global state!'''&lt;br /&gt;
&lt;br /&gt;
The Singleton is a creational pattern. It is used to enforce, that a class be instantiated only once. What it basically does is, to give control over instantiation back to the programmer. This is what you sometimes need in languages with classical constructors (Java, C++ and such).&lt;br /&gt;
&lt;br /&gt;
=== Factory ===&lt;br /&gt;
Create an interface for building an object, but let subclasses decide which class to instantiate. It allows a class to defer instantiation of subclasses.&lt;br /&gt;
Factory pattern is one of the patterns that have being heavily abused. With as long as if --- else, go to the factory model, as long as the object involved in the creation of selective, go to the factory model. Factory pattern seems to have become the panacea to solve all.&lt;br /&gt;
But let us look at some of the above contrast with the factory pattern, you simple code it? Wrong! The contrary, no increase in the scalability of the code at the same time, it increased the number of types of calls, an increase of the number of categories. This is not what we want to see!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
One example is there is only one object to be instantiate. There was no concept of abstraction or extended classes,just plain old ClassX &amp;amp; ClassXFactory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class A {&lt;br /&gt;
       public String str;&lt;br /&gt;
       public String getStr() {&lt;br /&gt;
              return str;&lt;br /&gt;
       }&lt;br /&gt;
}// End of class&lt;br /&gt;
&lt;br /&gt;
public class ChildA extends A {&lt;br /&gt;
       public ChildA(String str) {&lt;br /&gt;
       System.out.println(&amp;quot;Hello &amp;quot;+str);&lt;br /&gt;
       }&lt;br /&gt;
}// End of class&lt;br /&gt;
&lt;br /&gt;
public class AFactory {&lt;br /&gt;
       public static void main(String args[]) {&lt;br /&gt;
              AFactory factory = new AFactory();&lt;br /&gt;
              factory.getA(args[0]);&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
       public A getA(String str) {&lt;br /&gt;
              if(str!=NULL)&lt;br /&gt;
                     return new A(str);&lt;br /&gt;
              else&lt;br /&gt;
                     return null;&lt;br /&gt;
       }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When to use a Factory Pattern?&lt;br /&gt;
The Factory patterns can be used in following cases:&lt;br /&gt;
&lt;br /&gt;
1. When a class does not know which class of objects it must create.&lt;br /&gt;
&lt;br /&gt;
2. A class specifies its sub-classes to specify which objects to create.&lt;br /&gt;
&lt;br /&gt;
3. In programmer’s language (very raw form), you can use factory pattern where you have to create an object of any one of sub-classes depending on the data provided.&lt;br /&gt;
&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
Visitor pattern represent an operation to be performed on the elements of an object structure. In GoF's word, &amp;quot;It let you define a new operation changing the classes of the elements on which it operates.&amp;quot;&lt;br /&gt;
However, It's also the one that GoF most worried about. It's not a &amp;quot;necessary evil&amp;quot; - but is often over used and the need for it often reveals a more fundamental flaw in your design.&lt;br /&gt;
&lt;br /&gt;
Following is a classic example being that you have the intersection between two shapes, but there's an even simpler case that's often overlooked: comparing the equality of two heterogeneous objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface IShape&lt;br /&gt;
{&lt;br /&gt;
    double intersectWith(Triangle t);&lt;br /&gt;
    double intersectWith(Rectangle r);&lt;br /&gt;
    double intersectWith(Circle c);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The problem with this is that you have coupled together all of your implementations of &amp;quot;IShape&amp;quot;. You've implied that whenever you wish to add a new shape to the hierarchy you will need to change all the other &amp;quot;Shape&amp;quot; implementations too.&lt;br /&gt;
&lt;br /&gt;
Sometimes, this is the correct minimal design - but think it through. Does your design really mandate that you need to dispatch on two types? Are you willing to write each of the combinatorial explosion of multi-methods?&lt;br /&gt;
&lt;br /&gt;
Often, by introducing another concept you can reduce the number of combinations that you're actually going to have to write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface IShape&lt;br /&gt;
{&lt;br /&gt;
    Area getArea();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Area&lt;br /&gt;
{&lt;br /&gt;
    public double intersectWith(Area otherArea);&lt;br /&gt;
    ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Command ===&lt;br /&gt;
The Command design pattern encapsulates commands (method calls) in objects allowing us to issue requests without knowing the requested operation or the requesting object. Command design pattern provides the options to queue commands, undo/redo actions and other manipulations.&lt;br /&gt;
&lt;br /&gt;
There are two extremes that a programmer must avoid when using this pattern: &lt;br /&gt;
&lt;br /&gt;
1. The command is just a link between the receiver and the actions that carry out the request&lt;br /&gt;
2. The command implements everything itself, without sending anything to the receiver.&lt;br /&gt;
&lt;br /&gt;
We must always keep in mind the fact that the receiver is the one who knows how to perform the operations needed, the purpose of the command being to help the client to delegate its request quickly and to make sure the command ends up where it should.&lt;br /&gt;
&lt;br /&gt;
One example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class FileDeleteCommand&lt;br /&gt;
   def initialize(path)&lt;br /&gt;
     @path = path&lt;br /&gt;
   end&lt;br /&gt;
   def execute&lt;br /&gt;
     File.delete(@path)&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 fdc = FileDeleteCommand.new('foo.dat')&lt;br /&gt;
 fdc.execute&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
there is nothing simpler than just getting on with it:&lt;br /&gt;
File.delete('foo.dat')&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69192</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69192"/>
		<updated>2012-10-28T02:54:20Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses classes and their methods in an object-oriented language. Developers often start thinking about design after learning a programming language and writing code for a while. You might notice that someone else’s code seems simpler and works better than yours does, and you might wonder how that developer achieves such simplicity. Design patterns are a level up from code and typically show how to achieve a goal using a few classes. A pattern represents an idea, not a particular implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Intent !! Patterns&lt;br /&gt;
|-&lt;br /&gt;
| Interfaces || ADAPTER, FACADE, COMPOSITE, BRIDGE&lt;br /&gt;
|-&lt;br /&gt;
| Responsibility || SINGLETON, OBSERVER, MEDIATOR, PROXY, CHAIN OF RESPONSIBILITY, FLYWEIGHT&lt;br /&gt;
|-&lt;br /&gt;
| Construction || BUILDER, FACTORY METHOD, ABSTRACT FACTORY, PROTOTYPE, MEMENTO&lt;br /&gt;
|-&lt;br /&gt;
| Operations|| TEMPLATE METHOD, STATE, STRATEGY, COMMAND, INTERPRETER&lt;br /&gt;
|-&lt;br /&gt;
| Extensions || DECORATOR, ITERATOR, VISITOR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
Design patterns provide a way of encapsulating the experience of software developers in a form that can be communicated to other developers. They provide a higher level of abstraction than single classes and objects thus providing bigger building blocks in the construction of software designs. &lt;br /&gt;
&lt;br /&gt;
The main benefits of design patterns are:&lt;br /&gt;
&lt;br /&gt;
*They encapsulate and codify design experience.&lt;br /&gt;
*Provide a common vocabulary for software designers to use when communicating with their peers.&lt;br /&gt;
*Enhance maintainability of software systems whose designs are documented with patterns.&lt;br /&gt;
*Provide robustness to the design by copying or imitating proven design techniques.&lt;br /&gt;
*Reuse at the design level.&lt;br /&gt;
&lt;br /&gt;
At first glance some of these benefits may not seem very powerful, but upon further inspection maybe we can gain new insight into the true nature of their value. Let us just consider the fact that we have given a design pattern a common name. We can now communicate an entire design principle or concept with other software developers by just using the simple name of the pattern. In one fell swoop we have drastically reduced the effort and time needed for a developer to discuss a concept with another developer. Taken one step further we can discuss the patterns and their interactions in the system and illustrate the system architecture in few sentences. Grouping design concepts with common names facilitates communication among developers and raises the conversation to a higher level of abstraction.&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
There are four primary symptoms that tell us that our designs are rotting. They are not orthogonal, but are related to each other in ways that will become obvious. &lt;br /&gt;
&lt;br /&gt;
The four symptoms are:&lt;br /&gt;
*Rigidity -- the tendency for software to be difficult to change, even in simple ways.&lt;br /&gt;
*Fragility -- the tendency of the software to break in many places every time it is changed. &lt;br /&gt;
*Immobility -- the inability to reuse software from other projects or from parts of the same project.&lt;br /&gt;
*Viscosity -- viscosity comes in two forms: viscosity of the design, and viscosity of the environment.&lt;br /&gt;
&lt;br /&gt;
In following passage of this wiki page, we will discuss over 'Fragility' with some examples.&lt;br /&gt;
&lt;br /&gt;
== Definition of Pattern Fragility ==&lt;br /&gt;
Fragility is the tendency of the &lt;br /&gt;
software to break in many places every time it is changed. Often the breakage occurs &lt;br /&gt;
in areas that have no conceptual relationship with the area that was changed. Such &lt;br /&gt;
errors fill the hearts of managers with foreboding. Every time they authorize a fix, &lt;br /&gt;
they fear that the software will break in some unexpected way.&lt;br /&gt;
As the fragility becomes worse, the probability of breakage increases with time, &lt;br /&gt;
asymptotically approaching 1. Such software is impossible to maintain. Every fix &lt;br /&gt;
makes it worse, introducing more problems than are solved.&lt;br /&gt;
Such software causes managers and customers to suspect that the developers have lost &lt;br /&gt;
control of their software. Distrust reigns, and credibility is lost.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton -- the most overused pattern ===&lt;br /&gt;
&lt;br /&gt;
Sometimes it's important to have only one instance for a class. For example, in a system there should be only one window manager (or only a file system). Usually singletons are used for centralized management of internal or external resources and they provide a global point of access to themselves. The primary purpose of the singleton is to guarantee that at anytime there is only one instance for a given class and provide a global reference to it.&lt;br /&gt;
&lt;br /&gt;
The singleton pattern is one of the simplest design patterns: it involves only one class which is responsible to instantiate itself, to make sure it creates not more than one instance; in the same time it provides a global point of access to that instance. In this case the same instance can be used from everywhere, being impossible to invoke directly the constructor each time.&lt;br /&gt;
&lt;br /&gt;
Well, the question is, is it safe to use a singleton class when it might be very tempting to do so? Obviously, the answer is negative. There is a general misconception about how Singletons should be used. Possibly, because it is true, that for having global state, it is better using Singletons, than just plainly global variables or class objects.&lt;br /&gt;
&lt;br /&gt;
Some people see the Singleton as a justification for global state, along the lines of &amp;quot;If there's a pattern for it, it must be good&amp;quot;. Well no, it isn’t. Global state is considered harmful. For a number of reasons, that even Singleton-misuse won't make go away, simply because: '''Singletons are NOT intended to provide global state!'''&lt;br /&gt;
&lt;br /&gt;
The Singleton is a creational pattern. It is used to enforce, that a class be instantiated only once. What it basically does is, to give control over instantiation back to the programmer. This is what you sometimes need in languages with classical constructors (Java, C++ and such).&lt;br /&gt;
&lt;br /&gt;
=== Factory ===&lt;br /&gt;
Create an interface for building an object, but let subclasses decide which class to instantiate. It allows a class to defer instantiation of subclasses.&lt;br /&gt;
Factory pattern is one of the patterns that have being heavily abused. With as long as if --- else, go to the factory model, as long as the object involved in the creation of selective, go to the factory model. Factory pattern seems to have become the panacea to solve all.&lt;br /&gt;
But let us look at some of the above contrast with the factory pattern, you simple code it? Wrong! The contrary, no increase in the scalability of the code at the same time, it increased the number of types of calls, an increase of the number of categories. This is not what we want to see!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
One example is there is only one object to be instantiate. There was no concept of abstraction or extended classes,just plain old ClassX &amp;amp; ClassXFactory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class A {&lt;br /&gt;
       public String str;&lt;br /&gt;
       public String getStr() {&lt;br /&gt;
              return str;&lt;br /&gt;
       }&lt;br /&gt;
}// End of class&lt;br /&gt;
&lt;br /&gt;
public class ChildA extends A {&lt;br /&gt;
       public ChildA(String str) {&lt;br /&gt;
       System.out.println(&amp;quot;Hello &amp;quot;+str);&lt;br /&gt;
       }&lt;br /&gt;
}// End of class&lt;br /&gt;
&lt;br /&gt;
public class AFactory {&lt;br /&gt;
       public static void main(String args[]) {&lt;br /&gt;
              AFactory factory = new AFactory();&lt;br /&gt;
              factory.getA(args[0]);&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
       public A getA(String str) {&lt;br /&gt;
              if(str!=NULL)&lt;br /&gt;
                     return new A(str);&lt;br /&gt;
              else&lt;br /&gt;
                     return null;&lt;br /&gt;
       }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When to use a Factory Pattern?&lt;br /&gt;
The Factory patterns can be used in following cases:&lt;br /&gt;
&lt;br /&gt;
1. When a class does not know which class of objects it must create.&lt;br /&gt;
&lt;br /&gt;
2. A class specifies its sub-classes to specify which objects to create.&lt;br /&gt;
&lt;br /&gt;
3. In programmer’s language (very raw form), you can use factory pattern where you have to create an object of any one of sub-classes depending on the data provided.&lt;br /&gt;
&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
Visitor pattern represent an operation to be performed on the elements of an object structure. In GoF's word, &amp;quot;It let you define a new operation changing the classes of the elements on which it operates.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Command ===&lt;br /&gt;
The Command design pattern encapsulates commands (method calls) in objects allowing us to issue requests without knowing the requested operation or the requesting object. Command design pattern provides the options to queue commands, undo/redo actions and other manipulations.&lt;br /&gt;
&lt;br /&gt;
There are two extremes that a programmer must avoid when using this pattern: &lt;br /&gt;
&lt;br /&gt;
1. The command is just a link between the receiver and the actions that carry out the request&lt;br /&gt;
2. The command implements everything itself, without sending anything to the receiver.&lt;br /&gt;
&lt;br /&gt;
We must always keep in mind the fact that the receiver is the one who knows how to perform the operations needed, the purpose of the command being to help the client to delegate its request quickly and to make sure the command ends up where it should.&lt;br /&gt;
&lt;br /&gt;
One example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class FileDeleteCommand&lt;br /&gt;
   def initialize(path)&lt;br /&gt;
     @path = path&lt;br /&gt;
   end&lt;br /&gt;
   def execute&lt;br /&gt;
     File.delete(@path)&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 fdc = FileDeleteCommand.new('foo.dat')&lt;br /&gt;
 fdc.execute&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
there is nothing simpler than just getting on with it:&lt;br /&gt;
File.delete('foo.dat')&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69191</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69191"/>
		<updated>2012-10-28T02:53:57Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses classes and their methods in an object-oriented language. Developers often start thinking about design after learning a programming language and writing code for a while. You might notice that someone else’s code seems simpler and works better than yours does, and you might wonder how that developer achieves such simplicity. Design patterns are a level up from code and typically show how to achieve a goal using a few classes. A pattern represents an idea, not a particular implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Intent !! Patterns&lt;br /&gt;
|-&lt;br /&gt;
| Interfaces || ADAPTER, FACADE, COMPOSITE, BRIDGE&lt;br /&gt;
|-&lt;br /&gt;
| Responsibility || SINGLETON, OBSERVER, MEDIATOR, PROXY, CHAIN OF RESPONSIBILITY, FLYWEIGHT&lt;br /&gt;
|-&lt;br /&gt;
| Construction || BUILDER, FACTORY METHOD, ABSTRACT FACTORY, PROTOTYPE, MEMENTO&lt;br /&gt;
|-&lt;br /&gt;
| Operations|| TEMPLATE METHOD, STATE, STRATEGY, COMMAND, INTERPRETER&lt;br /&gt;
|-&lt;br /&gt;
| Extensions || DECORATOR, ITERATOR, VISITOR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
Design patterns provide a way of encapsulating the experience of software developers in a form that can be communicated to other developers. They provide a higher level of abstraction than single classes and objects thus providing bigger building blocks in the construction of software designs. &lt;br /&gt;
&lt;br /&gt;
The main benefits of design patterns are:&lt;br /&gt;
&lt;br /&gt;
*They encapsulate and codify design experience.&lt;br /&gt;
*Provide a common vocabulary for software designers to use when communicating with their peers.&lt;br /&gt;
*Enhance maintainability of software systems whose designs are documented with patterns.&lt;br /&gt;
*Provide robustness to the design by copying or imitating proven design techniques.&lt;br /&gt;
*Reuse at the design level.&lt;br /&gt;
&lt;br /&gt;
At first glance some of these benefits may not seem very powerful, but upon further inspection maybe we can gain new insight into the true nature of their value. Let us just consider the fact that we have given a design pattern a common name. We can now communicate an entire design principle or concept with other software developers by just using the simple name of the pattern. In one fell swoop we have drastically reduced the effort and time needed for a developer to discuss a concept with another developer. Taken one step further we can discuss the patterns and their interactions in the system and illustrate the system architecture in few sentences. Grouping design concepts with common names facilitates communication among developers and raises the conversation to a higher level of abstraction.&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
There are four primary symptoms that tell us that our designs are rotting. They are not orthogonal, but are related to each other in ways that will become obvious. &lt;br /&gt;
&lt;br /&gt;
The four symptoms are:&lt;br /&gt;
*Rigidity -- the tendency for software to be difficult to change, even in simple ways.&lt;br /&gt;
*Fragility -- the tendency of the software to break in many places every time it is changed. &lt;br /&gt;
*Immobility -- the inability to reuse software from other projects or from parts of the same project.&lt;br /&gt;
*Viscosity -- viscosity comes in two forms: viscosity of the design, and viscosity of the environment.&lt;br /&gt;
&lt;br /&gt;
In following passage of this wiki page, we will discuss over 'Fragility' with some examples.&lt;br /&gt;
&lt;br /&gt;
== Definition of Pattern Fragility ==&lt;br /&gt;
Fragility is the tendency of the &lt;br /&gt;
software to break in many places every time it is changed. Often the breakage occurs &lt;br /&gt;
in areas that have no conceptual relationship with the area that was changed. Such &lt;br /&gt;
errors fill the hearts of managers with foreboding. Every time they authorize a fix, &lt;br /&gt;
they fear that the software will break in some unexpected way.&lt;br /&gt;
As the fragility becomes worse, the probability of breakage increases with time, &lt;br /&gt;
asymptotically approaching 1. Such software is impossible to maintain. Every fix &lt;br /&gt;
makes it worse, introducing more problems than are solved.&lt;br /&gt;
Such software causes managers and customers to suspect that the developers have lost &lt;br /&gt;
control of their software. Distrust reigns, and credibility is lost.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton -- the most overused pattern ===&lt;br /&gt;
&lt;br /&gt;
Sometimes it's important to have only one instance for a class. For example, in a system there should be only one window manager (or only a file system). Usually singletons are used for centralized management of internal or external resources and they provide a global point of access to themselves. The primary purpose of the singleton is to guarantee that at anytime there is only one instance for a given class and provide a global reference to it.&lt;br /&gt;
&lt;br /&gt;
The singleton pattern is one of the simplest design patterns: it involves only one class which is responsible to instantiate itself, to make sure it creates not more than one instance; in the same time it provides a global point of access to that instance. In this case the same instance can be used from everywhere, being impossible to invoke directly the constructor each time.&lt;br /&gt;
&lt;br /&gt;
Well, the question is, is it safe to use a singleton class when it might be very tempting to do so? Obviously, the answer is negative. There is a general misconception about how Singletons should be used. Possibly, because it is true, that for having global state, it is better using Singletons, than just plainly global variables or class objects.&lt;br /&gt;
&lt;br /&gt;
Some people see the Singleton as a justification for global state, along the lines of &amp;quot;If there's a pattern for it, it must be good&amp;quot;. Well no, it isn’t. Global state is considered harmful. For a number of reasons, that even Singleton-misuse won't make go away, simply because: '''Singletons are NOT intended to provide global state!'''&lt;br /&gt;
&lt;br /&gt;
The Singleton is a creational pattern. It is used to enforce, that a class be instantiated only once. What it basically does is, to give control over instantiation back to the programmer. This is what you sometimes need in languages with classical constructors (Java, C++ and such).&lt;br /&gt;
&lt;br /&gt;
=== Factory ===&lt;br /&gt;
Create an interface for building an object, but let subclasses decide which class to instantiate. It allows a class to defer instantiation of subclasses.&lt;br /&gt;
Factory pattern is one of the patterns that have being heavily abused. With as long as if --- else, go to the factory model, as long as the object involved in the creation of selective, go to the factory model. Factory pattern seems to have become the panacea to solve all.&lt;br /&gt;
But let us look at some of the above contrast with the factory pattern, you simple code it? Wrong! The contrary, no increase in the scalability of the code at the same time, it increased the number of types of calls, an increase of the number of categories. This is not what we want to see!&lt;br /&gt;
&lt;br /&gt;
One example is there is only one object to be instantiate. There was no concept of abstraction or extended classes,just plain old ClassX &amp;amp; ClassXFactory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class A {&lt;br /&gt;
       public String str;&lt;br /&gt;
       public String getStr() {&lt;br /&gt;
              return str;&lt;br /&gt;
       }&lt;br /&gt;
}// End of class&lt;br /&gt;
&lt;br /&gt;
public class ChildA extends A {&lt;br /&gt;
       public ChildA(String str) {&lt;br /&gt;
       System.out.println(&amp;quot;Hello &amp;quot;+str);&lt;br /&gt;
       }&lt;br /&gt;
}// End of class&lt;br /&gt;
&lt;br /&gt;
public class AFactory {&lt;br /&gt;
       public static void main(String args[]) {&lt;br /&gt;
              AFactory factory = new AFactory();&lt;br /&gt;
              factory.getA(args[0]);&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
       public A getA(String str) {&lt;br /&gt;
              if(str!=NULL)&lt;br /&gt;
                     return new A(str);&lt;br /&gt;
              else&lt;br /&gt;
                     return null;&lt;br /&gt;
       }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When to use a Factory Pattern?&lt;br /&gt;
The Factory patterns can be used in following cases:&lt;br /&gt;
&lt;br /&gt;
1. When a class does not know which class of objects it must create.&lt;br /&gt;
&lt;br /&gt;
2. A class specifies its sub-classes to specify which objects to create.&lt;br /&gt;
&lt;br /&gt;
3. In programmer’s language (very raw form), you can use factory pattern where you have to create an object of any one of sub-classes depending on the data provided.&lt;br /&gt;
&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
Visitor pattern represent an operation to be performed on the elements of an object structure. In GoF's word, &amp;quot;It let you define a new operation changing the classes of the elements on which it operates.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Command ===&lt;br /&gt;
The Command design pattern encapsulates commands (method calls) in objects allowing us to issue requests without knowing the requested operation or the requesting object. Command design pattern provides the options to queue commands, undo/redo actions and other manipulations.&lt;br /&gt;
&lt;br /&gt;
There are two extremes that a programmer must avoid when using this pattern: &lt;br /&gt;
&lt;br /&gt;
1. The command is just a link between the receiver and the actions that carry out the request&lt;br /&gt;
2. The command implements everything itself, without sending anything to the receiver.&lt;br /&gt;
&lt;br /&gt;
We must always keep in mind the fact that the receiver is the one who knows how to perform the operations needed, the purpose of the command being to help the client to delegate its request quickly and to make sure the command ends up where it should.&lt;br /&gt;
&lt;br /&gt;
One example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class FileDeleteCommand&lt;br /&gt;
   def initialize(path)&lt;br /&gt;
     @path = path&lt;br /&gt;
   end&lt;br /&gt;
   def execute&lt;br /&gt;
     File.delete(@path)&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 fdc = FileDeleteCommand.new('foo.dat')&lt;br /&gt;
 fdc.execute&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
there is nothing simpler than just getting on with it:&lt;br /&gt;
File.delete('foo.dat')&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69190</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69190"/>
		<updated>2012-10-28T02:52:34Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses classes and their methods in an object-oriented language. Developers often start thinking about design after learning a programming language and writing code for a while. You might notice that someone else’s code seems simpler and works better than yours does, and you might wonder how that developer achieves such simplicity. Design patterns are a level up from code and typically show how to achieve a goal using a few classes. A pattern represents an idea, not a particular implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Intent !! Patterns&lt;br /&gt;
|-&lt;br /&gt;
| Interfaces || ADAPTER, FACADE, COMPOSITE, BRIDGE&lt;br /&gt;
|-&lt;br /&gt;
| Responsibility || SINGLETON, OBSERVER, MEDIATOR, PROXY, CHAIN OF RESPONSIBILITY, FLYWEIGHT&lt;br /&gt;
|-&lt;br /&gt;
| Construction || BUILDER, FACTORY METHOD, ABSTRACT FACTORY, PROTOTYPE, MEMENTO&lt;br /&gt;
|-&lt;br /&gt;
| Operations|| TEMPLATE METHOD, STATE, STRATEGY, COMMAND, INTERPRETER&lt;br /&gt;
|-&lt;br /&gt;
| Extensions || DECORATOR, ITERATOR, VISITOR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
Design patterns provide a way of encapsulating the experience of software developers in a form that can be communicated to other developers. They provide a higher level of abstraction than single classes and objects thus providing bigger building blocks in the construction of software designs. &lt;br /&gt;
&lt;br /&gt;
The main benefits of design patterns are:&lt;br /&gt;
&lt;br /&gt;
*They encapsulate and codify design experience.&lt;br /&gt;
*Provide a common vocabulary for software designers to use when communicating with their peers.&lt;br /&gt;
*Enhance maintainability of software systems whose designs are documented with patterns.&lt;br /&gt;
*Provide robustness to the design by copying or imitating proven design techniques.&lt;br /&gt;
*Reuse at the design level.&lt;br /&gt;
&lt;br /&gt;
At first glance some of these benefits may not seem very powerful, but upon further inspection maybe we can gain new insight into the true nature of their value. Let us just consider the fact that we have given a design pattern a common name. We can now communicate an entire design principle or concept with other software developers by just using the simple name of the pattern. In one fell swoop we have drastically reduced the effort and time needed for a developer to discuss a concept with another developer. Taken one step further we can discuss the patterns and their interactions in the system and illustrate the system architecture in few sentences. Grouping design concepts with common names facilitates communication among developers and raises the conversation to a higher level of abstraction.&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
There are four primary symptoms that tell us that our designs are rotting. They are not orthogonal, but are related to each other in ways that will become obvious. &lt;br /&gt;
&lt;br /&gt;
The four symptoms are:&lt;br /&gt;
*Rigidity -- the tendency for software to be difficult to change, even in simple ways.&lt;br /&gt;
*Fragility -- the tendency of the software to break in many places every time it is changed. &lt;br /&gt;
*Immobility -- the inability to reuse software from other projects or from parts of the same project.&lt;br /&gt;
*Viscosity -- viscosity comes in two forms: viscosity of the design, and viscosity of the environment.&lt;br /&gt;
&lt;br /&gt;
In following passage of this wiki page, we will discuss over 'Fragility' with some examples.&lt;br /&gt;
&lt;br /&gt;
== Definition of Pattern Fragility ==&lt;br /&gt;
Fragility is the tendency of the &lt;br /&gt;
software to break in many places every time it is changed. Often the breakage occurs &lt;br /&gt;
in areas that have no conceptual relationship with the area that was changed. Such &lt;br /&gt;
errors fill the hearts of managers with foreboding. Every time they authorize a fix, &lt;br /&gt;
they fear that the software will break in some unexpected way.&lt;br /&gt;
As the fragility becomes worse, the probability of breakage increases with time, &lt;br /&gt;
asymptotically approaching 1. Such software is impossible to maintain. Every fix &lt;br /&gt;
makes it worse, introducing more problems than are solved.&lt;br /&gt;
Such software causes managers and customers to suspect that the developers have lost &lt;br /&gt;
control of their software. Distrust reigns, and credibility is lost.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton -- the most overused pattern ===&lt;br /&gt;
&lt;br /&gt;
Sometimes it's important to have only one instance for a class. For example, in a system there should be only one window manager (or only a file system). Usually singletons are used for centralized management of internal or external resources and they provide a global point of access to themselves. The primary purpose of the singleton is to guarantee that at anytime there is only one instance for a given class and provide a global reference to it.&lt;br /&gt;
&lt;br /&gt;
The singleton pattern is one of the simplest design patterns: it involves only one class which is responsible to instantiate itself, to make sure it creates not more than one instance; in the same time it provides a global point of access to that instance. In this case the same instance can be used from everywhere, being impossible to invoke directly the constructor each time.&lt;br /&gt;
&lt;br /&gt;
Well, the question is, is it safe to use a singleton class when it might be very tempting to do so? Obviously, the answer is negative. There is a general misconception about how Singletons should be used. Possibly, because it is true, that for having global state, it is better using Singletons, than just plainly global variables or class objects.&lt;br /&gt;
&lt;br /&gt;
Some people see the Singleton as a justification for global state, along the lines of &amp;quot;If there's a pattern for it, it must be good&amp;quot;. Well no, it isn’t. Global state is considered harmful. For a number of reasons, that even Singleton-misuse won't make go away, simply because: '''Singletons are NOT intended to provide global state!'''&lt;br /&gt;
&lt;br /&gt;
The Singleton is a creational pattern. It is used to enforce, that a class be instantiated only once. What it basically does is, to give control over instantiation back to the programmer. This is what you sometimes need in languages with classical constructors (Java, C++ and such).&lt;br /&gt;
&lt;br /&gt;
=== Factory ===&lt;br /&gt;
Create an interface for building an object, but let subclasses decide which class to instantiate. It allows a class to defer instantiation of subclasses.&lt;br /&gt;
Factory pattern is one of the patterns that have being heavily abused. With as long as if --- else, go to the factory model, as long as the object involved in the creation of selective, go to the factory model. Factory pattern seems to have become the panacea to solve all.&lt;br /&gt;
But let us look at some of the above contrast with the factory pattern, you simple code it? Wrong! The contrary, no increase in the scalability of the code at the same time, it increased the number of types of calls, an increase of the number of categories. This is not what we want to see!&lt;br /&gt;
&lt;br /&gt;
One example is there is only one object to be instantiate. There was no concept of abstraction or extended classes,just plain old ClassX &amp;amp; ClassXFactory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class A {&lt;br /&gt;
public String str;&lt;br /&gt;
&lt;br /&gt;
public String getStr() {&lt;br /&gt;
return str;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}// End of class&lt;br /&gt;
&lt;br /&gt;
public class ChildA extends A {&lt;br /&gt;
public ChildA(String str) {&lt;br /&gt;
System.out.println(&amp;quot;Hello &amp;quot;+str);&lt;br /&gt;
}&lt;br /&gt;
}// End of class&lt;br /&gt;
&lt;br /&gt;
public class AFactory {&lt;br /&gt;
public static void main(String args[]) {&lt;br /&gt;
AFactory factory = new AFactory();&lt;br /&gt;
factory.getA(args[0]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public A getA(String str) {&lt;br /&gt;
if(str!=NULL)&lt;br /&gt;
return new A(str);&lt;br /&gt;
else&lt;br /&gt;
return null;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When to use a Factory Pattern?&lt;br /&gt;
The Factory patterns can be used in following cases:&lt;br /&gt;
1. When a class does not know which class of objects it must create.&lt;br /&gt;
2. A class specifies its sub-classes to specify which objects to create.&lt;br /&gt;
3. In programmer’s language (very raw form), you can use factory pattern where you have to create an object of any one of sub-classes depending on the data provided.&lt;br /&gt;
&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
Visitor pattern represent an operation to be performed on the elements of an object structure. In GoF's word, &amp;quot;It let you define a new operation changing the classes of the elements on which it operates.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Command ===&lt;br /&gt;
The Command design pattern encapsulates commands (method calls) in objects allowing us to issue requests without knowing the requested operation or the requesting object. Command design pattern provides the options to queue commands, undo/redo actions and other manipulations.&lt;br /&gt;
&lt;br /&gt;
There are two extremes that a programmer must avoid when using this pattern: &lt;br /&gt;
&lt;br /&gt;
1. The command is just a link between the receiver and the actions that carry out the request&lt;br /&gt;
2. The command implements everything itself, without sending anything to the receiver.&lt;br /&gt;
&lt;br /&gt;
We must always keep in mind the fact that the receiver is the one who knows how to perform the operations needed, the purpose of the command being to help the client to delegate its request quickly and to make sure the command ends up where it should.&lt;br /&gt;
&lt;br /&gt;
One example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class FileDeleteCommand&lt;br /&gt;
   def initialize(path)&lt;br /&gt;
     @path = path&lt;br /&gt;
   end&lt;br /&gt;
   def execute&lt;br /&gt;
     File.delete(@path)&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 fdc = FileDeleteCommand.new('foo.dat')&lt;br /&gt;
 fdc.execute&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
there is nothing simpler than just getting on with it:&lt;br /&gt;
File.delete('foo.dat')&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69176</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69176"/>
		<updated>2012-10-28T02:09:44Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses classes and their methods in an object-oriented language. Developers often start thinking about design after learning a programming language and writing code for a while. You might notice that someone else’s code seems simpler and works better than yours does, and you might wonder how that developer achieves such simplicity. Design patterns are a level up from code and typically show how to achieve a goal using a few classes. A pattern represents an idea, not a particular implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Intent !! Patterns&lt;br /&gt;
|-&lt;br /&gt;
| Interfaces || ADAPTER, FACADE, COMPOSITE, BRIDGE&lt;br /&gt;
|-&lt;br /&gt;
| Responsibility || SINGLETON, OBSERVER, MEDIATOR, PROXY, CHAIN OF RESPONSIBILITY, FLYWEIGHT&lt;br /&gt;
|-&lt;br /&gt;
| Construction || BUILDER, FACTORY METHOD, ABSTRACT FACTORY, PROTOTYPE, MEMENTO&lt;br /&gt;
|-&lt;br /&gt;
| Operations|| TEMPLATE METHOD, STATE, STRATEGY, COMMAND, INTERPRETER&lt;br /&gt;
|-&lt;br /&gt;
| Extensions || DECORATOR, ITERATOR, VISITOR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
Design patterns provide a way of encapsulating the experience of software developers in a form that can be communicated to other developers. They provide a higher level of abstraction than single classes and objects thus providing bigger building blocks in the construction of software designs. &lt;br /&gt;
&lt;br /&gt;
The main benefits of design patterns are:&lt;br /&gt;
&lt;br /&gt;
*They encapsulate and codify design experience.&lt;br /&gt;
*Provide a common vocabulary for software designers to use when communicating with their peers.&lt;br /&gt;
*Enhance maintainability of software systems whose designs are documented with patterns.&lt;br /&gt;
*Provide robustness to the design by copying or imitating proven design techniques.&lt;br /&gt;
*Reuse at the design level.&lt;br /&gt;
&lt;br /&gt;
At first glance some of these benefits may not seem very powerful, but upon further inspection maybe we can gain new insight into the true nature of their value. Let us just consider the fact that we have given a design pattern a common name. We can now communicate an entire design principle or concept with other software developers by just using the simple name of the pattern. In one fell swoop we have drastically reduced the effort and time needed for a developer to discuss a concept with another developer. Taken one step further we can discuss the patterns and their interactions in the system and illustrate the system architecture in few sentences. Grouping design concepts with common names facilitates communication among developers and raises the conversation to a higher level of abstraction.&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
There are four primary symptoms that tell us that our designs are rotting. They are not orthogonal, but are related to each other in ways that will become obvious. &lt;br /&gt;
&lt;br /&gt;
The four symptoms are:&lt;br /&gt;
*Rigidity -- the tendency for software to be difficult to change, even in simple ways.&lt;br /&gt;
*Fragility -- the tendency of the software to break in many places every time it is changed. &lt;br /&gt;
*Immobility -- the inability to reuse software from other projects or from parts of the same project.&lt;br /&gt;
*Viscosity -- viscosity comes in two forms: viscosity of the design, and viscosity of the environment.&lt;br /&gt;
&lt;br /&gt;
In following passage of this wiki page, we will discuss over 'Fragility' with some examples.&lt;br /&gt;
&lt;br /&gt;
== Definition of Pattern Fragility ==&lt;br /&gt;
Fragility is the tendency of the &lt;br /&gt;
software to break in many places every time it is changed. Often the breakage occurs &lt;br /&gt;
in areas that have no conceptual relationship with the area that was changed. Such &lt;br /&gt;
errors fill the hearts of managers with foreboding. Every time they authorize a fix, &lt;br /&gt;
they fear that the software will break in some unexpected way.&lt;br /&gt;
As the fragility becomes worse, the probability of breakage increases with time, &lt;br /&gt;
asymptotically approaching 1. Such software is impossible to maintain. Every fix &lt;br /&gt;
makes it worse, introducing more problems than are solved.&lt;br /&gt;
Such software causes managers and customers to suspect that the developers have lost &lt;br /&gt;
control of their software. Distrust reigns, and credibility is lost.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton -- the most overused pattern ===&lt;br /&gt;
&lt;br /&gt;
Sometimes it's important to have only one instance for a class. For example, in a system there should be only one window manager (or only a file system). Usually singletons are used for centralized management of internal or external resources and they provide a global point of access to themselves. The primary purpose of the singleton is to guarantee that at anytime there is only one instance for a given class and provide a global reference to it.&lt;br /&gt;
&lt;br /&gt;
The singleton pattern is one of the simplest design patterns: it involves only one class which is responsible to instantiate itself, to make sure it creates not more than one instance; in the same time it provides a global point of access to that instance. In this case the same instance can be used from everywhere, being impossible to invoke directly the constructor each time.&lt;br /&gt;
&lt;br /&gt;
Well, the question is, is it safe to use a singleton class when it might be very tempting to do so? Obviously, the answer is negative. There is a general misconception about how Singletons should be used. Possibly, because it is true, that for having global state, it is better using Singletons, than just plainly global variables or class objects.&lt;br /&gt;
&lt;br /&gt;
Some people see the Singleton as a justification for global state, along the lines of &amp;quot;If there's a pattern for it, it must be good&amp;quot;. Well no, it isn’t. Global state is considered harmful. For a number of reasons, that even Singleton-misuse won't make go away, simply because: '''Singletons are NOT intended to provide global state!'''&lt;br /&gt;
&lt;br /&gt;
The Singleton is a creational pattern. It is used to enforce, that a class be instantiated only once. What it basically does is, to give control over instantiation back to the programmer. This is what you sometimes need in languages with classical constructors (Java, C++ and such).&lt;br /&gt;
&lt;br /&gt;
=== Factory ===&lt;br /&gt;
Create an interface for building an object, but let subclasses decide which class to instantiate. It allows a class to defer instantiation of subclasses.&lt;br /&gt;
Factory pattern is one of the patterns that have being heavily abused. With as long as if --- else, go to the factory model, as long as the object involved in the creation of selective, go to the factory model. Factory pattern seems to have become the panacea to solve all.&lt;br /&gt;
But let us look at some of the above contrast with the factory pattern, you simple code it? Wrong! The contrary, no increase in the scalability of the code at the same time, it increased the number of types of calls, an increase of the number of categories. This is not what we want to see!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When to use a Factory Pattern?&lt;br /&gt;
The Factory patterns can be used in following cases:&lt;br /&gt;
1. When a class does not know which class of objects it must create.&lt;br /&gt;
2. A class specifies its sub-classes to specify which objects to create.&lt;br /&gt;
3. In programmer’s language (very raw form), you can use factory pattern where you have to create an object of any one of sub-classes depending on the data provided.&lt;br /&gt;
&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
Visitor pattern represent an operation to be performed on the elements of an object structure. In GoF's word, &amp;quot;It let you define a new operation changing the classes of the elements on which it operates.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Command ===&lt;br /&gt;
The Command design pattern encapsulates commands (method calls) in objects allowing us to issue requests without knowing the requested operation or the requesting object. Command design pattern provides the options to queue commands, undo/redo actions and other manipulations.&lt;br /&gt;
&lt;br /&gt;
There are two extremes that a programmer must avoid when using this pattern: &lt;br /&gt;
&lt;br /&gt;
1. The command is just a link between the receiver and the actions that carry out the request&lt;br /&gt;
2. The command implements everything itself, without sending anything to the receiver.&lt;br /&gt;
&lt;br /&gt;
We must always keep in mind the fact that the receiver is the one who knows how to perform the operations needed, the purpose of the command being to help the client to delegate its request quickly and to make sure the command ends up where it should.&lt;br /&gt;
&lt;br /&gt;
One example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class FileDeleteCommand&lt;br /&gt;
   def initialize(path)&lt;br /&gt;
     @path = path&lt;br /&gt;
   end&lt;br /&gt;
   def execute&lt;br /&gt;
     File.delete(@path)&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 fdc = FileDeleteCommand.new('foo.dat')&lt;br /&gt;
 fdc.execute&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
there is nothing simpler than just getting on with it:&lt;br /&gt;
File.delete('foo.dat')&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69175</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=69175"/>
		<updated>2012-10-28T01:38:27Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses classes and their methods in an object-oriented language. Developers often start thinking about design after learning a programming language and writing code for a while. You might notice that someone else’s code seems simpler and works better than yours does, and you might wonder how that developer achieves such simplicity. Design patterns are a level up from code and typically show how to achieve a goal using a few classes. A pattern represents an idea, not a particular implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Intent !! Patterns&lt;br /&gt;
|-&lt;br /&gt;
| Interfaces || ADAPTER, FACADE, COMPOSITE, BRIDGE&lt;br /&gt;
|-&lt;br /&gt;
| Responsibility || SINGLETON, OBSERVER, MEDIATOR, PROXY, CHAIN OF RESPONSIBILITY, FLYWEIGHT&lt;br /&gt;
|-&lt;br /&gt;
| Construction || BUILDER, FACTORY METHOD, ABSTRACT FACTORY, PROTOTYPE, MEMENTO&lt;br /&gt;
|-&lt;br /&gt;
| Operations|| TEMPLATE METHOD, STATE, STRATEGY, COMMAND, INTERPRETER&lt;br /&gt;
|-&lt;br /&gt;
| Extensions || DECORATOR, ITERATOR, VISITOR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
Design patterns provide a way of encapsulating the experience of software developers in a form that can be communicated to other developers. They provide a higher level of abstraction than single classes and objects thus providing bigger building blocks in the construction of software designs. &lt;br /&gt;
&lt;br /&gt;
The main benefits of design patterns are:&lt;br /&gt;
&lt;br /&gt;
*They encapsulate and codify design experience.&lt;br /&gt;
*Provide a common vocabulary for software designers to use when communicating with their peers.&lt;br /&gt;
*Enhance maintainability of software systems whose designs are documented with patterns.&lt;br /&gt;
*Provide robustness to the design by copying or imitating proven design techniques.&lt;br /&gt;
*Reuse at the design level.&lt;br /&gt;
&lt;br /&gt;
At first glance some of these benefits may not seem very powerful, but upon further inspection maybe we can gain new insight into the true nature of their value. Let us just consider the fact that we have given a design pattern a common name. We can now communicate an entire design principle or concept with other software developers by just using the simple name of the pattern. In one fell swoop we have drastically reduced the effort and time needed for a developer to discuss a concept with another developer. Taken one step further we can discuss the patterns and their interactions in the system and illustrate the system architecture in few sentences. Grouping design concepts with common names facilitates communication among developers and raises the conversation to a higher level of abstraction.&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
There are four primary symptoms that tell us that our designs are rotting. They are not orthogonal, but are related to each other in ways that will become obvious. &lt;br /&gt;
&lt;br /&gt;
The four symptoms are:&lt;br /&gt;
*Rigidity -- the tendency for software to be difficult to change, even in simple ways.&lt;br /&gt;
*Fragility -- the tendency of the software to break in many places every time it is changed. &lt;br /&gt;
*Immobility -- the inability to reuse software from other projects or from parts of the same project.&lt;br /&gt;
*Viscosity -- viscosity comes in two forms: viscosity of the design, and viscosity of the environment.&lt;br /&gt;
&lt;br /&gt;
In following passage of this wiki page, we will discuss over 'Fragility' with some examples.&lt;br /&gt;
&lt;br /&gt;
== Definition of Pattern Fragility ==&lt;br /&gt;
Fragility is the tendency of the &lt;br /&gt;
software to break in many places every time it is changed. Often the breakage occurs &lt;br /&gt;
in areas that have no conceptual relationship with the area that was changed. Such &lt;br /&gt;
errors fill the hearts of managers with foreboding. Every time they authorize a fix, &lt;br /&gt;
they fear that the software will break in some unexpected way.&lt;br /&gt;
As the fragility becomes worse, the probability of breakage increases with time, &lt;br /&gt;
asymptotically approaching 1. Such software is impossible to maintain. Every fix &lt;br /&gt;
makes it worse, introducing more problems than are solved.&lt;br /&gt;
Such software causes managers and customers to suspect that the developers have lost &lt;br /&gt;
control of their software. Distrust reigns, and credibility is lost.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton -- the most overused pattern ===&lt;br /&gt;
&lt;br /&gt;
Sometimes it's important to have only one instance for a class. For example, in a system there should be only one window manager (or only a file system). Usually singletons are used for centralized management of internal or external resources and they provide a global point of access to themselves. The primary purpose of the singleton is to guarantee that at anytime there is only one instance for a given class and provide a global reference to it.&lt;br /&gt;
&lt;br /&gt;
The singleton pattern is one of the simplest design patterns: it involves only one class which is responsible to instantiate itself, to make sure it creates not more than one instance; in the same time it provides a global point of access to that instance. In this case the same instance can be used from everywhere, being impossible to invoke directly the constructor each time.&lt;br /&gt;
&lt;br /&gt;
Well, the question is, is it safe to use a singleton class when it might be very tempting to do so? Obviously, the answer is negative. There is a general misconception about how Singletons should be used. Possibly, because it is true, that for having global state, it is better using Singletons, than just plainly global variables or class objects.&lt;br /&gt;
&lt;br /&gt;
Some people see the Singleton as a justification for global state, along the lines of &amp;quot;If there's a pattern for it, it must be good&amp;quot;. Well no, it isn’t. Global state is considered harmful. For a number of reasons, that even Singleton-misuse won't make go away, simply because: '''Singletons are NOT intended to provide global state!'''&lt;br /&gt;
&lt;br /&gt;
The Singleton is a creational pattern. It is used to enforce, that a class be instantiated only once. What it basically does is, to give control over instantiation back to the programmer. This is what you sometimes need in languages with classical constructors (Java, C++ and such).&lt;br /&gt;
&lt;br /&gt;
=== Factory ===&lt;br /&gt;
Create an interface for building an object, but let subclasses decide which class to instantiate. It allows a class to defer instantiation of subclasses.&lt;br /&gt;
Factory pattern is one of the patterns that have being heavily abused. With as long as if --- else, go to the factory model, as long as the object involved in the creation of selective, go to the factory model. Factory pattern seems to have become the panacea to solve all.&lt;br /&gt;
But let us look at some of the above contrast with the factory pattern, you simple code it? Wrong! The contrary, no increase in the scalability of the code at the same time, it increased the number of types of calls, an increase of the number of categories. This is not what we want to see!&lt;br /&gt;
&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
Visitor pattern represent an operation to be performed on the elements of an object structure. In GoF's word, &amp;quot;It let you define a new operation changing the classes of the elements on which it operates.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Command ===&lt;br /&gt;
The Command design pattern encapsulates commands (method calls) in objects allowing us to issue requests without knowing the requested operation or the requesting object. Command design pattern provides the options to queue commands, undo/redo actions and other manipulations.&lt;br /&gt;
&lt;br /&gt;
There are two extremes that a programmer must avoid when using this pattern: &lt;br /&gt;
&lt;br /&gt;
1. The command is just a link between the receiver and the actions that carry out the request&lt;br /&gt;
2. The command implements everything itself, without sending anything to the receiver.&lt;br /&gt;
&lt;br /&gt;
We must always keep in mind the fact that the receiver is the one who knows how to perform the operations needed, the purpose of the command being to help the client to delegate its request quickly and to make sure the command ends up where it should.&lt;br /&gt;
&lt;br /&gt;
One example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class FileDeleteCommand&lt;br /&gt;
   def initialize(path)&lt;br /&gt;
     @path = path&lt;br /&gt;
   end&lt;br /&gt;
   def execute&lt;br /&gt;
     File.delete(@path)&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 fdc = FileDeleteCommand.new('foo.dat')&lt;br /&gt;
 fdc.execute&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
there is nothing simpler than just getting on with it:&lt;br /&gt;
File.delete('foo.dat')&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68131</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68131"/>
		<updated>2012-10-24T21:40:27Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Command */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses&lt;br /&gt;
classes and their methods in an object-oriented language. Developers&lt;br /&gt;
often start thinking about design after learning a programming language&lt;br /&gt;
and writing code for a while. You might notice that someone&lt;br /&gt;
else’s code seems simpler and works better than yours does, and you&lt;br /&gt;
might wonder how that developer achieves such simplicity. Design&lt;br /&gt;
patterns are a level up from code and typically show how to achieve a&lt;br /&gt;
goal using a few classes. A pattern represents an idea, not a particular&lt;br /&gt;
implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Intent !! Patterns&lt;br /&gt;
|-&lt;br /&gt;
| Interfaces || ADAPTER, FACADE, COMPOSITE, BRIDGE&lt;br /&gt;
|-&lt;br /&gt;
| Responsibility || SINGLETON, OBSERVER, MEDIATOR, PROXY, CHAIN OF RESPONSIBILITY, FLYWEIGHT&lt;br /&gt;
|-&lt;br /&gt;
| Construction || BUILDER, FACTORY METHOD, ABSTRACT FACTORY, PROTOTYPE, MEMENTO&lt;br /&gt;
|-&lt;br /&gt;
| Operations|| TEMPLATE METHOD, STATE, STRATEGY, COMMAND, INTERPRETER&lt;br /&gt;
|-&lt;br /&gt;
| Extensions || DECORATOR, ITERATOR, VISITOR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== Definition of Pattern Fragility ==&lt;br /&gt;
Fragility is the tendency of the &lt;br /&gt;
software to break in many places every time it is changed. Often the breakage occurs &lt;br /&gt;
in areas that have no conceptual relationship with the area that was changed. Such &lt;br /&gt;
errors fill the hearts of managers with foreboding. Every time they authorize a fix, &lt;br /&gt;
they fear that the software will break in some unexpected way.&lt;br /&gt;
As the fragility becomes worse, the probability of breakage increases with time, &lt;br /&gt;
asymptotically approaching 1. Such software is impossible to maintain. Every fix &lt;br /&gt;
makes it worse, introducing more problems than are solved.&lt;br /&gt;
Such software causes managers and customers to suspect that the developers have lost &lt;br /&gt;
control of their software. Distrust reigns, and credibility is lost.&lt;br /&gt;
&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
There are four primary symptoms that tell us that our designs are rotting. They are not &lt;br /&gt;
orthogonal, but are related to each other in ways that will become obvious. they are: &lt;br /&gt;
rigidity, fragility, immobility, and viscosity&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton ===&lt;br /&gt;
=== Factory ===&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
=== Command ===&lt;br /&gt;
There are two extremes that a programmer must avoid when using this pattern: &lt;br /&gt;
&lt;br /&gt;
1. The command is just a link between the receiver and the actions that carry out the request&lt;br /&gt;
2. The command implements everything itself, without sending anything to the receiver.&lt;br /&gt;
&lt;br /&gt;
We must always keep in mind the fact that the receiver is the one who knows how to perform the operations needed, the purpose of the command being to help the client to delegate its request quickly and to make sure the command ends up where it should.&lt;br /&gt;
&lt;br /&gt;
One example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class FileDeleteCommand&lt;br /&gt;
   def initialize(path)&lt;br /&gt;
     @path = path&lt;br /&gt;
   end&lt;br /&gt;
   def execute&lt;br /&gt;
     File.delete(@path)&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 fdc = FileDeleteCommand.new('foo.dat')&lt;br /&gt;
 fdc.execute&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
there is nothing simpler than just getting on with it:&lt;br /&gt;
File.delete('foo.dat')&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68130</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68130"/>
		<updated>2012-10-24T21:39:19Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Command */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses&lt;br /&gt;
classes and their methods in an object-oriented language. Developers&lt;br /&gt;
often start thinking about design after learning a programming language&lt;br /&gt;
and writing code for a while. You might notice that someone&lt;br /&gt;
else’s code seems simpler and works better than yours does, and you&lt;br /&gt;
might wonder how that developer achieves such simplicity. Design&lt;br /&gt;
patterns are a level up from code and typically show how to achieve a&lt;br /&gt;
goal using a few classes. A pattern represents an idea, not a particular&lt;br /&gt;
implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Intent !! Patterns&lt;br /&gt;
|-&lt;br /&gt;
| Interfaces || ADAPTER, FACADE, COMPOSITE, BRIDGE&lt;br /&gt;
|-&lt;br /&gt;
| Responsibility || SINGLETON, OBSERVER, MEDIATOR, PROXY, CHAIN OF RESPONSIBILITY, FLYWEIGHT&lt;br /&gt;
|-&lt;br /&gt;
| Construction || BUILDER, FACTORY METHOD, ABSTRACT FACTORY, PROTOTYPE, MEMENTO&lt;br /&gt;
|-&lt;br /&gt;
| Operations|| TEMPLATE METHOD, STATE, STRATEGY, COMMAND, INTERPRETER&lt;br /&gt;
|-&lt;br /&gt;
| Extensions || DECORATOR, ITERATOR, VISITOR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== Definition of Pattern Fragility ==&lt;br /&gt;
Fragility is the tendency of the &lt;br /&gt;
software to break in many places every time it is changed. Often the breakage occurs &lt;br /&gt;
in areas that have no conceptual relationship with the area that was changed. Such &lt;br /&gt;
errors fill the hearts of managers with foreboding. Every time they authorize a fix, &lt;br /&gt;
they fear that the software will break in some unexpected way.&lt;br /&gt;
As the fragility becomes worse, the probability of breakage increases with time, &lt;br /&gt;
asymptotically approaching 1. Such software is impossible to maintain. Every fix &lt;br /&gt;
makes it worse, introducing more problems than are solved.&lt;br /&gt;
Such software causes managers and customers to suspect that the developers have lost &lt;br /&gt;
control of their software. Distrust reigns, and credibility is lost.&lt;br /&gt;
&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
There are four primary symptoms that tell us that our designs are rotting. They are not &lt;br /&gt;
orthogonal, but are related to each other in ways that will become obvious. they are: &lt;br /&gt;
rigidity, fragility, immobility, and viscosity&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton ===&lt;br /&gt;
=== Factory ===&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
=== Command ===&lt;br /&gt;
There are two extremes that a programmer must avoid when using this pattern: &lt;br /&gt;
&lt;br /&gt;
1. The command is just a link between the receiver and the actions that carry out the request&lt;br /&gt;
2. The command implements everything itself, without sending anything to the receiver.&lt;br /&gt;
&lt;br /&gt;
We must always keep in mind the fact that the receiver is the one who knows how to perform the operations needed, the purpose of the command being to help the client to delegate its request quickly and to make sure the command ends up where it should.&lt;br /&gt;
&lt;br /&gt;
One example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:class FileDeleteCommand&lt;br /&gt;
::def initialize(path)&lt;br /&gt;
:::@path = path&lt;br /&gt;
::end&lt;br /&gt;
::def execute&lt;br /&gt;
:::File.delete(@path)&lt;br /&gt;
::end&lt;br /&gt;
:end&lt;br /&gt;
:fdc = FileDeleteCommand.new('foo.dat')&lt;br /&gt;
:fdc.execute&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
there is nothing simpler than just getting on with it:&lt;br /&gt;
File.delete('foo.dat')&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68129</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68129"/>
		<updated>2012-10-24T21:37:47Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Command */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses&lt;br /&gt;
classes and their methods in an object-oriented language. Developers&lt;br /&gt;
often start thinking about design after learning a programming language&lt;br /&gt;
and writing code for a while. You might notice that someone&lt;br /&gt;
else’s code seems simpler and works better than yours does, and you&lt;br /&gt;
might wonder how that developer achieves such simplicity. Design&lt;br /&gt;
patterns are a level up from code and typically show how to achieve a&lt;br /&gt;
goal using a few classes. A pattern represents an idea, not a particular&lt;br /&gt;
implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Intent !! Patterns&lt;br /&gt;
|-&lt;br /&gt;
| Interfaces || ADAPTER, FACADE, COMPOSITE, BRIDGE&lt;br /&gt;
|-&lt;br /&gt;
| Responsibility || SINGLETON, OBSERVER, MEDIATOR, PROXY, CHAIN OF RESPONSIBILITY, FLYWEIGHT&lt;br /&gt;
|-&lt;br /&gt;
| Construction || BUILDER, FACTORY METHOD, ABSTRACT FACTORY, PROTOTYPE, MEMENTO&lt;br /&gt;
|-&lt;br /&gt;
| Operations|| TEMPLATE METHOD, STATE, STRATEGY, COMMAND, INTERPRETER&lt;br /&gt;
|-&lt;br /&gt;
| Extensions || DECORATOR, ITERATOR, VISITOR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== Definition of Pattern Fragility ==&lt;br /&gt;
Fragility is the tendency of the &lt;br /&gt;
software to break in many places every time it is changed. Often the breakage occurs &lt;br /&gt;
in areas that have no conceptual relationship with the area that was changed. Such &lt;br /&gt;
errors fill the hearts of managers with foreboding. Every time they authorize a fix, &lt;br /&gt;
they fear that the software will break in some unexpected way.&lt;br /&gt;
As the fragility becomes worse, the probability of breakage increases with time, &lt;br /&gt;
asymptotically approaching 1. Such software is impossible to maintain. Every fix &lt;br /&gt;
makes it worse, introducing more problems than are solved.&lt;br /&gt;
Such software causes managers and customers to suspect that the developers have lost &lt;br /&gt;
control of their software. Distrust reigns, and credibility is lost.&lt;br /&gt;
&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
There are four primary symptoms that tell us that our designs are rotting. They are not &lt;br /&gt;
orthogonal, but are related to each other in ways that will become obvious. they are: &lt;br /&gt;
rigidity, fragility, immobility, and viscosity&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton ===&lt;br /&gt;
=== Factory ===&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
=== Command ===&lt;br /&gt;
There are two extremes that a programmer must avoid when using this pattern: &lt;br /&gt;
&lt;br /&gt;
1. The command is just a link between the receiver and the actions that carry out the request&lt;br /&gt;
2. The command implements everything itself, without sending anything to the receiver.&lt;br /&gt;
&lt;br /&gt;
We must always keep in mind the fact that the receiver is the one who knows how to perform the operations needed, the purpose of the command being to help the client to delegate its request quickly and to make sure the command ends up where it should.&lt;br /&gt;
&lt;br /&gt;
One example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class FileDeleteCommand&lt;br /&gt;
def initialize(path)&lt;br /&gt;
@path = path&lt;br /&gt;
end&lt;br /&gt;
def execute&lt;br /&gt;
File.delete(@path)&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
fdc = FileDeleteCommand.new('foo.dat')&lt;br /&gt;
fdc.execute&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
there is nothing simpler than just getting on with it:&lt;br /&gt;
File.delete('foo.dat')&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68126</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68126"/>
		<updated>2012-10-24T21:14:14Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Categorization of Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses&lt;br /&gt;
classes and their methods in an object-oriented language. Developers&lt;br /&gt;
often start thinking about design after learning a programming language&lt;br /&gt;
and writing code for a while. You might notice that someone&lt;br /&gt;
else’s code seems simpler and works better than yours does, and you&lt;br /&gt;
might wonder how that developer achieves such simplicity. Design&lt;br /&gt;
patterns are a level up from code and typically show how to achieve a&lt;br /&gt;
goal using a few classes. A pattern represents an idea, not a particular&lt;br /&gt;
implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Intent !! Patterns&lt;br /&gt;
|-&lt;br /&gt;
| Interfaces || ADAPTER, FACADE, COMPOSITE, BRIDGE&lt;br /&gt;
|-&lt;br /&gt;
| Responsibility || SINGLETON, OBSERVER, MEDIATOR, PROXY, CHAIN OF RESPONSIBILITY, FLYWEIGHT&lt;br /&gt;
|-&lt;br /&gt;
| Construction || BUILDER, FACTORY METHOD, ABSTRACT FACTORY, PROTOTYPE, MEMENTO&lt;br /&gt;
|-&lt;br /&gt;
| Operations|| TEMPLATE METHOD, STATE, STRATEGY, COMMAND, INTERPRETER&lt;br /&gt;
|-&lt;br /&gt;
| Extensions || DECORATOR, ITERATOR, VISITOR&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== Definition of Pattern Fragility ==&lt;br /&gt;
Fragility is the tendency of the &lt;br /&gt;
software to break in many places every time it is changed. Often the breakage occurs &lt;br /&gt;
in areas that have no conceptual relationship with the area that was changed. Such &lt;br /&gt;
errors fill the hearts of managers with foreboding. Every time they authorize a fix, &lt;br /&gt;
they fear that the software will break in some unexpected way.&lt;br /&gt;
As the fragility becomes worse, the probability of breakage increases with time, &lt;br /&gt;
asymptotically approaching 1. Such software is impossible to maintain. Every fix &lt;br /&gt;
makes it worse, introducing more problems than are solved.&lt;br /&gt;
Such software causes managers and customers to suspect that the developers have lost &lt;br /&gt;
control of their software. Distrust reigns, and credibility is lost.&lt;br /&gt;
&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
There are four primary symptoms that tell us that our designs are rotting. They are not &lt;br /&gt;
orthogonal, but are related to each other in ways that will become obvious. they are: &lt;br /&gt;
rigidity, fragility, immobility, and viscosity&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton ===&lt;br /&gt;
=== Factory ===&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
=== Command ===&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68125</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68125"/>
		<updated>2012-10-24T21:07:25Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Categorization of Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses&lt;br /&gt;
classes and their methods in an object-oriented language. Developers&lt;br /&gt;
often start thinking about design after learning a programming language&lt;br /&gt;
and writing code for a while. You might notice that someone&lt;br /&gt;
else’s code seems simpler and works better than yours does, and you&lt;br /&gt;
might wonder how that developer achieves such simplicity. Design&lt;br /&gt;
patterns are a level up from code and typically show how to achieve a&lt;br /&gt;
goal using a few classes. A pattern represents an idea, not a particular&lt;br /&gt;
implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
[[File:Category.jpg]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Header text !! Header text !! Header text&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== Definition of Pattern Fragility ==&lt;br /&gt;
Fragility is the tendency of the &lt;br /&gt;
software to break in many places every time it is changed. Often the breakage occurs &lt;br /&gt;
in areas that have no conceptual relationship with the area that was changed. Such &lt;br /&gt;
errors fill the hearts of managers with foreboding. Every time they authorize a fix, &lt;br /&gt;
they fear that the software will break in some unexpected way.&lt;br /&gt;
As the fragility becomes worse, the probability of breakage increases with time, &lt;br /&gt;
asymptotically approaching 1. Such software is impossible to maintain. Every fix &lt;br /&gt;
makes it worse, introducing more problems than are solved.&lt;br /&gt;
Such software causes managers and customers to suspect that the developers have lost &lt;br /&gt;
control of their software. Distrust reigns, and credibility is lost.&lt;br /&gt;
&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
There are four primary symptoms that tell us that our designs are rotting. They are not &lt;br /&gt;
orthogonal, but are related to each other in ways that will become obvious. they are: &lt;br /&gt;
rigidity, fragility, immobility, and viscosity&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton ===&lt;br /&gt;
=== Factory ===&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
=== Command ===&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68123</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68123"/>
		<updated>2012-10-24T21:00:27Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Symptoms of Rotting Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses&lt;br /&gt;
classes and their methods in an object-oriented language. Developers&lt;br /&gt;
often start thinking about design after learning a programming language&lt;br /&gt;
and writing code for a while. You might notice that someone&lt;br /&gt;
else’s code seems simpler and works better than yours does, and you&lt;br /&gt;
might wonder how that developer achieves such simplicity. Design&lt;br /&gt;
patterns are a level up from code and typically show how to achieve a&lt;br /&gt;
goal using a few classes. A pattern represents an idea, not a particular&lt;br /&gt;
implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
[[File:Category.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== Definition of Pattern Fragility ==&lt;br /&gt;
Fragility is the tendency of the &lt;br /&gt;
software to break in many places every time it is changed. Often the breakage occurs &lt;br /&gt;
in areas that have no conceptual relationship with the area that was changed. Such &lt;br /&gt;
errors fill the hearts of managers with foreboding. Every time they authorize a fix, &lt;br /&gt;
they fear that the software will break in some unexpected way.&lt;br /&gt;
As the fragility becomes worse, the probability of breakage increases with time, &lt;br /&gt;
asymptotically approaching 1. Such software is impossible to maintain. Every fix &lt;br /&gt;
makes it worse, introducing more problems than are solved.&lt;br /&gt;
Such software causes managers and customers to suspect that the developers have lost &lt;br /&gt;
control of their software. Distrust reigns, and credibility is lost.&lt;br /&gt;
&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
There are four primary symptoms that tell us that our designs are rotting. They are not &lt;br /&gt;
orthogonal, but are related to each other in ways that will become obvious. they are: &lt;br /&gt;
rigidity, fragility, immobility, and viscosity&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton ===&lt;br /&gt;
=== Factory ===&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68122</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68122"/>
		<updated>2012-10-24T20:59:10Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* What is Pattern Fragility */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses&lt;br /&gt;
classes and their methods in an object-oriented language. Developers&lt;br /&gt;
often start thinking about design after learning a programming language&lt;br /&gt;
and writing code for a while. You might notice that someone&lt;br /&gt;
else’s code seems simpler and works better than yours does, and you&lt;br /&gt;
might wonder how that developer achieves such simplicity. Design&lt;br /&gt;
patterns are a level up from code and typically show how to achieve a&lt;br /&gt;
goal using a few classes. A pattern represents an idea, not a particular&lt;br /&gt;
implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
[[File:Category.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== Definition of Pattern Fragility ==&lt;br /&gt;
Fragility is the tendency of the &lt;br /&gt;
software to break in many places every time it is changed. Often the breakage occurs &lt;br /&gt;
in areas that have no conceptual relationship with the area that was changed. Such &lt;br /&gt;
errors fill the hearts of managers with foreboding. Every time they authorize a fix, &lt;br /&gt;
they fear that the software will break in some unexpected way.&lt;br /&gt;
As the fragility becomes worse, the probability of breakage increases with time, &lt;br /&gt;
asymptotically approaching 1. Such software is impossible to maintain. Every fix &lt;br /&gt;
makes it worse, introducing more problems than are solved.&lt;br /&gt;
Such software causes managers and customers to suspect that the developers have lost &lt;br /&gt;
control of their software. Distrust reigns, and credibility is lost.&lt;br /&gt;
&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton ===&lt;br /&gt;
=== Factory ===&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68121</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68121"/>
		<updated>2012-10-24T20:57:58Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Categorization of Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses&lt;br /&gt;
classes and their methods in an object-oriented language. Developers&lt;br /&gt;
often start thinking about design after learning a programming language&lt;br /&gt;
and writing code for a while. You might notice that someone&lt;br /&gt;
else’s code seems simpler and works better than yours does, and you&lt;br /&gt;
might wonder how that developer achieves such simplicity. Design&lt;br /&gt;
patterns are a level up from code and typically show how to achieve a&lt;br /&gt;
goal using a few classes. A pattern represents an idea, not a particular&lt;br /&gt;
implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
[[File:Category.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== What is Pattern Fragility ==&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton ===&lt;br /&gt;
=== Factory ===&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Category.jpg&amp;diff=68120</id>
		<title>File:Category.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Category.jpg&amp;diff=68120"/>
		<updated>2012-10-24T20:57:22Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68119</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68119"/>
		<updated>2012-10-24T20:54:52Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Categorization of Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses&lt;br /&gt;
classes and their methods in an object-oriented language. Developers&lt;br /&gt;
often start thinking about design after learning a programming language&lt;br /&gt;
and writing code for a while. You might notice that someone&lt;br /&gt;
else’s code seems simpler and works better than yours does, and you&lt;br /&gt;
might wonder how that developer achieves such simplicity. Design&lt;br /&gt;
patterns are a level up from code and typically show how to achieve a&lt;br /&gt;
goal using a few classes. A pattern represents an idea, not a particular&lt;br /&gt;
implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
[[File:Example.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== What is Pattern Fragility ==&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton ===&lt;br /&gt;
=== Factory ===&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68118</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68118"/>
		<updated>2012-10-24T20:52:43Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Why Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses&lt;br /&gt;
classes and their methods in an object-oriented language. Developers&lt;br /&gt;
often start thinking about design after learning a programming language&lt;br /&gt;
and writing code for a while. You might notice that someone&lt;br /&gt;
else’s code seems simpler and works better than yours does, and you&lt;br /&gt;
might wonder how that developer achieves such simplicity. Design&lt;br /&gt;
patterns are a level up from code and typically show how to achieve a&lt;br /&gt;
goal using a few classes. A pattern represents an idea, not a particular&lt;br /&gt;
implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== What is Pattern Fragility ==&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton ===&lt;br /&gt;
=== Factory ===&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68117</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68117"/>
		<updated>2012-10-24T20:52:10Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Why Design Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Patterns ==&lt;br /&gt;
A pattern is a way of doing something: a way of pursuing an intent, a&lt;br /&gt;
technique. The idea of capturing effective techniques applies to many&lt;br /&gt;
endeavors: making food, fireworks, software, and other crafts. In any&lt;br /&gt;
new craft that is starting to mature, the people working on it will&lt;br /&gt;
begin to find common, effective methods for achieving their aims&lt;br /&gt;
and solving problems in various contexts. The community of people&lt;br /&gt;
who practice a craft usually invent jargon that helps them talk about&lt;br /&gt;
their craft. Some of this jargon will refer to patterns, or established&lt;br /&gt;
techniques for achieving certain aims. As a craft and its jargon grows,&lt;br /&gt;
writers begin to play an important role. Writers document a craft’s&lt;br /&gt;
patterns, helping to standardize the jargon and to publicize effective&lt;br /&gt;
techniques.&lt;br /&gt;
&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
A design pattern is a pattern—a way to pursue an intent—that uses&lt;br /&gt;
classes and their methods in an object-oriented language. Developers&lt;br /&gt;
often start thinking about design after learning a programming language&lt;br /&gt;
and writing code for a while. You might notice that someone&lt;br /&gt;
else’s code seems simpler and works better than yours does, and you&lt;br /&gt;
might wonder how that developer achieves such simplicity. Design&lt;br /&gt;
patterns are a level up from code and typically show how to achieve a&lt;br /&gt;
goal using a few classes. A pattern represents an idea, not a particular&lt;br /&gt;
implementation.&lt;br /&gt;
&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== What is Pattern Fragility ==&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton ===&lt;br /&gt;
=== Factory ===&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68116</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68116"/>
		<updated>2012-10-24T20:51:49Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Why Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Patterns ==&lt;br /&gt;
A pattern is a way of doing something: a way of pursuing an intent, a&lt;br /&gt;
technique. The idea of capturing effective techniques applies to many&lt;br /&gt;
endeavors: making food, fireworks, software, and other crafts. In any&lt;br /&gt;
new craft that is starting to mature, the people working on it will&lt;br /&gt;
begin to find common, effective methods for achieving their aims&lt;br /&gt;
and solving problems in various contexts. The community of people&lt;br /&gt;
who practice a craft usually invent jargon that helps them talk about&lt;br /&gt;
their craft. Some of this jargon will refer to patterns, or established&lt;br /&gt;
techniques for achieving certain aims. As a craft and its jargon grows,&lt;br /&gt;
writers begin to play an important role. Writers document a craft’s&lt;br /&gt;
patterns, helping to standardize the jargon and to publicize effective&lt;br /&gt;
techniques.&lt;br /&gt;
&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== What is Pattern Fragility ==&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton ===&lt;br /&gt;
=== Factory ===&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68115</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68115"/>
		<updated>2012-10-24T20:45:05Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Design Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable or treated as such.&lt;br /&gt;
== Why Patterns ==&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== What is Pattern Fragility ==&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton ===&lt;br /&gt;
=== Factory ===&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68114</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w14 bb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w14_bb&amp;diff=68114"/>
		<updated>2012-10-24T20:40:33Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The purpose of the wiki is to introduce and show some example about pattern fragility. The contents include definition of pattern fragility and what does the concept cover. We also give some examples of mistakes in code that spoil the benefits of design patterns.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
== Why Patterns ==&lt;br /&gt;
== Why Design Patterns ==&lt;br /&gt;
== Categorization of Patterns ==&lt;br /&gt;
== Benefits of Design Patterns ==&lt;br /&gt;
= Pattern Fragility =&lt;br /&gt;
== What is Pattern Fragility ==&lt;br /&gt;
== Symptoms of Rotting Design ==&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== Singleton ===&lt;br /&gt;
=== Factory ===&lt;br /&gt;
=== Visitor ===&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= Reference =&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63534</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w21 wi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63534"/>
		<updated>2012-09-11T03:27:13Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Primitive objects in object-oriented languages'''&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
In any programming language, the [http://en.wikipedia.org/wiki/Data_type data type] refers to the class of data which contains specific type or range of values. Data types are used along with variables used in the program. The data type tells us what kind of values the variable can store, what is the range of the values and how much space the values take in memory etc.&lt;br /&gt;
&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Primitive_data_type primitive data types] refer to the built-in data types which are supported by the programming language. Often 'data types' and 'primitive data types' are used interchangeably. But not all data types are primitive. Programming languages have some non-primitive data types or derived data types which are provided by the language by making use of its primitive data types.&lt;br /&gt;
&lt;br /&gt;
The common built-in data types or primitive data types are integers, floating point numbers, characters, strings and boolean.&lt;br /&gt;
* Integers - Integers represent the whole numbers which can be positive or negative or zero, e.g. 9999, 0, -25, etc. &lt;br /&gt;
* Floating point numbers - Floating point numbers represent the numbers which are fractions or contain floating-decimal points, e.g. -3.002, 2.5, 22.0, etc.&lt;br /&gt;
* Characters - Characters represent any single letter, number, space, punctuation mark, or symbol that can be typed on a computer, e.g. 'a', '9', ' ', '!' , '\n', etc.&lt;br /&gt;
* Strings - Strings represent the sequences of characters or simply any text, e.g. &amp;quot;Hello!&amp;quot;, &amp;quot;9 am to 6 pm&amp;quot;, etc. &lt;br /&gt;
* Booleans - Booleans represent the true or false values. Sometimes, instead of true and false, 1 and 0 are used to represent the boolean values.&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] languages provide support for primitive data types while some object-oriented programming languages provide support for primitive objects along with primitive types.&lt;br /&gt;
&lt;br /&gt;
== Definition ==&lt;br /&gt;
&lt;br /&gt;
Primitive objects refer to the objects of built-in classes which provide more functionality than the primitive types. Some object-oriented programming languages provide support for only primitive objects (i.e., in such languages all primitive types are objects).&lt;br /&gt;
&lt;br /&gt;
Different object-oriented programming languages implement these primitive data types and primitive objects in a different manner.&lt;br /&gt;
&lt;br /&gt;
== Primitive objects in different OO languages ==&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java], there are 8 primitive types: boolean, char, byte, short, int, long, float, and double. &amp;lt;ref&amp;gt;http://www.cafeaulait.org/course/week2/02.html Java's Primitive Data Types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each of these primitive types, Java provides [http://en.wikipedia.org/wiki/Primitive_wrapper_class wrapper classes] to create primitive objects which wrap the primitive data values. A wrapper  not only contains the primitive data value, but it also defines properties and methods that can be used to manipulate that data. In Java, the primitive values are not implicitly converted to primitive objects. Instead, methods are provided for doing explicit conversion.&lt;br /&gt;
The primitive objects are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack heap] in memory while the variables containing primitive values are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack stack].&amp;lt;ref&amp;gt;http://www.informit.com/articles/article.aspx?p=31755&amp;amp;seqNum=8 Stack and Heap memory&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class!! Size&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean || 1-bit&lt;br /&gt;
|-&lt;br /&gt;
| char || Character || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| byte || Byte || 8-bit&lt;br /&gt;
|-&lt;br /&gt;
| short || Short || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| int || Integer || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| long || Long || 64-bit&lt;br /&gt;
|-&lt;br /&gt;
| float || Float || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| double || Double || 64-bit&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 20;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I+II);            &lt;br /&gt;
    System.out.println(I.equals(II));    &lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    30&lt;br /&gt;
    false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find out if these wrapper classes are primitive or not, we can use the isPrimitive() method.&lt;br /&gt;
&lt;br /&gt;
    System.out.println(INTEGER.TYPE.isPrimitive());&lt;br /&gt;
    System.out.println(BOOLEAN.TYPE.isPrimitive());&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    true&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java, the comparison operations work in the same way on the primitive objects as well as any other class objects but different on the primitive types. The == operator when used on objects checks whether they refer to the same object but when used on variables of primitive types checks whether they contain the same value.&amp;lt;ref&amp;gt;http://leepoint.net/notes-java/data/expressions/22compareobjects.html Comparisons in Java&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 10;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I==II);            &lt;br /&gt;
    System.out.println(i==ii);&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    false&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29 C#] is a [http://en.wikipedia.org/wiki/Strong_typing strongly typed] language, where it is necessary to declare the data type of a variable and also be aware of the data type conversion. C# provides a significant number of primitive data types.&amp;lt;ref&amp;gt;http://condor.depaul.edu/sjost/ndp/notes/cs1/CSDatatypes.htm C# Primitive Datatypes&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.java2s.com/Tutorial/CSharp/0040__Data-Type/PrimitivesinC.htm Primitives in C#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type. For example:&lt;br /&gt;
 &lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        int x = 7;&lt;br /&gt;
        object o = x;&lt;br /&gt;
        System.Console.WriteLine(o.ToString());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Some data types (e.g. Decimal and String) can appear like primitives at first sight, but are actually not. So it is important to exercise caution before making such assumptions. To test whether a particular type is a primitive or not you can use the property Type.IsPrimitive.&lt;br /&gt;
&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;br /&gt;
    if (t.IsPrimitive)    // where t is the type&lt;br /&gt;
    {&lt;br /&gt;
        // Is Primitive&lt;br /&gt;
    } else if (t == typeof(Decimal))&lt;br /&gt;
    {&lt;br /&gt;
        // Is Decimal&lt;br /&gt;
    } else if (t == typeof(String))&lt;br /&gt;
    {&lt;br /&gt;
        // Is String&lt;br /&gt;
    } else&lt;br /&gt;
    {&lt;br /&gt;
        // Other type&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== JavaScript ===&lt;br /&gt;
&lt;br /&gt;
There are 5 primitive data types in [http://en.wikipedia.org/wiki/JavaScript JavaScript]: string, number, boolean, null and undefined. &amp;lt;ref&amp;gt;http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html JavaScript Data Types and Variables&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For string, number and boolean values, there are corresponding classes just like in Java to create primitive objects which wrap the primitive values. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class&lt;br /&gt;
|-&lt;br /&gt;
| string || String&lt;br /&gt;
|-&lt;br /&gt;
| number|| Number&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In JavaScript, the primitive value is implicitly converted to a primitive object whenever someone tries to access a property or invoke a method on the primitive value and the primitive object is used in place of the primitive value. Since the object contains properties and methods, the use of primitive value as an object succeeds. After the property is accessed or the method is processed, the primitive object is no longer needed and hence discarded. The same is true for the other primitive types and their corresponding primitive objects.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    var upperCaseString = &amp;quot;APPLE&amp;quot;;&lt;br /&gt;
    var lowerCaseString = upperCaseString.toLowerCase();  // assigns string &amp;quot;apple&amp;quot; to lowerCaseString &lt;br /&gt;
    var s = &amp;quot;Hello&amp;quot;&lt;br /&gt;
    var len = s.length;                                   // assigns value 5 to len&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
&lt;br /&gt;
Since [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] is a [http://www.jvoegele.com/software/langcomp.html pure object oriented] language, everything in Ruby is an object. Hence, all primitive types such as integers, floating point numbers, strings, are objects of a built-in class.&amp;lt;ref&amp;gt;http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Classes in Ruby&amp;lt;/ref&amp;gt; &lt;br /&gt;
All integers are primitive objects of either class [http://corelib.rubyonrails.org/classes/Fixnum.html Fixnum] or [http://corelib.rubyonrails.org/classes/Bignum.html Bignum]. A numeric literal with a decimal point and/or an exponent is a primitive object of [http://corelib.rubyonrails.org/classes/Float.html Float]. Single quoted literals and double quoted literals are primitive objects of [http://corelib.rubyonrails.org/classes/String.html String].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    puts 10.class&lt;br /&gt;
    puts 7.45.class&lt;br /&gt;
    puts 'hi'.class&lt;br /&gt;
    puts &amp;quot;hello&amp;quot;.class&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    Fixnum&lt;br /&gt;
    Float&lt;br /&gt;
    String&lt;br /&gt;
    String&lt;br /&gt;
&lt;br /&gt;
This indicates that 10 is converted into an object of type Fixnum, 7.45 is converted into an object of type Float, 'hi' and &amp;quot;hello&amp;quot; are both converted into an object of type String.&lt;br /&gt;
&lt;br /&gt;
Since all primitive types in Ruby are objects, we should be able to call methods of the Object class on them. Let us demonstrate the same for integer and float using the following example:&lt;br /&gt;
&lt;br /&gt;
    a=10&lt;br /&gt;
    puts a.to_f  &lt;br /&gt;
    b=20.5&lt;br /&gt;
    puts b.to_i&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    10.0&lt;br /&gt;
    20&lt;br /&gt;
&lt;br /&gt;
== Advantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
Advantages that use of primitive data type offers are as follows:&lt;br /&gt;
===Consistency===&lt;br /&gt;
Many ideas of Java originate in C and in C++, objects and primitive type also co-exist. When object-oriented constructs were grafted onto the C language, C’s data types remained as is. The motivation behind this is that Bjarne Stroustrup, C++’s designer, wanted to be as consistent as possible with the base C language, hoping to capitalize on programmers’ pre-C++ knowledge.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://www.research.ibm.com/people/a/alpert/ptch/ptch.html Primitive Types Considered Harmful&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Simplicity===&lt;br /&gt;
It is simple and intuitive to use primitive data type in basic utility.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
1. Recurring number in a loop.(C++)&lt;br /&gt;
&lt;br /&gt;
   for(int i=0;i&amp;lt;10;i++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Temp variables that record only one or two data.&lt;br /&gt;
&lt;br /&gt;
===Time performance===&lt;br /&gt;
Processing primitive data type operation would be faster than processing composite data type in most cases. There are several reasons result in this differences. &lt;br /&gt;
*Hardware processing discrepancy&lt;br /&gt;
Many primitive data operations (like integer addition) can be performed as a single machine instruction while processing of composite data type would be transformed to a combination of primitive data types. eg. Some processors offer specific instructions to process sequences of characters with a single instruction.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
[http://www.research.ibm.com/people/a/alpert/ptch/ptch.html  Difference in data fetching between primitive data and composite data in Java]&lt;br /&gt;
 &lt;br /&gt;
*Allocating and Garbage collection overhead for composite data type&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Performance_implications Garbage collection&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.ibm.com/developerworks/java/library/j-jtp01274/index.html Java theory and practice: Garbage collection and performance&amp;lt;/ref&amp;gt;&lt;br /&gt;
There are many initialization operations for composite data type that will generate high overheads for example boxing and unboxing, constructors and destructors.Composite data type like class will also have garbage collection overheads that may be beyond the control of the programmer and can sometimes lead to performance problems. For example, commonly used stop-the-world garbage collectors, which pause program execution at arbitrary times, may make garbage collection inappropriate for some [http://en.wikipedia.org/wiki/Embedded_system embedded systems], high-performance [http://en.wikipedia.org/wiki/Server_(computing)  server] software, and applications with [http://en.wikipedia.org/wiki/Real-time_computing real-time] needs.In the early days of Java technology, allocating objects got a high overheads. There were lots of articles advising developers to avoid creating temporary objects unnecessarily because allocation (and the corresponding garbage-collection overhead) was expensive. Although the costs have been greatly reduced nowadays. It still much slower than primitive data type which don’t have such troubles.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
     public void test1(){&lt;br /&gt;
        int a=1,b=1;&lt;br /&gt;
        long startTime1 = System.currentTimeMillis();&lt;br /&gt;
        for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
           a=a+b;&lt;br /&gt;
                        }&lt;br /&gt;
        long endTime1 = System.currentTimeMillis();&lt;br /&gt;
        System.out.println(endTime1-startTime1);&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
     public void test2(){&lt;br /&gt;
         Integer c=new Integer(1);&lt;br /&gt;
         Integer d=new Integer(1);&lt;br /&gt;
         long startTime2 = System.currentTimeMillis();&lt;br /&gt;
         for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
            c=c+d;&lt;br /&gt;
         }&lt;br /&gt;
         long endTime2 = System.currentTimeMillis();&lt;br /&gt;
         System.out.println(endTime2-startTime2)&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
Average execution time for test1 is: 1 mm&lt;br /&gt;
&lt;br /&gt;
Average execution time for test2 is: 702mm&lt;br /&gt;
&lt;br /&gt;
(test case number: 1000 times )&lt;br /&gt;
&lt;br /&gt;
===Space performance===&lt;br /&gt;
Composite data type will cost more memory space than primitive data type in general. The reason is not only for the overheads generated by constructors, destructors etc, but also the feature of data alignment. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding Data structure alignment&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of data alignment（C++）&lt;br /&gt;
     struct compose&lt;br /&gt;
     {&lt;br /&gt;
         char name;&lt;br /&gt;
         int a;&lt;br /&gt;
         int b;&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
We all know the size of char is 1 byte, the size of int is 4 bytes. But the size of the struct compose as shown above is 12 bytes but not 9 bytes.&lt;br /&gt;
&lt;br /&gt;
== Disdvantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
The various disadvantages of using the primitive data types are as follows:&lt;br /&gt;
&lt;br /&gt;
===Cannot be extended===&lt;br /&gt;
We can use a class or array to model the intricate data or functional structure. With the feature of class, programmers can create subtypes, modify their operations and even redefine them. In addition with the feature of class, programmers can make their variables unchangeable to any code outside the class, or make the implementation hidden to other code with call the methods. That means with composite data types, it will be more convenient for the programmers to handle sophisticated data and also make the code easier to maintain.&lt;br /&gt;
&lt;br /&gt;
In the following example, we create a Person type in RUBY. We defined a “talk” method to make a Person can talk about himself. We also hope to only make the variable “motherland” changeable by the code outside this class. &lt;br /&gt;
&lt;br /&gt;
Example: (in RUBY)&lt;br /&gt;
&lt;br /&gt;
    class Person&lt;br /&gt;
  &lt;br /&gt;
        def initialize( name, age=18 )&lt;br /&gt;
            @name = name&lt;br /&gt;
            @age = age&lt;br /&gt;
            @motherland = &amp;quot;US&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
  &lt;br /&gt;
        def talk&lt;br /&gt;
            puts &amp;quot;my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
            if  @motherland == &amp;quot;US&amp;quot;&lt;br /&gt;
               puts &amp;quot;I\'m American.&amp;quot;&lt;br /&gt;
            else&lt;br /&gt;
               puts &amp;quot;I\'m International.&amp;quot;&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
        attr_writer :motherland   &lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
Later when we need to create a “Student” type, we can just inherent the “Person” type and make some adjustment based on our needs. Here we redefine the “talk” method to make a student talk in a different way.&lt;br /&gt;
&lt;br /&gt;
    class Student &amp;lt; Person&lt;br /&gt;
 &lt;br /&gt;
         def talk&lt;br /&gt;
             puts &amp;quot;I am a student. my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
         end  &lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
===Inability on handling large scale data===&lt;br /&gt;
Though it means more processing time, it is necessary for programmers to create composite type to handle the data whose length is too large or changing all the time. If we have a set or integers to maintain in memory, but the number of integers will change every second, it will be impossible if we only use primitive types to handle. But we can make use of the “Arraylist” type in Java or other composite types. With the “Arraylist”, the programmers do not need to pay attention to the storage in the memory or the space it takes. The compiler of Java will reallocate more space automatically for the Arraylist if more elements are putted. &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.5.0/docs/api/java/util/ArrayList.html Inability on handling large scale data&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of the insert and sorting methods of the Arraylist type in Java:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    ArrayListaList=newArrayList();&lt;br /&gt;
    aList.Add(&amp;quot;a&amp;quot;);&lt;br /&gt;
    aList.Add(&amp;quot;b&amp;quot;);&lt;br /&gt;
    aList.Add(&amp;quot;c&amp;quot;);&lt;br /&gt;
    aList.Add(&amp;quot;d&amp;quot;); &lt;br /&gt;
    aList.Add(&amp;quot;e&amp;quot;);&lt;br /&gt;
    aList.Sort();&lt;br /&gt;
&lt;br /&gt;
===Limitation on size===&lt;br /&gt;
&lt;br /&gt;
For the primitive data types in most programming languages, there are some limits of the size. For example we can put an integer between -(2^16) and (2^16)-1 into an “int” in Java. That will be enough for some most of the cases but definitely not all of them. For example, the primitive types are not enough for a scientific calculation if we need an accuracy on 10^-500. And a more extreme case is to calculate the last 100 numbers for the PI has a 100 million length.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For these situations, the programmers usually need to create a composite data type by themselves. They can even redefine the operators (“+”, “-”) to make the super-long float also can make addition, subtraction with ordinary operators instead of method calling. For more details to create a super long float please see reference.&amp;lt;ref&amp;gt;http://en.verysource.com/code/1285797_1/tlargefloat.h.html Limitation on size&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Not supporting utility methods===&lt;br /&gt;
Most of the object oriented languages have certain utility methods associated with non primitive data types that ease their use as compared to primitive data types that do not have such methods.&amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html Not supporting utility methods&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
An especially useful example is the method of parsing integers in a specified radix in Java (Integer.parseInt). &lt;br /&gt;
&lt;br /&gt;
      parseInt(&amp;quot;1100110&amp;quot;, 2); //returns 102&lt;br /&gt;
      parseInt(&amp;quot;-0&amp;quot;, 10); //returns 0&lt;br /&gt;
      parseInt(&amp;quot;-FF&amp;quot;, 16); //returns -255&lt;br /&gt;
      parseInt(&amp;quot;99&amp;quot;, 8); //throws a NumberFormatException&lt;br /&gt;
&lt;br /&gt;
From the above examples, it is obvious that “Integer” type not just support ordinary methods an integer should have (such as Integer.equals), but also some more utility methods which are helpful for the programmers.&lt;br /&gt;
&lt;br /&gt;
In addition, for some data structure which only take object but not primitive type (such as Vector in Java), it is necessary to box a primitive data type to a corresponding object. For example if a programmer needs to make use of a vector to store some integer, it is necessary to box the ints and floats first:&lt;br /&gt;
&lt;br /&gt;
      Vector　v=new Vector();  &lt;br /&gt;
      int k=121; &lt;br /&gt;
      v.addElemt(new Integer(k));&lt;br /&gt;
&lt;br /&gt;
===Functionality===&lt;br /&gt;
Discussion of advantages and disadvantages should concerned the functionality you want to implement. For example if you want to operate a serials of int number. The performance of array may be better than int. &amp;lt;ref&amp;gt;http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH05/CH05-2.html Composite datatypes&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:1w1.gif]]&lt;br /&gt;
&lt;br /&gt;
To access an element of an array, you need a function that converts an array index into the address of the indexed element. For a single dimension array, this function is very simple. It is&lt;br /&gt;
Element_Address = Base_Address + ((Index - Initial_Index) * Element_Size)&lt;br /&gt;
&lt;br /&gt;
However, If you use five primitive data type to implement the same function. It may cost more time for the cpu to search the address of each data.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
In a nutshell, composite data type is more likely to stand out the features of object-oriented language and be widely used. However,primitive data type would not disappear in a foreseeable future because of its advantage in performance and use. It bridges the gap between novice programmers and experienced programmers by making powerful features basic to the language and makes coding simpler. Dealing with primitive objects is easier at times.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63526</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w21 wi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63526"/>
		<updated>2012-09-11T03:22:16Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Primitive objects in object-oriented languages'''&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
In any programming language, the [http://en.wikipedia.org/wiki/Data_type data type] refers to the class of data which contains specific type or range of values. Data types are used along with variables used in the program. The data type tells us what kind of values the variable can store, what is the range of the values and how much space the values take in memory etc.&lt;br /&gt;
&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Primitive_data_type primitive data types] refer to the built-in data types which are supported by the programming language. Often 'data types' and 'primitive data types' are used interchangeably. But not all data types are primitive. Programming languages have some non-primitive data types or derived data types which are provided by the language by making use of its primitive data types.&lt;br /&gt;
&lt;br /&gt;
The common built-in data types or primitive data types are integers, floating point numbers, characters, strings and boolean.&lt;br /&gt;
* Integers - Integers represent the whole numbers which can be positive or negative or zero, e.g. 9999, 0, -25, etc. &lt;br /&gt;
* Floating point numbers - Floating point numbers represent the numbers which are fractions or contain floating-decimal points, e.g. -3.002, 2.5, 22.0, etc.&lt;br /&gt;
* Characters - Characters represent any single letter, number, space, punctuation mark, or symbol that can be typed on a computer, e.g. 'a', '9', ' ', '!' , '\n', etc.&lt;br /&gt;
* Strings - Strings represent the sequences of characters or simply any text, e.g. &amp;quot;Hello!&amp;quot;, &amp;quot;9 am to 6 pm&amp;quot;, etc. &lt;br /&gt;
* Booleans - Booleans represent the true or false values. Sometimes, instead of true and false, 1 and 0 are used to represent the boolean values.&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] languages provide support for primitive data types while some object-oriented programming languages provide support for primitive objects along with primitive types.&lt;br /&gt;
&lt;br /&gt;
== Definition ==&lt;br /&gt;
&lt;br /&gt;
Primitive objects refer to the objects of built-in classes which provide more functionality than the primitive types. Some object-oriented programming languages provide support for only primitive objects (i.e., in such languages all primitive types are objects).&lt;br /&gt;
&lt;br /&gt;
Different object-oriented programming languages implement these primitive data types and primitive objects in a different manner.&lt;br /&gt;
&lt;br /&gt;
== Primitive objects in different OO languages ==&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java], there are 8 primitive types: boolean, char, byte, short, int, long, float, and double. &amp;lt;ref&amp;gt;http://www.cafeaulait.org/course/week2/02.html Java's Primitive Data Types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each of these primitive types, Java provides [http://en.wikipedia.org/wiki/Primitive_wrapper_class wrapper classes] to create primitive objects which wrap the primitive data values. A wrapper  not only contains the primitive data value, but it also defines properties and methods that can be used to manipulate that data. In Java, the primitive values are not implicitly converted to primitive objects. Instead, methods are provided for doing explicit conversion.&lt;br /&gt;
The primitive objects are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack heap] in memory while the variables containing primitive values are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack stack].&amp;lt;ref&amp;gt;http://www.informit.com/articles/article.aspx?p=31755&amp;amp;seqNum=8 Stack and Heap memory&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class!! Size&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean || 1-bit&lt;br /&gt;
|-&lt;br /&gt;
| char || Character || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| byte || Byte || 8-bit&lt;br /&gt;
|-&lt;br /&gt;
| short || Short || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| int || Integer || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| long || Long || 64-bit&lt;br /&gt;
|-&lt;br /&gt;
| float || Float || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| double || Double || 64-bit&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 20;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I+II);            &lt;br /&gt;
    System.out.println(I.equals(II));    &lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    30&lt;br /&gt;
    false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find out if these wrapper classes are primitive or not, we can use the isPrimitive() method.&lt;br /&gt;
&lt;br /&gt;
    System.out.println(INTEGER.TYPE.isPrimitive());&lt;br /&gt;
    System.out.println(BOOLEAN.TYPE.isPrimitive());&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    true&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java, the comparison operations work in the same way on the primitive objects as well as any other class objects but different on the primitive types. The == operator when used on objects checks whether they refer to the same object but when used on variables of primitive types checks whether they contain the same value.&amp;lt;ref&amp;gt;http://leepoint.net/notes-java/data/expressions/22compareobjects.html Comparisons in Java&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 10;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I==II);            &lt;br /&gt;
    System.out.println(i==ii);&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    false&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29 C#] is a [http://en.wikipedia.org/wiki/Strong_typing strongly typed] language, where it is necessary to declare the data type of a variable and also be aware of the data type conversion. C# provides a significant number of primitive data types.&amp;lt;ref&amp;gt;http://condor.depaul.edu/sjost/ndp/notes/cs1/CSDatatypes.htm C# Primitive Datatypes&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.java2s.com/Tutorial/CSharp/0040__Data-Type/PrimitivesinC.htm Primitives in C#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type. For example:&lt;br /&gt;
 &lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        int x = 7;&lt;br /&gt;
        object o = x;&lt;br /&gt;
        System.Console.WriteLine(o.ToString());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Some data types (e.g. Decimal and String) can appear like primitives at first sight, but are actually not. So it is important to exercise caution before making such assumptions. To test whether a particular type is a primitive or not you can use the property Type.IsPrimitive.&lt;br /&gt;
&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;br /&gt;
    if (t.IsPrimitive)    // where t is the type&lt;br /&gt;
    {&lt;br /&gt;
        // Is Primitive&lt;br /&gt;
    } else if (t == typeof(Decimal))&lt;br /&gt;
    {&lt;br /&gt;
        // Is Decimal&lt;br /&gt;
    } else if (t == typeof(String))&lt;br /&gt;
    {&lt;br /&gt;
        // Is String&lt;br /&gt;
    } else&lt;br /&gt;
    {&lt;br /&gt;
        // Other type&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== JavaScript ===&lt;br /&gt;
&lt;br /&gt;
There are 5 primitive data types in [http://en.wikipedia.org/wiki/JavaScript JavaScript]: string, number, boolean, null and undefined. &amp;lt;ref&amp;gt;http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html JavaScript Data Types and Variables&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For string, number and boolean values, there are corresponding classes just like in Java to create primitive objects which wrap the primitive values. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class&lt;br /&gt;
|-&lt;br /&gt;
| string || String&lt;br /&gt;
|-&lt;br /&gt;
| number|| Number&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In JavaScript, the primitive value is implicitly converted to a primitive object whenever someone tries to access a property or invoke a method on the primitive value and the primitive object is used in place of the primitive value. Since the object contains properties and methods, the use of primitive value as an object succeeds. After the property is accessed or the method is processed, the primitive object is no longer needed and hence discarded. The same is true for the other primitive types and their corresponding primitive objects.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    var upperCaseString = &amp;quot;APPLE&amp;quot;;&lt;br /&gt;
    var lowerCaseString = upperCaseString.toLowerCase();  // assigns string &amp;quot;apple&amp;quot; to lowerCaseString &lt;br /&gt;
    var s = &amp;quot;Hello&amp;quot;&lt;br /&gt;
    var len = s.length;                                   // assigns value 5 to len&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
&lt;br /&gt;
Since [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] is a [http://www.jvoegele.com/software/langcomp.html pure object oriented] language, everything in Ruby is an object. Hence, all primitive types such as integers, floating point numbers, strings, are objects of a built-in class.&amp;lt;ref&amp;gt;http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Classes in Ruby&amp;lt;/ref&amp;gt; &lt;br /&gt;
All integers are primitive objects of either class [http://corelib.rubyonrails.org/classes/Fixnum.html Fixnum] or [http://corelib.rubyonrails.org/classes/Bignum.html Bignum]. A numeric literal with a decimal point and/or an exponent is a primitive object of [http://corelib.rubyonrails.org/classes/Float.html Float]. Single quoted literals and double quoted literals are primitive objects of [http://corelib.rubyonrails.org/classes/String.html String].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    puts 10.class&lt;br /&gt;
    puts 7.45.class&lt;br /&gt;
    puts 'hi'.class&lt;br /&gt;
    puts &amp;quot;hello&amp;quot;.class&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    Fixnum&lt;br /&gt;
    Float&lt;br /&gt;
    String&lt;br /&gt;
    String&lt;br /&gt;
&lt;br /&gt;
This indicates that 10 is converted into an object of type Fixnum, 7.45 is converted into an object of type Float, 'hi' and &amp;quot;hello&amp;quot; are both converted into an object of type String.&lt;br /&gt;
&lt;br /&gt;
Since all primitive types in Ruby are objects, we should be able to call methods of the Object class on them. Let us demonstrate the same for integer and float using the following example:&lt;br /&gt;
&lt;br /&gt;
    a=10&lt;br /&gt;
    puts a.to_f  &lt;br /&gt;
    b=20.5&lt;br /&gt;
    puts b.to_i&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    10.0&lt;br /&gt;
    20&lt;br /&gt;
&lt;br /&gt;
== Advantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
Advantages that use of primitive data type offers are as follows:&lt;br /&gt;
===Consistency===&lt;br /&gt;
Many ideas of Java originate in C and in C++, objects and primitive type also co-exist. When object-oriented constructs were grafted onto the C language, C’s data types remained as is. The motivation behind this is that Bjarne Stroustrup, C++’s designer, wanted to be as consistent as possible with the base C language, hoping to capitalize on programmers’ pre-C++ knowledge.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://www.research.ibm.com/people/a/alpert/ptch/ptch.html Primitive Types Considered Harmful&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Simplicity===&lt;br /&gt;
It is simple and intuitive to use primitive data type in basic utility.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
1. Recurring number in a loop.(C++)&lt;br /&gt;
&lt;br /&gt;
   for(int i=0;i&amp;lt;10;i++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Temp variables that record only one or two data.&lt;br /&gt;
&lt;br /&gt;
===Time performance===&lt;br /&gt;
Processing primitive data type operation would be faster than processing composite data type in most cases. There are several reasons result in this differences. &lt;br /&gt;
*Hardware processing discrepancy&lt;br /&gt;
Many primitive data operations (like integer addition) can be performed as a single machine instruction while processing of composite data type would be transformed to a combination of primitive data types. eg. Some processors offer specific instructions to process sequences of characters with a single instruction.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
[http://www.research.ibm.com/people/a/alpert/ptch/ptch.html  Difference in data fetching between primitive data and composite data in Java]&lt;br /&gt;
 &lt;br /&gt;
*Allocating and Garbage collection overhead for composite data type&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Performance_implications Garbage collection&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.ibm.com/developerworks/java/library/j-jtp01274/index.html Java theory and practice: Garbage collection and performance&amp;lt;/ref&amp;gt;&lt;br /&gt;
There are many initialization operations for composite data type that will generate high overheads for example boxing and unboxing, constructors and destructors.Composite data type like class will also have garbage collection overheads that may be beyond the control of the programmer and can sometimes lead to performance problems. For example, commonly used stop-the-world garbage collectors, which pause program execution at arbitrary times, may make garbage collection inappropriate for some [http://en.wikipedia.org/wiki/Embedded_system embedded systems], high-performance [http://en.wikipedia.org/wiki/Server_(computing)  server] software, and applications with [http://en.wikipedia.org/wiki/Real-time_computing real-time] needs.In the early days of Java technology, allocating objects got a high overheads. There were lots of articles advising developers to avoid creating temporary objects unnecessarily because allocation (and the corresponding garbage-collection overhead) was expensive. Although the costs have been greatly reduced nowadays. It still much slower than primitive data type which don’t have such troubles.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
        public void test1(){&lt;br /&gt;
           int a=1,b=1;&lt;br /&gt;
           long startTime1 = System.currentTimeMillis();&lt;br /&gt;
           for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
              a=a+b;&lt;br /&gt;
                          }&lt;br /&gt;
           long endTime1 = System.currentTimeMillis();&lt;br /&gt;
           System.out.println(endTime1-startTime1);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        public void test2(){&lt;br /&gt;
            Integer c=new Integer(1);&lt;br /&gt;
            Integer d=new Integer(1);&lt;br /&gt;
            long startTime2 = System.currentTimeMillis();&lt;br /&gt;
            for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
               c=c+d;&lt;br /&gt;
            }&lt;br /&gt;
            long endTime2 = System.currentTimeMillis();&lt;br /&gt;
            System.out.println(endTime2-startTime2)&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
Average execution time for test1 is: 1 mm&lt;br /&gt;
&lt;br /&gt;
Average execution time for test2 is: 702mm&lt;br /&gt;
&lt;br /&gt;
(test case number: 1000 times )&lt;br /&gt;
&lt;br /&gt;
===Space performance===&lt;br /&gt;
Composite data type will cost more memory space than primitive data type in general. The reason is not only for the overheads generated by constructors, destructors etc, but also the feature of data alignment. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding Data structure alignment&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of data alignment（C++）&lt;br /&gt;
       struct compose&lt;br /&gt;
       {&lt;br /&gt;
           char name;&lt;br /&gt;
           int a;&lt;br /&gt;
           int b;&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
We all know the size of char is 1 byte, the size of int is 4 bytes. But the size of the struct compose as shown above is 12 bytes but not 9 bytes.&lt;br /&gt;
&lt;br /&gt;
== Disdvantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
The various disadvantages of using the primitive data types are as follows:&lt;br /&gt;
&lt;br /&gt;
===Cannot be extended===&lt;br /&gt;
We can use a class or array to model the intricate data or functional structure. With the feature of class, programmers can create subtypes, modify their operations and even redefine them. In addition with the feature of class, programmers can make their variables unchangeable to any code outside the class, or make the implementation hidden to other code with call the methods. That means with composite data types, it will be more convenient for the programmers to handle sophisticated data and also make the code easier to maintain.&lt;br /&gt;
&lt;br /&gt;
In the following example, we create a Person type in RUBY. We defined a “talk” method to make a Person can talk about himself. We also hope to only make the variable “motherland” changeable by the code outside this class. &lt;br /&gt;
&lt;br /&gt;
Example: (in RUBY)&lt;br /&gt;
&lt;br /&gt;
      class Person&lt;br /&gt;
  &lt;br /&gt;
          def initialize( name, age=18 )&lt;br /&gt;
              @name = name&lt;br /&gt;
              @age = age&lt;br /&gt;
              @motherland = &amp;quot;US&amp;quot;&lt;br /&gt;
          end&lt;br /&gt;
  &lt;br /&gt;
          def talk&lt;br /&gt;
              puts &amp;quot;my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
              if  @motherland == &amp;quot;US&amp;quot;&lt;br /&gt;
                 puts &amp;quot;I\'m American.&amp;quot;&lt;br /&gt;
              else&lt;br /&gt;
                 puts &amp;quot;I\'m International.&amp;quot;&lt;br /&gt;
              end&lt;br /&gt;
          end&lt;br /&gt;
          attr_writer :motherland   &lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
Later when we need to create a “Student” type, we can just inherent the “Person” type and make some adjustment based on our needs. Here we redefine the “talk” method to make a student talk in a different way.&lt;br /&gt;
&lt;br /&gt;
      class Student &amp;lt; Person&lt;br /&gt;
 &lt;br /&gt;
           def talk&lt;br /&gt;
               puts &amp;quot;I am a student. my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
           end  &lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
===Inability on handling large scale data===&lt;br /&gt;
Though it means more processing time, it is necessary for programmers to create composite type to handle the data whose length is too large or changing all the time. If we have a set or integers to maintain in memory, but the number of integers will change every second, it will be impossible if we only use primitive types to handle. But we can make use of the “Arraylist” type in Java or other composite types. With the “Arraylist”, the programmers do not need to pay attention to the storage in the memory or the space it takes. The compiler of Java will reallocate more space automatically for the Arraylist if more elements are putted. &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.5.0/docs/api/java/util/ArrayList.html Inability on handling large scale data&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of the insert and sorting methods of the Arraylist type in Java:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ArrayListaList=newArrayList();&lt;br /&gt;
      aList.Add(&amp;quot;a&amp;quot;);&lt;br /&gt;
      aList.Add(&amp;quot;b&amp;quot;);&lt;br /&gt;
      aList.Add(&amp;quot;c&amp;quot;);&lt;br /&gt;
      aList.Add(&amp;quot;d&amp;quot;); &lt;br /&gt;
      aList.Add(&amp;quot;e&amp;quot;);&lt;br /&gt;
      aList.Sort();&lt;br /&gt;
&lt;br /&gt;
===Limitation on size===&lt;br /&gt;
&lt;br /&gt;
For the primitive data types in most programming languages, there are some limits of the size. For example we can put an integer between -(2^16) and (2^16)-1 into an “int” in Java. That will be enough for some most of the cases but definitely not all of them. For example, the primitive types are not enough for a scientific calculation if we need an accuracy on 10^-500. And a more extreme case is to calculate the last 100 numbers for the PI has a 100 million length.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For these situations, the programmers usually need to create a composite data type by themselves. They can even redefine the operators (“+”, “-”) to make the super-long float also can make addition, subtraction with ordinary operators instead of method calling. For more details to create a super long float please see reference.&amp;lt;ref&amp;gt;http://en.verysource.com/code/1285797_1/tlargefloat.h.html Limitation on size&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Not supporting utility methods===&lt;br /&gt;
Most of the object oriented languages have certain utility methods associated with non primitive data types that ease their use as compared to primitive data types that do not have such methods.&amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html Not supporting utility methods&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
An especially useful example is the method of parsing integers in a specified radix in Java (Integer.parseInt). &lt;br /&gt;
&lt;br /&gt;
      parseInt(&amp;quot;1100110&amp;quot;, 2); //returns 102&lt;br /&gt;
      parseInt(&amp;quot;-0&amp;quot;, 10); //returns 0&lt;br /&gt;
      parseInt(&amp;quot;-FF&amp;quot;, 16); //returns -255&lt;br /&gt;
      parseInt(&amp;quot;99&amp;quot;, 8); //throws a NumberFormatException&lt;br /&gt;
&lt;br /&gt;
From the above examples, it is obvious that “Integer” type not just support ordinary methods an integer should have (such as Integer.equals), but also some more utility methods which are helpful for the programmers.&lt;br /&gt;
&lt;br /&gt;
In addition, for some data structure which only take object but not primitive type (such as Vector in Java), it is necessary to box a primitive data type to a corresponding object. For example if a programmer needs to make use of a vector to store some integer, it is necessary to box the ints and floats first:&lt;br /&gt;
&lt;br /&gt;
      Vector　v=new Vector();  &lt;br /&gt;
      int k=121; &lt;br /&gt;
      v.addElemt(new Integer(k));&lt;br /&gt;
&lt;br /&gt;
===Functionality===&lt;br /&gt;
Discussion of advantages and disadvantages should concerned the functionality you want to implement. For example if you want to operate a serials of int number. The performance of array may be better than int. &amp;lt;ref&amp;gt;http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH05/CH05-2.html Composite datatypes&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:1w1.gif]]&lt;br /&gt;
&lt;br /&gt;
To access an element of an array, you need a function that converts an array index into the address of the indexed element. For a single dimension array, this function is very simple. It is&lt;br /&gt;
Element_Address = Base_Address + ((Index - Initial_Index) * Element_Size)&lt;br /&gt;
&lt;br /&gt;
However, If you use five primitive data type to implement the same function. It may cost more time for the cpu to search the address of each data.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
In a nutshell,composite data type is more likely to stand out the features of object-oriented language and be widely used. However,primitive data type would not disappear in a foreseeable future because of its advantage in performance and use. It bridges the gap between novice programmers and experienced programmers by making powerful features basic to the language and makes coding simpler. Dealing with primitive objects is easier at times. In brief, the primitive objects help to increase the productivity of the programmers.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63524</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w21 wi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63524"/>
		<updated>2012-09-11T03:21:41Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Primitive objects in object-oriented languages'''&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
In any programming language, the [http://en.wikipedia.org/wiki/Data_type data type] refers to the class of data which contains specific type or range of values. Data types are used along with variables used in the program. The data type tells us what kind of values the variable can store, what is the range of the values and how much space the values take in memory etc.&lt;br /&gt;
&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Primitive_data_type primitive data types] refer to the built-in data types which are supported by the programming language. Often 'data types' and 'primitive data types' are used interchangeably. But not all data types are primitive. Programming languages have some non-primitive data types or derived data types which are provided by the language by making use of its primitive data types.&lt;br /&gt;
&lt;br /&gt;
The common built-in data types or primitive data types are integers, floating point numbers, characters, strings and boolean.&lt;br /&gt;
* Integers - Integers represent the whole numbers which can be positive or negative or zero, e.g. 9999, 0, -25, etc. &lt;br /&gt;
* Floating point numbers - Floating point numbers represent the numbers which are fractions or contain floating-decimal points, e.g. -3.002, 2.5, 22.0, etc.&lt;br /&gt;
* Characters - Characters represent any single letter, number, space, punctuation mark, or symbol that can be typed on a computer, e.g. 'a', '9', ' ', '!' , '\n', etc.&lt;br /&gt;
* Strings - Strings represent the sequences of characters or simply any text, e.g. &amp;quot;Hello!&amp;quot;, &amp;quot;9 am to 6 pm&amp;quot;, etc. &lt;br /&gt;
* Booleans - Booleans represent the true or false values. Sometimes, instead of true and false, 1 and 0 are used to represent the boolean values.&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] languages provide support for primitive data types while some object-oriented programming languages provide support for primitive objects along with primitive types.&lt;br /&gt;
&lt;br /&gt;
== Definition ==&lt;br /&gt;
&lt;br /&gt;
Primitive objects refer to the objects of built-in classes which provide more functionality than the primitive types. Some object-oriented programming languages provide support for only primitive objects (i.e., in such languages all primitive types are objects).&lt;br /&gt;
&lt;br /&gt;
Different object-oriented programming languages implement these primitive data types and primitive objects in a different manner.&lt;br /&gt;
&lt;br /&gt;
== Primitive objects in different OO languages ==&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java], there are 8 primitive types: boolean, char, byte, short, int, long, float, and double. &amp;lt;ref&amp;gt;http://www.cafeaulait.org/course/week2/02.html Java's Primitive Data Types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each of these primitive types, Java provides [http://en.wikipedia.org/wiki/Primitive_wrapper_class wrapper classes] to create primitive objects which wrap the primitive data values. A wrapper  not only contains the primitive data value, but it also defines properties and methods that can be used to manipulate that data. In Java, the primitive values are not implicitly converted to primitive objects. Instead, methods are provided for doing explicit conversion.&lt;br /&gt;
The primitive objects are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack heap] in memory while the variables containing primitive values are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack stack].&amp;lt;ref&amp;gt;http://www.informit.com/articles/article.aspx?p=31755&amp;amp;seqNum=8 Stack and Heap memory&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class!! Size&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean || 1-bit&lt;br /&gt;
|-&lt;br /&gt;
| char || Character || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| byte || Byte || 8-bit&lt;br /&gt;
|-&lt;br /&gt;
| short || Short || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| int || Integer || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| long || Long || 64-bit&lt;br /&gt;
|-&lt;br /&gt;
| float || Float || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| double || Double || 64-bit&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 20;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I+II);            &lt;br /&gt;
    System.out.println(I.equals(II));    &lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    30&lt;br /&gt;
    false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find out if these wrapper classes are primitive or not, we can use the isPrimitive() method.&lt;br /&gt;
&lt;br /&gt;
    System.out.println(INTEGER.TYPE.isPrimitive());&lt;br /&gt;
    System.out.println(BOOLEAN.TYPE.isPrimitive());&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    true&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java, the comparison operations work in the same way on the primitive objects as well as any other class objects but different on the primitive types. The == operator when used on objects checks whether they refer to the same object but when used on variables of primitive types checks whether they contain the same value.&amp;lt;ref&amp;gt;http://leepoint.net/notes-java/data/expressions/22compareobjects.html Comparisons in Java&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 10;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I==II);            &lt;br /&gt;
    System.out.println(i==ii);&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    false&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29 C#] is a [http://en.wikipedia.org/wiki/Strong_typing strongly typed] language, where it is necessary to declare the data type of a variable and also be aware of the data type conversion. C# provides a significant number of primitive data types.&amp;lt;ref&amp;gt;http://condor.depaul.edu/sjost/ndp/notes/cs1/CSDatatypes.htm C# Primitive Datatypes&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.java2s.com/Tutorial/CSharp/0040__Data-Type/PrimitivesinC.htm Primitives in C#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type. For example:&lt;br /&gt;
 &lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        int x = 7;&lt;br /&gt;
        object o = x;&lt;br /&gt;
        System.Console.WriteLine(o.ToString());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Some data types (e.g. Decimal and String) can appear like primitives at first sight, but are actually not. So it is important to exercise caution before making such assumptions. To test whether a particular type is a primitive or not you can use the property Type.IsPrimitive.&lt;br /&gt;
&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;br /&gt;
    if (t.IsPrimitive)    // where t is the type&lt;br /&gt;
    {&lt;br /&gt;
        // Is Primitive&lt;br /&gt;
    } else if (t == typeof(Decimal))&lt;br /&gt;
    {&lt;br /&gt;
        // Is Decimal&lt;br /&gt;
    } else if (t == typeof(String))&lt;br /&gt;
    {&lt;br /&gt;
        // Is String&lt;br /&gt;
    } else&lt;br /&gt;
    {&lt;br /&gt;
        // Other type&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== JavaScript ===&lt;br /&gt;
&lt;br /&gt;
There are 5 primitive data types in [http://en.wikipedia.org/wiki/JavaScript JavaScript]: string, number, boolean, null and undefined. &amp;lt;ref&amp;gt;http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html JavaScript Data Types and Variables&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For string, number and boolean values, there are corresponding classes just like in Java to create primitive objects which wrap the primitive values. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class&lt;br /&gt;
|-&lt;br /&gt;
| string || String&lt;br /&gt;
|-&lt;br /&gt;
| number|| Number&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In JavaScript, the primitive value is implicitly converted to a primitive object whenever someone tries to access a property or invoke a method on the primitive value and the primitive object is used in place of the primitive value. Since the object contains properties and methods, the use of primitive value as an object succeeds. After the property is accessed or the method is processed, the primitive object is no longer needed and hence discarded. The same is true for the other primitive types and their corresponding primitive objects.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    var upperCaseString = &amp;quot;APPLE&amp;quot;;&lt;br /&gt;
    var lowerCaseString = upperCaseString.toLowerCase();  // assigns string &amp;quot;apple&amp;quot; to lowerCaseString &lt;br /&gt;
    var s = &amp;quot;Hello&amp;quot;&lt;br /&gt;
    var len = s.length;                                   // assigns value 5 to len&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
&lt;br /&gt;
Since [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] is a [http://www.jvoegele.com/software/langcomp.html pure object oriented] language, everything in Ruby is an object. Hence, all primitive types such as integers, floating point numbers, strings, are objects of a built-in class.&amp;lt;ref&amp;gt;http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Classes in Ruby&amp;lt;/ref&amp;gt; &lt;br /&gt;
All integers are primitive objects of either class [http://corelib.rubyonrails.org/classes/Fixnum.html Fixnum] or [http://corelib.rubyonrails.org/classes/Bignum.html Bignum]. A numeric literal with a decimal point and/or an exponent is a primitive object of [http://corelib.rubyonrails.org/classes/Float.html Float]. Single quoted literals and double quoted literals are primitive objects of [http://corelib.rubyonrails.org/classes/String.html String].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    puts 10.class&lt;br /&gt;
    puts 7.45.class&lt;br /&gt;
    puts 'hi'.class&lt;br /&gt;
    puts &amp;quot;hello&amp;quot;.class&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    Fixnum&lt;br /&gt;
    Float&lt;br /&gt;
    String&lt;br /&gt;
    String&lt;br /&gt;
&lt;br /&gt;
This indicates that 10 is converted into an object of type Fixnum, 7.45 is converted into an object of type Float, 'hi' and &amp;quot;hello&amp;quot; are both converted into an object of type String.&lt;br /&gt;
&lt;br /&gt;
Since all primitive types in Ruby are objects, we should be able to call methods of the Object class on them. Let us demonstrate the same for integer and float using the following example:&lt;br /&gt;
&lt;br /&gt;
    a=10&lt;br /&gt;
    puts a.to_f  &lt;br /&gt;
    b=20.5&lt;br /&gt;
    puts b.to_i&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    10.0&lt;br /&gt;
    20&lt;br /&gt;
&lt;br /&gt;
== Advantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
Advantages that use of primitive data type offers are as follows:&lt;br /&gt;
===Consistency===&lt;br /&gt;
Many ideas of Java originate in C and in C++, objects and primitive type also co-exist. When object-oriented constructs were grafted onto the C language, C’s data types remained as is. The motivation behind this is that Bjarne Stroustrup, C++’s designer, wanted to be as consistent as possible with the base C language, hoping to capitalize on programmers’ pre-C++ knowledge.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://www.research.ibm.com/people/a/alpert/ptch/ptch.html Primitive Types Considered Harmful&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Simplicity===&lt;br /&gt;
It is simple and intuitive to use primitive data type in basic utility.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
1. Recurring number in a loop.(C++)&lt;br /&gt;
&lt;br /&gt;
   for(int i=0;i&amp;lt;10;i++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Temp variables that record only one or two data.&lt;br /&gt;
&lt;br /&gt;
===Time performance===&lt;br /&gt;
Processing primitive data type operation would be faster than processing composite data type in most cases. There are several reasons result in this differences. &lt;br /&gt;
*Hardware processing discrepancy&lt;br /&gt;
Many primitive data operations (like integer addition) can be performed as a single machine instruction while processing of composite data type would be transformed to a combination of primitive data types. eg. Some processors offer specific instructions to process sequences of characters with a single instruction.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
[http://www.research.ibm.com/people/a/alpert/ptch/ptch.html  Difference in data fetching between primitive data and composite data in Java]&lt;br /&gt;
 &lt;br /&gt;
*Allocating and Garbage collection overhead for composite data type&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Performance_implications Garbage collection&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.ibm.com/developerworks/java/library/j-jtp01274/index.html Java theory and practice: Garbage collection and performance&amp;lt;/ref&amp;gt;&lt;br /&gt;
There are many initialization operations for composite data type that will generate high overheads for example boxing and unboxing, constructors and destructors.Composite data type like class will also have garbage collection overheads that may be beyond the control of the programmer and can sometimes lead to performance problems. For example, commonly used stop-the-world garbage collectors, which pause program execution at arbitrary times, may make garbage collection inappropriate for some [http://en.wikipedia.org/wiki/Embedded_system embedded systems], high-performance [http://en.wikipedia.org/wiki/Server_(computing)  server] software, and applications with [http://en.wikipedia.org/wiki/Real-time_computing real-time] needs.In the early days of Java technology, allocating objects got a high overheads. There were lots of articles advising developers to avoid creating temporary objects unnecessarily because allocation (and the corresponding garbage-collection overhead) was expensive. Although the costs have been greatly reduced nowadays. It still much slower than primitive data type which don’t have such troubles.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
        public void test1(){&lt;br /&gt;
           int a=1,b=1;&lt;br /&gt;
           long startTime1 = System.currentTimeMillis();&lt;br /&gt;
           for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
              a=a+b;&lt;br /&gt;
                          }&lt;br /&gt;
           long endTime1 = System.currentTimeMillis();&lt;br /&gt;
           System.out.println(endTime1-startTime1);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        public void test2(){&lt;br /&gt;
            Integer c=new Integer(1);&lt;br /&gt;
            Integer d=new Integer(1);&lt;br /&gt;
            long startTime2 = System.currentTimeMillis();&lt;br /&gt;
            for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
               c=c+d;&lt;br /&gt;
            }&lt;br /&gt;
            long endTime2 = System.currentTimeMillis();&lt;br /&gt;
            System.out.println(endTime2-startTime2)&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
Average execution time for test1 is: 1 mm&lt;br /&gt;
&lt;br /&gt;
Average execution time for test2 is: 702mm&lt;br /&gt;
&lt;br /&gt;
(test case number: 1000 times )&lt;br /&gt;
&lt;br /&gt;
===Space performance===&lt;br /&gt;
Composite data type will cost more memory space than primitive data type in general. The reason is not only for the overheads generated by constructors, destructors etc, but also the feature of data alignment. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding Data structure alignment&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of data alignment（C++）&lt;br /&gt;
       struct compose&lt;br /&gt;
       {&lt;br /&gt;
           char name;&lt;br /&gt;
           int a;&lt;br /&gt;
           int b;&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
We all know the size of char is 1 byte, the size of int is 4 bytes. But the size of the struct compose as shown above is 12 bytes but not 9 bytes.&lt;br /&gt;
&lt;br /&gt;
== Disdvantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
The various disadvantages of using the primitive data types are as follows:&lt;br /&gt;
&lt;br /&gt;
===Cannot be extended===&lt;br /&gt;
We can use a class or array to model the intricate data or functional structure. With the feature of class, programmers can create subtypes, modify their operations and even redefine them. In addition with the feature of class, programmers can make their variables unchangeable to any code outside the class, or make the implementation hidden to other code with call the methods. That means with composite data types, it will be more convenient for the programmers to handle sophisticated data and also make the code easier to maintain.&lt;br /&gt;
&lt;br /&gt;
In the following example, we create a Person type in RUBY. We defined a “talk” method to make a Person can talk about himself. We also hope to only make the variable “motherland” changeable by the code outside this class. &lt;br /&gt;
&lt;br /&gt;
Example: (in RUBY)&lt;br /&gt;
&lt;br /&gt;
       class Person&lt;br /&gt;
  &lt;br /&gt;
           def initialize( name, age=18 )&lt;br /&gt;
               @name = name&lt;br /&gt;
               @age = age&lt;br /&gt;
               @motherland = &amp;quot;US&amp;quot;&lt;br /&gt;
           end&lt;br /&gt;
  &lt;br /&gt;
           def talk&lt;br /&gt;
               puts &amp;quot;my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
               if  @motherland == &amp;quot;US&amp;quot;&lt;br /&gt;
                  puts &amp;quot;I\'m American.&amp;quot;&lt;br /&gt;
               else&lt;br /&gt;
                  puts &amp;quot;I\'m International.&amp;quot;&lt;br /&gt;
               end&lt;br /&gt;
           end&lt;br /&gt;
           attr_writer :motherland   &lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
Later when we need to create a “Student” type, we can just inherent the “Person” type and make some adjustment based on our needs. Here we redefine the “talk” method to make a student talk in a different way.&lt;br /&gt;
&lt;br /&gt;
       class Student &amp;lt; Person&lt;br /&gt;
 &lt;br /&gt;
            def talk&lt;br /&gt;
                puts &amp;quot;I am a student. my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
            end  &lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
===Inability on handling large scale data===&lt;br /&gt;
Though it means more processing time, it is necessary for programmers to create composite type to handle the data whose length is too large or changing all the time. If we have a set or integers to maintain in memory, but the number of integers will change every second, it will be impossible if we only use primitive types to handle. But we can make use of the “Arraylist” type in Java or other composite types. With the “Arraylist”, the programmers do not need to pay attention to the storage in the memory or the space it takes. The compiler of Java will reallocate more space automatically for the Arraylist if more elements are putted. &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.5.0/docs/api/java/util/ArrayList.html Inability on handling large scale data&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of the insert and sorting methods of the Arraylist type in Java:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ArrayListaList=newArrayList();&lt;br /&gt;
      aList.Add(&amp;quot;a&amp;quot;);&lt;br /&gt;
      aList.Add(&amp;quot;b&amp;quot;);&lt;br /&gt;
      aList.Add(&amp;quot;c&amp;quot;);&lt;br /&gt;
      aList.Add(&amp;quot;d&amp;quot;); &lt;br /&gt;
      aList.Add(&amp;quot;e&amp;quot;);&lt;br /&gt;
      aList.Sort();&lt;br /&gt;
&lt;br /&gt;
===Limitation on size===&lt;br /&gt;
&lt;br /&gt;
For the primitive data types in most programming languages, there are some limits of the size. For example we can put an integer between -(2^16) and (2^16)-1 into an “int” in Java. That will be enough for some most of the cases but definitely not all of them. For example, the primitive types are not enough for a scientific calculation if we need an accuracy on 10^-500. And a more extreme case is to calculate the last 100 numbers for the PI has a 100 million length.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For these situations, the programmers usually need to create a composite data type by themselves. They can even redefine the operators (“+”, “-”) to make the super-long float also can make addition, subtraction with ordinary operators instead of method calling. For more details to create a super long float please see reference.&amp;lt;ref&amp;gt;http://en.verysource.com/code/1285797_1/tlargefloat.h.html Limitation on size&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Not supporting utility methods===&lt;br /&gt;
Most of the object oriented languages have certain utility methods associated with non primitive data types that ease their use as compared to primitive data types that do not have such methods.&amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html Not supporting utility methods&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
An especially useful example is the method of parsing integers in a specified radix in Java (Integer.parseInt). &lt;br /&gt;
&lt;br /&gt;
      parseInt(&amp;quot;1100110&amp;quot;, 2); //returns 102&lt;br /&gt;
      parseInt(&amp;quot;-0&amp;quot;, 10); //returns 0&lt;br /&gt;
      parseInt(&amp;quot;-FF&amp;quot;, 16); //returns -255&lt;br /&gt;
      parseInt(&amp;quot;99&amp;quot;, 8); //throws a NumberFormatException&lt;br /&gt;
&lt;br /&gt;
From the above examples, it is obvious that “Integer” type not just support ordinary methods an integer should have (such as Integer.equals), but also some more utility methods which are helpful for the programmers.&lt;br /&gt;
&lt;br /&gt;
In addition, for some data structure which only take object but not primitive type (such as Vector in Java), it is necessary to box a primitive data type to a corresponding object. For example if a programmer needs to make use of a vector to store some integer, it is necessary to box the ints and floats first:&lt;br /&gt;
&lt;br /&gt;
      Vector　v=new Vector();  &lt;br /&gt;
      int k=121; &lt;br /&gt;
      v.addElemt(new Integer(k));&lt;br /&gt;
&lt;br /&gt;
===Functionality===&lt;br /&gt;
Discussion of advantages and disadvantages should concerned the functionality you want to implement. For example if you want to operate a serials of int number. The performance of array may be better than int. &amp;lt;ref&amp;gt;http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH05/CH05-2.html Composite datatypes&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:1w1.gif]]&lt;br /&gt;
&lt;br /&gt;
To access an element of an array, you need a function that converts an array index into the address of the indexed element. For a single dimension array, this function is very simple. It is&lt;br /&gt;
Element_Address = Base_Address + ((Index - Initial_Index) * Element_Size)&lt;br /&gt;
&lt;br /&gt;
However, If you use five primitive data type to implement the same function. It may cost more time for the cpu to search the address of each data.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
In a nutshell,composite data type is more likely to stand out the features of object-oriented language and be widely used. However,primitive data type would not disappear in a foreseeable future because of its advantage in performance and use. What's more, it bridges the gap between novice programmers and experienced programmers by making powerful features basic to the language and makes coding simpler. Dealing with primitive objects is easier at times. In brief, the primitive objects help to increase the productivity of the programmers.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63502</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w21 wi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63502"/>
		<updated>2012-09-11T02:26:37Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Consistency */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Primitive objects in object-oriented languages'''&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
In any programming language, the [http://en.wikipedia.org/wiki/Data_type data type] refers to the class of data which contains specific type or range of values. Data types are used along with variables used in the program. The data type tells us what kind of values the variable can store, what is the range of the values and how much space the values take in memory etc.&lt;br /&gt;
&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Primitive_data_type primitive data types] refer to the built-in data types which are supported by the programming language. Often 'data types' and 'primitive data types' are used interchangeably. But not all data types are primitive. Programming languages have some non-primitive data types or derived data types which are provided by the language by making use of its primitive data types.&lt;br /&gt;
&lt;br /&gt;
The common built-in data types or primitive data types are integers, floating point numbers, characters, strings and boolean.&lt;br /&gt;
* Integers - Integers represent the whole numbers which can be positive or negative or zero, e.g. 9999, 0, -25, etc. &lt;br /&gt;
* Floating point numbers - Floating point numbers represent the numbers which are fractions or contain floating-decimal points, e.g. -3.002, 2.5, 22.0, etc.&lt;br /&gt;
* Characters - Characters represent any single letter, number, space, punctuation mark, or symbol that can be typed on a computer, e.g. 'a', '9', ' ', '!' , '\n', etc.&lt;br /&gt;
* Strings - Strings represent the sequences of characters or simply any text, e.g. &amp;quot;Hello!&amp;quot;, &amp;quot;9 am to 6 pm&amp;quot;, etc. &lt;br /&gt;
* Booleans - Booleans represent the true or false values. Sometimes, instead of true and false, 1 and 0 are used to represent the boolean values.&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] languages provide support for primitive data types while some object-oriented programming languages provide support for primitive objects along with primitive types.&lt;br /&gt;
&lt;br /&gt;
== Definition ==&lt;br /&gt;
&lt;br /&gt;
Primitive objects refer to the objects of built-in classes which provide more functionality than the primitive types. Some object-oriented programming languages provide support for only primitive objects (i.e., in such languages all primitive types are objects).&lt;br /&gt;
&lt;br /&gt;
Different object-oriented programming languages implement these primitive data types and primitive objects in a different manner.&lt;br /&gt;
&lt;br /&gt;
== Primitive objects in different OO languages ==&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java], there are 8 primitive types: boolean, char, byte, short, int, long, float, and double. &amp;lt;ref&amp;gt;http://www.cafeaulait.org/course/week2/02.html Java's Primitive Data Types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each of these primitive types, Java provides [http://en.wikipedia.org/wiki/Primitive_wrapper_class wrapper classes] to create primitive objects which wrap the primitive data values. A wrapper  not only contains the primitive data value, but it also defines properties and methods that can be used to manipulate that data. In Java, the primitive values are not implicitly converted to primitive objects. Instead, methods are provided for doing explicit conversion.&lt;br /&gt;
The primitive objects are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack heap] in memory while the variables containing primitive values are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack stack].&amp;lt;ref&amp;gt;http://www.informit.com/articles/article.aspx?p=31755&amp;amp;seqNum=8 Stack and Heap memory&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class!! Size&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean || 1-bit&lt;br /&gt;
|-&lt;br /&gt;
| char || Character || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| byte || Byte || 8-bit&lt;br /&gt;
|-&lt;br /&gt;
| short || Short || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| int || Integer || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| long || Long || 64-bit&lt;br /&gt;
|-&lt;br /&gt;
| float || Float || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| double || Double || 64-bit&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 20;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I+II);            &lt;br /&gt;
    System.out.println(I.equals(II));    &lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    30&lt;br /&gt;
    false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find out if these wrapper classes are primitive or not, we can use the isPrimitive() method.&lt;br /&gt;
&lt;br /&gt;
    System.out.println(INTEGER.TYPE.isPrimitive());&lt;br /&gt;
    System.out.println(BOOLEAN.TYPE.isPrimitive());&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    true&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java, the comparison operations work in the same way on the primitive objects as well as any other class objects but different on the primitive types. The == operator when used on objects checks whether they refer to the same object but when used on variables of primitive types checks whether they contain the same value.&amp;lt;ref&amp;gt;http://leepoint.net/notes-java/data/expressions/22compareobjects.html Comparisons in Java&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 10;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I==II);            &lt;br /&gt;
    System.out.println(i==ii);&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    false&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29 C#] is a [http://en.wikipedia.org/wiki/Strong_typing strongly typed] language, where it is necessary to declare the data type of a variable and also be aware of the data type conversion. C# provides a significant number of primitive data types.&amp;lt;ref&amp;gt;http://condor.depaul.edu/sjost/ndp/notes/cs1/CSDatatypes.htm C# Primitive Datatypes&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.java2s.com/Tutorial/CSharp/0040__Data-Type/PrimitivesinC.htm Primitives in C#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type. For example:&lt;br /&gt;
 &lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        int x = 7;&lt;br /&gt;
        object o = x;&lt;br /&gt;
        System.Console.WriteLine(o.ToString());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Some data types (e.g. Decimal and String) can appear like primitives at first sight, but are actually not. So it is important to exercise caution before making such assumptions. To test whether a particular type is a primitive or not you can use the property Type.IsPrimitive.&lt;br /&gt;
&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;br /&gt;
    if (t.IsPrimitive)    // where t is the type&lt;br /&gt;
    {&lt;br /&gt;
        // Is Primitive&lt;br /&gt;
    } else if (t == typeof(Decimal))&lt;br /&gt;
    {&lt;br /&gt;
        // Is Decimal&lt;br /&gt;
    } else if (t == typeof(String))&lt;br /&gt;
    {&lt;br /&gt;
        // Is String&lt;br /&gt;
    } else&lt;br /&gt;
    {&lt;br /&gt;
        // Other type&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== JavaScript ===&lt;br /&gt;
&lt;br /&gt;
There are 5 primitive data types in [http://en.wikipedia.org/wiki/JavaScript JavaScript]: string, number, boolean, null and undefined. &amp;lt;ref&amp;gt;http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html JavaScript Data Types and Variables&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For string, number and boolean values, there are corresponding classes just like in Java to create primitive objects which wrap the primitive values. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class&lt;br /&gt;
|-&lt;br /&gt;
| string || String&lt;br /&gt;
|-&lt;br /&gt;
| number|| Number&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In JavaScript, the primitive value is implicitly converted to a primitive object whenever someone tries to access a property or invoke a method on the primitive value and the primitive object is used in place of the primitive value. Since the object contains properties and methods, the use of primitive value as an object succeeds. After the property is accessed or the method is processed, the primitive object is no longer needed and hence discarded. The same is true for the other primitive types and their corresponding primitive objects.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    var upperCaseString = &amp;quot;APPLE&amp;quot;;&lt;br /&gt;
    var lowerCaseString = upperCaseString.toLowerCase();  // assigns string &amp;quot;apple&amp;quot; to lowerCaseString &lt;br /&gt;
    var s = &amp;quot;Hello&amp;quot;&lt;br /&gt;
    var len = s.length;                                   // assigns value 5 to len&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
&lt;br /&gt;
Since [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] is a [http://www.jvoegele.com/software/langcomp.html pure object oriented] language, everything in Ruby is an object. Hence, all primitive types such as integers, floating point numbers, strings, are objects of a built-in class.&amp;lt;ref&amp;gt;http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Classes in Ruby&amp;lt;/ref&amp;gt; &lt;br /&gt;
All integers are primitive objects of either class [http://corelib.rubyonrails.org/classes/Fixnum.html Fixnum] or [http://corelib.rubyonrails.org/classes/Bignum.html Bignum]. A numeric literal with a decimal point and/or an exponent is a primitive object of [http://corelib.rubyonrails.org/classes/Float.html Float]. Single quoted literals and double quoted literals are primitive objects of [http://corelib.rubyonrails.org/classes/String.html String].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    puts 10.class&lt;br /&gt;
    puts 7.45.class&lt;br /&gt;
    puts 'hi'.class&lt;br /&gt;
    puts &amp;quot;hello&amp;quot;.class&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    Fixnum&lt;br /&gt;
    Float&lt;br /&gt;
    String&lt;br /&gt;
    String&lt;br /&gt;
&lt;br /&gt;
This indicates that 10 is converted into an object of type Fixnum, 7.45 is converted into an object of type Float, 'hi' and &amp;quot;hello&amp;quot; are both converted into an object of type String.&lt;br /&gt;
&lt;br /&gt;
Since all primitive types in Ruby are objects, we should be able to call methods of the Object class on them. Let us demonstrate the same for integer and float using the following example:&lt;br /&gt;
&lt;br /&gt;
    a=10&lt;br /&gt;
    puts a.to_f  &lt;br /&gt;
    b=20.5&lt;br /&gt;
    puts b.to_i&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    10.0&lt;br /&gt;
    20&lt;br /&gt;
&lt;br /&gt;
== Advantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
Advantages that use of primitive data type offers are as follows:&lt;br /&gt;
===Consistency===&lt;br /&gt;
Many ideas of Java originate in C and in C++, objects and primitive type also co-exist. When object-oriented constructs were grafted onto the C language, C’s data types remained as is. The motivation behind this is that Bjarne Stroustrup, C++’s designer, wanted to be as consistent as possible with the base C language, hoping to capitalize on programmers’ pre-C++ knowledge.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://www.research.ibm.com/people/a/alpert/ptch/ptch.html Primitive Types Considered Harmful&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Simplicity===&lt;br /&gt;
It is simple and intuitive to use primitive data type in basic utility.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
1. Recurring number in a loop.(C++)&lt;br /&gt;
&lt;br /&gt;
   for(int i=0;i&amp;lt;10;i++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Temp variables that record only one or two data.&lt;br /&gt;
&lt;br /&gt;
===Performance===&lt;br /&gt;
&lt;br /&gt;
====Time====&lt;br /&gt;
Processing primitive data type operation would be faster than processing composite data type in most cases. There are several reasons result in this differences. &lt;br /&gt;
*Hardware processing discrepancy&lt;br /&gt;
Many primitive data operations (like integer addition) can be performed as a single machine instruction while processing of composite data type would be transformed to a combination of primitive data types. eg. Some processors offer specific instructions to process sequences of characters with a single instruction.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
[http://www.research.ibm.com/people/a/alpert/ptch/ptch.html  Difference in data fetching between primitive data and composite data in Java]&lt;br /&gt;
 &lt;br /&gt;
*Allocating and Garbage collection overhead for composite data type&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Performance_implications Garbage collection&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.ibm.com/developerworks/java/library/j-jtp01274/index.html Java theory and practice: Garbage collection and performance&amp;lt;/ref&amp;gt;&lt;br /&gt;
There are many initialization operations for composite data type that will generate high overheads for example boxing and unboxing, constructors and destructors.Composite data type like class will also have garbage collection overheads that may be beyond the control of the programmer and can sometimes lead to performance problems. For example, commonly used stop-the-world garbage collectors, which pause program execution at arbitrary times, may make garbage collection inappropriate for some [http://en.wikipedia.org/wiki/Embedded_system embedded systems], high-performance [http://en.wikipedia.org/wiki/Server_(computing)  server] software, and applications with [http://en.wikipedia.org/wiki/Real-time_computing real-time] needs.In the early days of Java technology, allocating objects got a high overheads. There were lots of articles advising developers to avoid creating temporary objects unnecessarily because allocation (and the corresponding garbage-collection overhead) was expensive. Although the costs have been greatly reduced nowadays. It still much slower than primitive data type which don’t have such troubles.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
        public class Test{&lt;br /&gt;
        double dur1,dur2;&lt;br /&gt;
        int N=100000000;&lt;br /&gt;
        public void test1()&lt;br /&gt;
        {&lt;br /&gt;
           int a=1,b=1;&lt;br /&gt;
           long startTime1 = System.currentTimeMillis();&lt;br /&gt;
           for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
              a=a+b;&lt;br /&gt;
                          }&lt;br /&gt;
           long endTime1 = System.currentTimeMillis();&lt;br /&gt;
           System.out.println(endTime1-startTime1);&lt;br /&gt;
        }&lt;br /&gt;
        public void test2(){&lt;br /&gt;
            Integer c=new Integer(1);&lt;br /&gt;
            Integer d=new Integer(1);&lt;br /&gt;
            long startTime2 = System.currentTimeMillis();&lt;br /&gt;
            for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
               c=c+d;&lt;br /&gt;
            }&lt;br /&gt;
            long endTime2 = System.currentTimeMillis();&lt;br /&gt;
            System.out.println(endTime2-startTime2)&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
Average execution time for test1 is: 1 mm&lt;br /&gt;
&lt;br /&gt;
Average execution time for test2 is: 702mm&lt;br /&gt;
&lt;br /&gt;
(test case number: 1000 times )&lt;br /&gt;
&lt;br /&gt;
====Space====&lt;br /&gt;
Composite data type will cost more memory space than primitive data type in general. The reason is not only for the overheads generated by constructors, destructors etc, but also the feature of data alignment. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding Data structure alignment&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of data alignment （C++）&lt;br /&gt;
       struct compose&lt;br /&gt;
       {&lt;br /&gt;
           char name;&lt;br /&gt;
           int a;&lt;br /&gt;
           int b;&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
We all know the size of char is 1 byte, the size of int is 4 bytes. But the size of the struct compose as shown above is 12 bytes but not 9 bytes.&lt;br /&gt;
&lt;br /&gt;
== Disdvantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
The various disadvantages of using the primitive data types are as follows:&lt;br /&gt;
&lt;br /&gt;
===Cannot be extended===&lt;br /&gt;
We can use class or array to express the intricate data or functional structure. And programmers can create subtypes, modify their operations and even redefine them. In addition with the feature of class, programmers can make their variables unchangeable to any code outside the class, or make the implementation hidden to other code with call the methods. That means with composite data types, it will be more convenient for the programmers to handle sophisticated data and also make the code easier to maintain.&lt;br /&gt;
&lt;br /&gt;
We can create a Person type in RUBY. We defined a “talk” method to make a Person can talk about himself. We also hope to only make the variable “motherland” changeable by the code outside this class.&lt;br /&gt;
&lt;br /&gt;
Example：&lt;br /&gt;
&lt;br /&gt;
       class Person&lt;br /&gt;
  &lt;br /&gt;
           def initialize( name, age=18 )&lt;br /&gt;
               @name = name&lt;br /&gt;
               @age = age&lt;br /&gt;
               @motherland = &amp;quot;US&amp;quot;&lt;br /&gt;
           end&lt;br /&gt;
  &lt;br /&gt;
           def talk&lt;br /&gt;
               puts &amp;quot;my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
               if  @motherland == &amp;quot;US&amp;quot;&lt;br /&gt;
                  puts &amp;quot;I\'m American.&amp;quot;&lt;br /&gt;
               else&lt;br /&gt;
                  puts &amp;quot;I\'m International.&amp;quot;&lt;br /&gt;
               end&lt;br /&gt;
           end&lt;br /&gt;
           attr_writer :motherland   &lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
Later when we need to create a “Student” type, we can just inherent the “Person” type and make some adjustment based on our needs. Here we redefine the “talk” method to make a student talk in a different way.&lt;br /&gt;
&lt;br /&gt;
       class Student &amp;lt; Person&lt;br /&gt;
 &lt;br /&gt;
            def talk&lt;br /&gt;
                puts &amp;quot;I am a student. my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
            end  &lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
===Uncertainty===&lt;br /&gt;
Though it means more processing time, it is necessary for programmers to create composite type to handle the data whose length is too large or changing all the time. If we have a set or integers to maintain in memory, but the number of integers will change every minute, it will be impossible if we only use primitive types to handle. But we can make use of the “Arraylist” type in Java or other composite types. With the “Arraylist”, the programmers do not need to pay attention to the storage in the memory or the space it takes. The compiler of Java will reallocate more space automatically for the Arraylist if more elements are putted. &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.5.0/docs/api/java/util/ArrayList.html uncertainty of array&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example for the insert and sorting methods of the Arraylist type in Java:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       ArrayListaList=newArrayList();&lt;br /&gt;
       aList.Add(&amp;quot;a&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;b&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;c&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;d&amp;quot;); &lt;br /&gt;
       aList.Add(&amp;quot;e&amp;quot;);&lt;br /&gt;
       aList.Sort();&lt;br /&gt;
&lt;br /&gt;
===Limitation===&lt;br /&gt;
&lt;br /&gt;
For the primitive data types in most programming languages, there are some limits of the length. For example we can put an integer between -(2^16) and (2^16)-1 into an “int” in Java. That will be enough for some most of the cases but definitely not all of them. For example, the primitive types are not able for a scientific calculation if we need an accuracy on 10^-500. And a more extreme case is to calculate the last 100 numbers for the PI has a 100 million length.&amp;lt;ref&amp;gt;http://en.verysource.com/code/1285797_1/tlargefloat.h.html limitation of primitive&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For these situations, the programmers usually need to create a composite data type by themselves. They can even redefine the operators (“+”, “-”) to make the super-long float also can make addition, subtraction with ordinary operators instead of method calling. For more details to create a super long float please see reference.&lt;br /&gt;
&lt;br /&gt;
===Cannot simplify the utility function associated with non primitive data types===&lt;br /&gt;
&lt;br /&gt;
Most of the object oriented languages have certain utility functions associated with non primitive data types that ease their use as compared to primitive data types that do not have such functions. An especially useful example is the method of parsing integers in a specified radix in Java (Integer.parseInt). &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html utility function associated with non primitive data types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
       parseInt(&amp;quot;1100110&amp;quot;, 2); //returns 102&lt;br /&gt;
       parseInt(&amp;quot;-0&amp;quot;, 10); //returns 0&lt;br /&gt;
       parseInt(&amp;quot;-FF&amp;quot;, 16); //returns -255&lt;br /&gt;
       parseInt(&amp;quot;99&amp;quot;, 8); //throws a NumberFormatException&lt;br /&gt;
&lt;br /&gt;
From the above examples, it is obvious that “Integer” type not just support ordinary methods an integer should have (such as Integer.equals), but also some more utility methods which are helpful for the programmers.&lt;br /&gt;
&lt;br /&gt;
In addition, for some data structure which only take object but not primitive type (such as Vector in Java), it is necessary to box a primitive data type to a corresponding object. For example if a programmer needs to make use of a vector to store some integer, it is necessary to box the int first:&lt;br /&gt;
&lt;br /&gt;
      Vector　v=new Vector();  &lt;br /&gt;
      int k=121; &lt;br /&gt;
      v.addElemt(new Integer(k));&lt;br /&gt;
&lt;br /&gt;
===Functionality===&lt;br /&gt;
Discussion of advantages and disadvantages should concerned the functionality you want to implement. For example if you want to operate a serials of int number. The performance of array may be better than int. &amp;lt;ref&amp;gt;http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH05/CH05-2.html composite datatypes&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:1w1.gif]]&lt;br /&gt;
&lt;br /&gt;
To access an element of an array, you need a function that converts an array index into the address of the indexed element. For a single dimension array, this function is very simple. It is&lt;br /&gt;
Element_Address = Base_Address + ((Index - Initial_Index) * Element_Size)&lt;br /&gt;
However, If you use five primitive data type to implement the same function. It may cost more time for the cpu to search the address of each data.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63501</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w21 wi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63501"/>
		<updated>2012-09-11T02:25:39Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Functionality */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Primitive objects in object-oriented languages'''&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
In any programming language, the [http://en.wikipedia.org/wiki/Data_type data type] refers to the class of data which contains specific type or range of values. Data types are used along with variables used in the program. The data type tells us what kind of values the variable can store, what is the range of the values and how much space the values take in memory etc.&lt;br /&gt;
&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Primitive_data_type primitive data types] refer to the built-in data types which are supported by the programming language. Often 'data types' and 'primitive data types' are used interchangeably. But not all data types are primitive. Programming languages have some non-primitive data types or derived data types which are provided by the language by making use of its primitive data types.&lt;br /&gt;
&lt;br /&gt;
The common built-in data types or primitive data types are integers, floating point numbers, characters, strings and boolean.&lt;br /&gt;
* Integers - Integers represent the whole numbers which can be positive or negative or zero, e.g. 9999, 0, -25, etc. &lt;br /&gt;
* Floating point numbers - Floating point numbers represent the numbers which are fractions or contain floating-decimal points, e.g. -3.002, 2.5, 22.0, etc.&lt;br /&gt;
* Characters - Characters represent any single letter, number, space, punctuation mark, or symbol that can be typed on a computer, e.g. 'a', '9', ' ', '!' , '\n', etc.&lt;br /&gt;
* Strings - Strings represent the sequences of characters or simply any text, e.g. &amp;quot;Hello!&amp;quot;, &amp;quot;9 am to 6 pm&amp;quot;, etc. &lt;br /&gt;
* Booleans - Booleans represent the true or false values. Sometimes, instead of true and false, 1 and 0 are used to represent the boolean values.&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] languages provide support for primitive data types while some object-oriented programming languages provide support for primitive objects along with primitive types.&lt;br /&gt;
&lt;br /&gt;
== Definition ==&lt;br /&gt;
&lt;br /&gt;
Primitive objects refer to the objects of built-in classes which provide more functionality than the primitive types. Some object-oriented programming languages provide support for only primitive objects (i.e., in such languages all primitive types are objects).&lt;br /&gt;
&lt;br /&gt;
Different object-oriented programming languages implement these primitive data types and primitive objects in a different manner.&lt;br /&gt;
&lt;br /&gt;
== Primitive objects in different OO languages ==&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java], there are 8 primitive types: boolean, char, byte, short, int, long, float, and double. &amp;lt;ref&amp;gt;http://www.cafeaulait.org/course/week2/02.html Java's Primitive Data Types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each of these primitive types, Java provides [http://en.wikipedia.org/wiki/Primitive_wrapper_class wrapper classes] to create primitive objects which wrap the primitive data values. A wrapper  not only contains the primitive data value, but it also defines properties and methods that can be used to manipulate that data. In Java, the primitive values are not implicitly converted to primitive objects. Instead, methods are provided for doing explicit conversion.&lt;br /&gt;
The primitive objects are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack heap] in memory while the variables containing primitive values are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack stack].&amp;lt;ref&amp;gt;http://www.informit.com/articles/article.aspx?p=31755&amp;amp;seqNum=8 Stack and Heap memory&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class!! Size&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean || 1-bit&lt;br /&gt;
|-&lt;br /&gt;
| char || Character || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| byte || Byte || 8-bit&lt;br /&gt;
|-&lt;br /&gt;
| short || Short || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| int || Integer || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| long || Long || 64-bit&lt;br /&gt;
|-&lt;br /&gt;
| float || Float || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| double || Double || 64-bit&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 20;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I+II);            &lt;br /&gt;
    System.out.println(I.equals(II));    &lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    30&lt;br /&gt;
    false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find out if these wrapper classes are primitive or not, we can use the isPrimitive() method.&lt;br /&gt;
&lt;br /&gt;
    System.out.println(INTEGER.TYPE.isPrimitive());&lt;br /&gt;
    System.out.println(BOOLEAN.TYPE.isPrimitive());&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    true&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java, the comparison operations work in the same way on the primitive objects as well as any other class objects but different on the primitive types. The == operator when used on objects checks whether they refer to the same object but when used on variables of primitive types checks whether they contain the same value.&amp;lt;ref&amp;gt;http://leepoint.net/notes-java/data/expressions/22compareobjects.html Comparisons in Java&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 10;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I==II);            &lt;br /&gt;
    System.out.println(i==ii);&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    false&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29 C#] is a [http://en.wikipedia.org/wiki/Strong_typing strongly typed] language, where it is necessary to declare the data type of a variable and also be aware of the data type conversion. C# provides a significant number of primitive data types.&amp;lt;ref&amp;gt;http://condor.depaul.edu/sjost/ndp/notes/cs1/CSDatatypes.htm C# Primitive Datatypes&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.java2s.com/Tutorial/CSharp/0040__Data-Type/PrimitivesinC.htm Primitives in C#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type. For example:&lt;br /&gt;
 &lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        int x = 7;&lt;br /&gt;
        object o = x;&lt;br /&gt;
        System.Console.WriteLine(o.ToString());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Some data types (e.g. Decimal and String) can appear like primitives at first sight, but are actually not. So it is important to exercise caution before making such assumptions. To test whether a particular type is a primitive or not you can use the property Type.IsPrimitive.&lt;br /&gt;
&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;br /&gt;
    if (t.IsPrimitive)    // where t is the type&lt;br /&gt;
    {&lt;br /&gt;
        // Is Primitive&lt;br /&gt;
    } else if (t == typeof(Decimal))&lt;br /&gt;
    {&lt;br /&gt;
        // Is Decimal&lt;br /&gt;
    } else if (t == typeof(String))&lt;br /&gt;
    {&lt;br /&gt;
        // Is String&lt;br /&gt;
    } else&lt;br /&gt;
    {&lt;br /&gt;
        // Other type&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== JavaScript ===&lt;br /&gt;
&lt;br /&gt;
There are 5 primitive data types in [http://en.wikipedia.org/wiki/JavaScript JavaScript]: string, number, boolean, null and undefined. &amp;lt;ref&amp;gt;http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html JavaScript Data Types and Variables&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For string, number and boolean values, there are corresponding classes just like in Java to create primitive objects which wrap the primitive values. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class&lt;br /&gt;
|-&lt;br /&gt;
| string || String&lt;br /&gt;
|-&lt;br /&gt;
| number|| Number&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In JavaScript, the primitive value is implicitly converted to a primitive object whenever someone tries to access a property or invoke a method on the primitive value and the primitive object is used in place of the primitive value. Since the object contains properties and methods, the use of primitive value as an object succeeds. After the property is accessed or the method is processed, the primitive object is no longer needed and hence discarded. The same is true for the other primitive types and their corresponding primitive objects.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    var upperCaseString = &amp;quot;APPLE&amp;quot;;&lt;br /&gt;
    var lowerCaseString = upperCaseString.toLowerCase();  // assigns string &amp;quot;apple&amp;quot; to lowerCaseString &lt;br /&gt;
    var s = &amp;quot;Hello&amp;quot;&lt;br /&gt;
    var len = s.length;                                   // assigns value 5 to len&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
&lt;br /&gt;
Since [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] is a [http://www.jvoegele.com/software/langcomp.html pure object oriented] language, everything in Ruby is an object. Hence, all primitive types such as integers, floating point numbers, strings, are objects of a built-in class.&amp;lt;ref&amp;gt;http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Classes in Ruby&amp;lt;/ref&amp;gt; &lt;br /&gt;
All integers are primitive objects of either class [http://corelib.rubyonrails.org/classes/Fixnum.html Fixnum] or [http://corelib.rubyonrails.org/classes/Bignum.html Bignum]. A numeric literal with a decimal point and/or an exponent is a primitive object of [http://corelib.rubyonrails.org/classes/Float.html Float]. Single quoted literals and double quoted literals are primitive objects of [http://corelib.rubyonrails.org/classes/String.html String].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    puts 10.class&lt;br /&gt;
    puts 7.45.class&lt;br /&gt;
    puts 'hi'.class&lt;br /&gt;
    puts &amp;quot;hello&amp;quot;.class&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    Fixnum&lt;br /&gt;
    Float&lt;br /&gt;
    String&lt;br /&gt;
    String&lt;br /&gt;
&lt;br /&gt;
This indicates that 10 is converted into an object of type Fixnum, 7.45 is converted into an object of type Float, 'hi' and &amp;quot;hello&amp;quot; are both converted into an object of type String.&lt;br /&gt;
&lt;br /&gt;
Since all primitive types in Ruby are objects, we should be able to call methods of the Object class on them. Let us demonstrate the same for integer and float using the following example:&lt;br /&gt;
&lt;br /&gt;
    a=10&lt;br /&gt;
    puts a.to_f  &lt;br /&gt;
    b=20.5&lt;br /&gt;
    puts b.to_i&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    10.0&lt;br /&gt;
    20&lt;br /&gt;
&lt;br /&gt;
== Advantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
Advantages that use of primitive data type offers are as follows:&lt;br /&gt;
===Consistency===&lt;br /&gt;
Many of Java’s ideas originate in C and in C++, objects and primitive type also co-exist. When object-oriented constructs were grafted onto the C language, C’s data types remained as is. The motivation behind this is that Bjarne Stroustrup, C++’s designer, wanted to be as consistent as possible with the base C language, hoping to capitalize on programmers’ pre-C++ knowledge.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://www.research.ibm.com/people/a/alpert/ptch/ptch.html Primitive Types Considered Harmful&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Simplicity===&lt;br /&gt;
It is simple and intuitive to use primitive data type in basic utility.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
1. Recurring number in a loop.(C++)&lt;br /&gt;
&lt;br /&gt;
   for(int i=0;i&amp;lt;10;i++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Temp variables that record only one or two data.&lt;br /&gt;
&lt;br /&gt;
===Performance===&lt;br /&gt;
&lt;br /&gt;
====Time====&lt;br /&gt;
Processing primitive data type operation would be faster than processing composite data type in most cases. There are several reasons result in this differences. &lt;br /&gt;
*Hardware processing discrepancy&lt;br /&gt;
Many primitive data operations (like integer addition) can be performed as a single machine instruction while processing of composite data type would be transformed to a combination of primitive data types. eg. Some processors offer specific instructions to process sequences of characters with a single instruction.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
[http://www.research.ibm.com/people/a/alpert/ptch/ptch.html  Difference in data fetching between primitive data and composite data in Java]&lt;br /&gt;
 &lt;br /&gt;
*Allocating and Garbage collection overhead for composite data type&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Performance_implications Garbage collection&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.ibm.com/developerworks/java/library/j-jtp01274/index.html Java theory and practice: Garbage collection and performance&amp;lt;/ref&amp;gt;&lt;br /&gt;
There are many initialization operations for composite data type that will generate high overheads for example boxing and unboxing, constructors and destructors.Composite data type like class will also have garbage collection overheads that may be beyond the control of the programmer and can sometimes lead to performance problems. For example, commonly used stop-the-world garbage collectors, which pause program execution at arbitrary times, may make garbage collection inappropriate for some [http://en.wikipedia.org/wiki/Embedded_system embedded systems], high-performance [http://en.wikipedia.org/wiki/Server_(computing)  server] software, and applications with [http://en.wikipedia.org/wiki/Real-time_computing real-time] needs.In the early days of Java technology, allocating objects got a high overheads. There were lots of articles advising developers to avoid creating temporary objects unnecessarily because allocation (and the corresponding garbage-collection overhead) was expensive. Although the costs have been greatly reduced nowadays. It still much slower than primitive data type which don’t have such troubles.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
        public class Test{&lt;br /&gt;
        double dur1,dur2;&lt;br /&gt;
        int N=100000000;&lt;br /&gt;
        public void test1()&lt;br /&gt;
        {&lt;br /&gt;
           int a=1,b=1;&lt;br /&gt;
           long startTime1 = System.currentTimeMillis();&lt;br /&gt;
           for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
              a=a+b;&lt;br /&gt;
                          }&lt;br /&gt;
           long endTime1 = System.currentTimeMillis();&lt;br /&gt;
           System.out.println(endTime1-startTime1);&lt;br /&gt;
        }&lt;br /&gt;
        public void test2(){&lt;br /&gt;
            Integer c=new Integer(1);&lt;br /&gt;
            Integer d=new Integer(1);&lt;br /&gt;
            long startTime2 = System.currentTimeMillis();&lt;br /&gt;
            for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
               c=c+d;&lt;br /&gt;
            }&lt;br /&gt;
            long endTime2 = System.currentTimeMillis();&lt;br /&gt;
            System.out.println(endTime2-startTime2)&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
Average execution time for test1 is: 1 mm&lt;br /&gt;
&lt;br /&gt;
Average execution time for test2 is: 702mm&lt;br /&gt;
&lt;br /&gt;
(test case number: 1000 times )&lt;br /&gt;
&lt;br /&gt;
====Space====&lt;br /&gt;
Composite data type will cost more memory space than primitive data type in general. The reason is not only for the overheads generated by constructors, destructors etc, but also the feature of data alignment. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding Data structure alignment&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of data alignment （C++）&lt;br /&gt;
       struct compose&lt;br /&gt;
       {&lt;br /&gt;
           char name;&lt;br /&gt;
           int a;&lt;br /&gt;
           int b;&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
We all know the size of char is 1 byte, the size of int is 4 bytes. But the size of the struct compose as shown above is 12 bytes but not 9 bytes.&lt;br /&gt;
&lt;br /&gt;
== Disdvantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
The various disadvantages of using the primitive data types are as follows:&lt;br /&gt;
&lt;br /&gt;
===Cannot be extended===&lt;br /&gt;
We can use class or array to express the intricate data or functional structure. And programmers can create subtypes, modify their operations and even redefine them. In addition with the feature of class, programmers can make their variables unchangeable to any code outside the class, or make the implementation hidden to other code with call the methods. That means with composite data types, it will be more convenient for the programmers to handle sophisticated data and also make the code easier to maintain.&lt;br /&gt;
&lt;br /&gt;
We can create a Person type in RUBY. We defined a “talk” method to make a Person can talk about himself. We also hope to only make the variable “motherland” changeable by the code outside this class.&lt;br /&gt;
&lt;br /&gt;
Example：&lt;br /&gt;
&lt;br /&gt;
       class Person&lt;br /&gt;
  &lt;br /&gt;
           def initialize( name, age=18 )&lt;br /&gt;
               @name = name&lt;br /&gt;
               @age = age&lt;br /&gt;
               @motherland = &amp;quot;US&amp;quot;&lt;br /&gt;
           end&lt;br /&gt;
  &lt;br /&gt;
           def talk&lt;br /&gt;
               puts &amp;quot;my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
               if  @motherland == &amp;quot;US&amp;quot;&lt;br /&gt;
                  puts &amp;quot;I\'m American.&amp;quot;&lt;br /&gt;
               else&lt;br /&gt;
                  puts &amp;quot;I\'m International.&amp;quot;&lt;br /&gt;
               end&lt;br /&gt;
           end&lt;br /&gt;
           attr_writer :motherland   &lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
Later when we need to create a “Student” type, we can just inherent the “Person” type and make some adjustment based on our needs. Here we redefine the “talk” method to make a student talk in a different way.&lt;br /&gt;
&lt;br /&gt;
       class Student &amp;lt; Person&lt;br /&gt;
 &lt;br /&gt;
            def talk&lt;br /&gt;
                puts &amp;quot;I am a student. my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
            end  &lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
===Uncertainty===&lt;br /&gt;
Though it means more processing time, it is necessary for programmers to create composite type to handle the data whose length is too large or changing all the time. If we have a set or integers to maintain in memory, but the number of integers will change every minute, it will be impossible if we only use primitive types to handle. But we can make use of the “Arraylist” type in Java or other composite types. With the “Arraylist”, the programmers do not need to pay attention to the storage in the memory or the space it takes. The compiler of Java will reallocate more space automatically for the Arraylist if more elements are putted. &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.5.0/docs/api/java/util/ArrayList.html uncertainty of array&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example for the insert and sorting methods of the Arraylist type in Java:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       ArrayListaList=newArrayList();&lt;br /&gt;
       aList.Add(&amp;quot;a&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;b&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;c&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;d&amp;quot;); &lt;br /&gt;
       aList.Add(&amp;quot;e&amp;quot;);&lt;br /&gt;
       aList.Sort();&lt;br /&gt;
&lt;br /&gt;
===Limitation===&lt;br /&gt;
&lt;br /&gt;
For the primitive data types in most programming languages, there are some limits of the length. For example we can put an integer between -(2^16) and (2^16)-1 into an “int” in Java. That will be enough for some most of the cases but definitely not all of them. For example, the primitive types are not able for a scientific calculation if we need an accuracy on 10^-500. And a more extreme case is to calculate the last 100 numbers for the PI has a 100 million length.&amp;lt;ref&amp;gt;http://en.verysource.com/code/1285797_1/tlargefloat.h.html limitation of primitive&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For these situations, the programmers usually need to create a composite data type by themselves. They can even redefine the operators (“+”, “-”) to make the super-long float also can make addition, subtraction with ordinary operators instead of method calling. For more details to create a super long float please see reference.&lt;br /&gt;
&lt;br /&gt;
===Cannot simplify the utility function associated with non primitive data types===&lt;br /&gt;
&lt;br /&gt;
Most of the object oriented languages have certain utility functions associated with non primitive data types that ease their use as compared to primitive data types that do not have such functions. An especially useful example is the method of parsing integers in a specified radix in Java (Integer.parseInt). &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html utility function associated with non primitive data types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
       parseInt(&amp;quot;1100110&amp;quot;, 2); //returns 102&lt;br /&gt;
       parseInt(&amp;quot;-0&amp;quot;, 10); //returns 0&lt;br /&gt;
       parseInt(&amp;quot;-FF&amp;quot;, 16); //returns -255&lt;br /&gt;
       parseInt(&amp;quot;99&amp;quot;, 8); //throws a NumberFormatException&lt;br /&gt;
&lt;br /&gt;
From the above examples, it is obvious that “Integer” type not just support ordinary methods an integer should have (such as Integer.equals), but also some more utility methods which are helpful for the programmers.&lt;br /&gt;
&lt;br /&gt;
In addition, for some data structure which only take object but not primitive type (such as Vector in Java), it is necessary to box a primitive data type to a corresponding object. For example if a programmer needs to make use of a vector to store some integer, it is necessary to box the int first:&lt;br /&gt;
&lt;br /&gt;
      Vector　v=new Vector();  &lt;br /&gt;
      int k=121; &lt;br /&gt;
      v.addElemt(new Integer(k));&lt;br /&gt;
&lt;br /&gt;
===Functionality===&lt;br /&gt;
Discussion of advantages and disadvantages should concerned the functionality you want to implement. For example if you want to operate a serials of int number. The performance of array may be better than int. &amp;lt;ref&amp;gt;http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH05/CH05-2.html composite datatypes&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:1w1.gif]]&lt;br /&gt;
&lt;br /&gt;
To access an element of an array, you need a function that converts an array index into the address of the indexed element. For a single dimension array, this function is very simple. It is&lt;br /&gt;
Element_Address = Base_Address + ((Index - Initial_Index) * Element_Size)&lt;br /&gt;
However, If you use five primitive data type to implement the same function. It may cost more time for the cpu to search the address of each data.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63500</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w21 wi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63500"/>
		<updated>2012-09-11T02:25:07Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Disdvantages of primitives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Primitive objects in object-oriented languages'''&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
In any programming language, the [http://en.wikipedia.org/wiki/Data_type data type] refers to the class of data which contains specific type or range of values. Data types are used along with variables used in the program. The data type tells us what kind of values the variable can store, what is the range of the values and how much space the values take in memory etc.&lt;br /&gt;
&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Primitive_data_type primitive data types] refer to the built-in data types which are supported by the programming language. Often 'data types' and 'primitive data types' are used interchangeably. But not all data types are primitive. Programming languages have some non-primitive data types or derived data types which are provided by the language by making use of its primitive data types.&lt;br /&gt;
&lt;br /&gt;
The common built-in data types or primitive data types are integers, floating point numbers, characters, strings and boolean.&lt;br /&gt;
* Integers - Integers represent the whole numbers which can be positive or negative or zero, e.g. 9999, 0, -25, etc. &lt;br /&gt;
* Floating point numbers - Floating point numbers represent the numbers which are fractions or contain floating-decimal points, e.g. -3.002, 2.5, 22.0, etc.&lt;br /&gt;
* Characters - Characters represent any single letter, number, space, punctuation mark, or symbol that can be typed on a computer, e.g. 'a', '9', ' ', '!' , '\n', etc.&lt;br /&gt;
* Strings - Strings represent the sequences of characters or simply any text, e.g. &amp;quot;Hello!&amp;quot;, &amp;quot;9 am to 6 pm&amp;quot;, etc. &lt;br /&gt;
* Booleans - Booleans represent the true or false values. Sometimes, instead of true and false, 1 and 0 are used to represent the boolean values.&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] languages provide support for primitive data types while some object-oriented programming languages provide support for primitive objects along with primitive types.&lt;br /&gt;
&lt;br /&gt;
== Definition ==&lt;br /&gt;
&lt;br /&gt;
Primitive objects refer to the objects of built-in classes which provide more functionality than the primitive types. Some object-oriented programming languages provide support for only primitive objects (i.e., in such languages all primitive types are objects).&lt;br /&gt;
&lt;br /&gt;
Different object-oriented programming languages implement these primitive data types and primitive objects in a different manner.&lt;br /&gt;
&lt;br /&gt;
== Primitive objects in different OO languages ==&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java], there are 8 primitive types: boolean, char, byte, short, int, long, float, and double. &amp;lt;ref&amp;gt;http://www.cafeaulait.org/course/week2/02.html Java's Primitive Data Types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each of these primitive types, Java provides [http://en.wikipedia.org/wiki/Primitive_wrapper_class wrapper classes] to create primitive objects which wrap the primitive data values. A wrapper  not only contains the primitive data value, but it also defines properties and methods that can be used to manipulate that data. In Java, the primitive values are not implicitly converted to primitive objects. Instead, methods are provided for doing explicit conversion.&lt;br /&gt;
The primitive objects are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack heap] in memory while the variables containing primitive values are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack stack].&amp;lt;ref&amp;gt;http://www.informit.com/articles/article.aspx?p=31755&amp;amp;seqNum=8 Stack and Heap memory&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class!! Size&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean || 1-bit&lt;br /&gt;
|-&lt;br /&gt;
| char || Character || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| byte || Byte || 8-bit&lt;br /&gt;
|-&lt;br /&gt;
| short || Short || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| int || Integer || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| long || Long || 64-bit&lt;br /&gt;
|-&lt;br /&gt;
| float || Float || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| double || Double || 64-bit&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 20;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I+II);            &lt;br /&gt;
    System.out.println(I.equals(II));    &lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    30&lt;br /&gt;
    false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find out if these wrapper classes are primitive or not, we can use the isPrimitive() method.&lt;br /&gt;
&lt;br /&gt;
    System.out.println(INTEGER.TYPE.isPrimitive());&lt;br /&gt;
    System.out.println(BOOLEAN.TYPE.isPrimitive());&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    true&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java, the comparison operations work in the same way on the primitive objects as well as any other class objects but different on the primitive types. The == operator when used on objects checks whether they refer to the same object but when used on variables of primitive types checks whether they contain the same value.&amp;lt;ref&amp;gt;http://leepoint.net/notes-java/data/expressions/22compareobjects.html Comparisons in Java&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 10;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I==II);            &lt;br /&gt;
    System.out.println(i==ii);&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    false&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29 C#] is a [http://en.wikipedia.org/wiki/Strong_typing strongly typed] language, where it is necessary to declare the data type of a variable and also be aware of the data type conversion. C# provides a significant number of primitive data types.&amp;lt;ref&amp;gt;http://condor.depaul.edu/sjost/ndp/notes/cs1/CSDatatypes.htm C# Primitive Datatypes&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.java2s.com/Tutorial/CSharp/0040__Data-Type/PrimitivesinC.htm Primitives in C#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type. For example:&lt;br /&gt;
 &lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        int x = 7;&lt;br /&gt;
        object o = x;&lt;br /&gt;
        System.Console.WriteLine(o.ToString());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Some data types (e.g. Decimal and String) can appear like primitives at first sight, but are actually not. So it is important to exercise caution before making such assumptions. To test whether a particular type is a primitive or not you can use the property Type.IsPrimitive.&lt;br /&gt;
&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;br /&gt;
    if (t.IsPrimitive)    // where t is the type&lt;br /&gt;
    {&lt;br /&gt;
        // Is Primitive&lt;br /&gt;
    } else if (t == typeof(Decimal))&lt;br /&gt;
    {&lt;br /&gt;
        // Is Decimal&lt;br /&gt;
    } else if (t == typeof(String))&lt;br /&gt;
    {&lt;br /&gt;
        // Is String&lt;br /&gt;
    } else&lt;br /&gt;
    {&lt;br /&gt;
        // Other type&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== JavaScript ===&lt;br /&gt;
&lt;br /&gt;
There are 5 primitive data types in [http://en.wikipedia.org/wiki/JavaScript JavaScript]: string, number, boolean, null and undefined. &amp;lt;ref&amp;gt;http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html JavaScript Data Types and Variables&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For string, number and boolean values, there are corresponding classes just like in Java to create primitive objects which wrap the primitive values. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class&lt;br /&gt;
|-&lt;br /&gt;
| string || String&lt;br /&gt;
|-&lt;br /&gt;
| number|| Number&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In JavaScript, the primitive value is implicitly converted to a primitive object whenever someone tries to access a property or invoke a method on the primitive value and the primitive object is used in place of the primitive value. Since the object contains properties and methods, the use of primitive value as an object succeeds. After the property is accessed or the method is processed, the primitive object is no longer needed and hence discarded. The same is true for the other primitive types and their corresponding primitive objects.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    var upperCaseString = &amp;quot;APPLE&amp;quot;;&lt;br /&gt;
    var lowerCaseString = upperCaseString.toLowerCase();  // assigns string &amp;quot;apple&amp;quot; to lowerCaseString &lt;br /&gt;
    var s = &amp;quot;Hello&amp;quot;&lt;br /&gt;
    var len = s.length;                                   // assigns value 5 to len&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
&lt;br /&gt;
Since [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] is a [http://www.jvoegele.com/software/langcomp.html pure object oriented] language, everything in Ruby is an object. Hence, all primitive types such as integers, floating point numbers, strings, are objects of a built-in class.&amp;lt;ref&amp;gt;http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Classes in Ruby&amp;lt;/ref&amp;gt; &lt;br /&gt;
All integers are primitive objects of either class [http://corelib.rubyonrails.org/classes/Fixnum.html Fixnum] or [http://corelib.rubyonrails.org/classes/Bignum.html Bignum]. A numeric literal with a decimal point and/or an exponent is a primitive object of [http://corelib.rubyonrails.org/classes/Float.html Float]. Single quoted literals and double quoted literals are primitive objects of [http://corelib.rubyonrails.org/classes/String.html String].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    puts 10.class&lt;br /&gt;
    puts 7.45.class&lt;br /&gt;
    puts 'hi'.class&lt;br /&gt;
    puts &amp;quot;hello&amp;quot;.class&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    Fixnum&lt;br /&gt;
    Float&lt;br /&gt;
    String&lt;br /&gt;
    String&lt;br /&gt;
&lt;br /&gt;
This indicates that 10 is converted into an object of type Fixnum, 7.45 is converted into an object of type Float, 'hi' and &amp;quot;hello&amp;quot; are both converted into an object of type String.&lt;br /&gt;
&lt;br /&gt;
Since all primitive types in Ruby are objects, we should be able to call methods of the Object class on them. Let us demonstrate the same for integer and float using the following example:&lt;br /&gt;
&lt;br /&gt;
    a=10&lt;br /&gt;
    puts a.to_f  &lt;br /&gt;
    b=20.5&lt;br /&gt;
    puts b.to_i&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    10.0&lt;br /&gt;
    20&lt;br /&gt;
&lt;br /&gt;
== Advantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
Advantages that use of primitive data type offers are as follows:&lt;br /&gt;
===Consistency===&lt;br /&gt;
Many of Java’s ideas originate in C and in C++, objects and primitive type also co-exist. When object-oriented constructs were grafted onto the C language, C’s data types remained as is. The motivation behind this is that Bjarne Stroustrup, C++’s designer, wanted to be as consistent as possible with the base C language, hoping to capitalize on programmers’ pre-C++ knowledge.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://www.research.ibm.com/people/a/alpert/ptch/ptch.html Primitive Types Considered Harmful&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Simplicity===&lt;br /&gt;
It is simple and intuitive to use primitive data type in basic utility.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
1. Recurring number in a loop.(C++)&lt;br /&gt;
&lt;br /&gt;
   for(int i=0;i&amp;lt;10;i++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Temp variables that record only one or two data.&lt;br /&gt;
&lt;br /&gt;
===Performance===&lt;br /&gt;
&lt;br /&gt;
====Time====&lt;br /&gt;
Processing primitive data type operation would be faster than processing composite data type in most cases. There are several reasons result in this differences. &lt;br /&gt;
*Hardware processing discrepancy&lt;br /&gt;
Many primitive data operations (like integer addition) can be performed as a single machine instruction while processing of composite data type would be transformed to a combination of primitive data types. eg. Some processors offer specific instructions to process sequences of characters with a single instruction.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
[http://www.research.ibm.com/people/a/alpert/ptch/ptch.html  Difference in data fetching between primitive data and composite data in Java]&lt;br /&gt;
 &lt;br /&gt;
*Allocating and Garbage collection overhead for composite data type&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Performance_implications Garbage collection&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.ibm.com/developerworks/java/library/j-jtp01274/index.html Java theory and practice: Garbage collection and performance&amp;lt;/ref&amp;gt;&lt;br /&gt;
There are many initialization operations for composite data type that will generate high overheads for example boxing and unboxing, constructors and destructors.Composite data type like class will also have garbage collection overheads that may be beyond the control of the programmer and can sometimes lead to performance problems. For example, commonly used stop-the-world garbage collectors, which pause program execution at arbitrary times, may make garbage collection inappropriate for some [http://en.wikipedia.org/wiki/Embedded_system embedded systems], high-performance [http://en.wikipedia.org/wiki/Server_(computing)  server] software, and applications with [http://en.wikipedia.org/wiki/Real-time_computing real-time] needs.In the early days of Java technology, allocating objects got a high overheads. There were lots of articles advising developers to avoid creating temporary objects unnecessarily because allocation (and the corresponding garbage-collection overhead) was expensive. Although the costs have been greatly reduced nowadays. It still much slower than primitive data type which don’t have such troubles.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
        public class Test{&lt;br /&gt;
        double dur1,dur2;&lt;br /&gt;
        int N=100000000;&lt;br /&gt;
        public void test1()&lt;br /&gt;
        {&lt;br /&gt;
           int a=1,b=1;&lt;br /&gt;
           long startTime1 = System.currentTimeMillis();&lt;br /&gt;
           for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
              a=a+b;&lt;br /&gt;
                          }&lt;br /&gt;
           long endTime1 = System.currentTimeMillis();&lt;br /&gt;
           System.out.println(endTime1-startTime1);&lt;br /&gt;
        }&lt;br /&gt;
        public void test2(){&lt;br /&gt;
            Integer c=new Integer(1);&lt;br /&gt;
            Integer d=new Integer(1);&lt;br /&gt;
            long startTime2 = System.currentTimeMillis();&lt;br /&gt;
            for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
               c=c+d;&lt;br /&gt;
            }&lt;br /&gt;
            long endTime2 = System.currentTimeMillis();&lt;br /&gt;
            System.out.println(endTime2-startTime2)&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
Average execution time for test1 is: 1 mm&lt;br /&gt;
&lt;br /&gt;
Average execution time for test2 is: 702mm&lt;br /&gt;
&lt;br /&gt;
(test case number: 1000 times )&lt;br /&gt;
&lt;br /&gt;
====Space====&lt;br /&gt;
Composite data type will cost more memory space than primitive data type in general. The reason is not only for the overheads generated by constructors, destructors etc, but also the feature of data alignment. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding Data structure alignment&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of data alignment （C++）&lt;br /&gt;
       struct compose&lt;br /&gt;
       {&lt;br /&gt;
           char name;&lt;br /&gt;
           int a;&lt;br /&gt;
           int b;&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
We all know the size of char is 1 byte, the size of int is 4 bytes. But the size of the struct compose as shown above is 12 bytes but not 9 bytes.&lt;br /&gt;
&lt;br /&gt;
== Disdvantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
The various disadvantages of using the primitive data types are as follows:&lt;br /&gt;
&lt;br /&gt;
===Cannot be extended===&lt;br /&gt;
We can use class or array to express the intricate data or functional structure. And programmers can create subtypes, modify their operations and even redefine them. In addition with the feature of class, programmers can make their variables unchangeable to any code outside the class, or make the implementation hidden to other code with call the methods. That means with composite data types, it will be more convenient for the programmers to handle sophisticated data and also make the code easier to maintain.&lt;br /&gt;
&lt;br /&gt;
We can create a Person type in RUBY. We defined a “talk” method to make a Person can talk about himself. We also hope to only make the variable “motherland” changeable by the code outside this class.&lt;br /&gt;
&lt;br /&gt;
Example：&lt;br /&gt;
&lt;br /&gt;
       class Person&lt;br /&gt;
  &lt;br /&gt;
           def initialize( name, age=18 )&lt;br /&gt;
               @name = name&lt;br /&gt;
               @age = age&lt;br /&gt;
               @motherland = &amp;quot;US&amp;quot;&lt;br /&gt;
           end&lt;br /&gt;
  &lt;br /&gt;
           def talk&lt;br /&gt;
               puts &amp;quot;my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
               if  @motherland == &amp;quot;US&amp;quot;&lt;br /&gt;
                  puts &amp;quot;I\'m American.&amp;quot;&lt;br /&gt;
               else&lt;br /&gt;
                  puts &amp;quot;I\'m International.&amp;quot;&lt;br /&gt;
               end&lt;br /&gt;
           end&lt;br /&gt;
           attr_writer :motherland   &lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
Later when we need to create a “Student” type, we can just inherent the “Person” type and make some adjustment based on our needs. Here we redefine the “talk” method to make a student talk in a different way.&lt;br /&gt;
&lt;br /&gt;
       class Student &amp;lt; Person&lt;br /&gt;
 &lt;br /&gt;
            def talk&lt;br /&gt;
                puts &amp;quot;I am a student. my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
            end  &lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
===Uncertainty===&lt;br /&gt;
Though it means more processing time, it is necessary for programmers to create composite type to handle the data whose length is too large or changing all the time. If we have a set or integers to maintain in memory, but the number of integers will change every minute, it will be impossible if we only use primitive types to handle. But we can make use of the “Arraylist” type in Java or other composite types. With the “Arraylist”, the programmers do not need to pay attention to the storage in the memory or the space it takes. The compiler of Java will reallocate more space automatically for the Arraylist if more elements are putted. &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.5.0/docs/api/java/util/ArrayList.html uncertainty of array&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example for the insert and sorting methods of the Arraylist type in Java:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       ArrayListaList=newArrayList();&lt;br /&gt;
       aList.Add(&amp;quot;a&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;b&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;c&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;d&amp;quot;); &lt;br /&gt;
       aList.Add(&amp;quot;e&amp;quot;);&lt;br /&gt;
       aList.Sort();&lt;br /&gt;
&lt;br /&gt;
===Limitation===&lt;br /&gt;
&lt;br /&gt;
For the primitive data types in most programming languages, there are some limits of the length. For example we can put an integer between -(2^16) and (2^16)-1 into an “int” in Java. That will be enough for some most of the cases but definitely not all of them. For example, the primitive types are not able for a scientific calculation if we need an accuracy on 10^-500. And a more extreme case is to calculate the last 100 numbers for the PI has a 100 million length.&amp;lt;ref&amp;gt;http://en.verysource.com/code/1285797_1/tlargefloat.h.html limitation of primitive&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For these situations, the programmers usually need to create a composite data type by themselves. They can even redefine the operators (“+”, “-”) to make the super-long float also can make addition, subtraction with ordinary operators instead of method calling. For more details to create a super long float please see reference.&lt;br /&gt;
&lt;br /&gt;
===Cannot simplify the utility function associated with non primitive data types===&lt;br /&gt;
&lt;br /&gt;
Most of the object oriented languages have certain utility functions associated with non primitive data types that ease their use as compared to primitive data types that do not have such functions. An especially useful example is the method of parsing integers in a specified radix in Java (Integer.parseInt). &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html utility function associated with non primitive data types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
       parseInt(&amp;quot;1100110&amp;quot;, 2); //returns 102&lt;br /&gt;
       parseInt(&amp;quot;-0&amp;quot;, 10); //returns 0&lt;br /&gt;
       parseInt(&amp;quot;-FF&amp;quot;, 16); //returns -255&lt;br /&gt;
       parseInt(&amp;quot;99&amp;quot;, 8); //throws a NumberFormatException&lt;br /&gt;
&lt;br /&gt;
From the above examples, it is obvious that “Integer” type not just support ordinary methods an integer should have (such as Integer.equals), but also some more utility methods which are helpful for the programmers.&lt;br /&gt;
&lt;br /&gt;
In addition, for some data structure which only take object but not primitive type (such as Vector in Java), it is necessary to box a primitive data type to a corresponding object. For example if a programmer needs to make use of a vector to store some integer, it is necessary to box the int first:&lt;br /&gt;
&lt;br /&gt;
      Vector　v=new Vector();  &lt;br /&gt;
      int k=121; &lt;br /&gt;
      v.addElemt(new Integer(k));&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
Discussion of advantages and disadvantages should concerned the functionality you want to implement. For example if you want to operate a serials of int number. The performance of array may be better than int. &amp;lt;ref&amp;gt;http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH05/CH05-2.html composite datatypes&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:1w1.gif]]&lt;br /&gt;
&lt;br /&gt;
To access an element of an array, you need a function that converts an array index into the address of the indexed element. For a single dimension array, this function is very simple. It is&lt;br /&gt;
Element_Address = Base_Address + ((Index - Initial_Index) * Element_Size)&lt;br /&gt;
However, If you use five primitive data type to implement the same function. It may cost more time for the cpu to search the address of each data.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63499</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w21 wi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63499"/>
		<updated>2012-09-11T02:24:43Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Functionality */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Primitive objects in object-oriented languages'''&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
In any programming language, the [http://en.wikipedia.org/wiki/Data_type data type] refers to the class of data which contains specific type or range of values. Data types are used along with variables used in the program. The data type tells us what kind of values the variable can store, what is the range of the values and how much space the values take in memory etc.&lt;br /&gt;
&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Primitive_data_type primitive data types] refer to the built-in data types which are supported by the programming language. Often 'data types' and 'primitive data types' are used interchangeably. But not all data types are primitive. Programming languages have some non-primitive data types or derived data types which are provided by the language by making use of its primitive data types.&lt;br /&gt;
&lt;br /&gt;
The common built-in data types or primitive data types are integers, floating point numbers, characters, strings and boolean.&lt;br /&gt;
* Integers - Integers represent the whole numbers which can be positive or negative or zero, e.g. 9999, 0, -25, etc. &lt;br /&gt;
* Floating point numbers - Floating point numbers represent the numbers which are fractions or contain floating-decimal points, e.g. -3.002, 2.5, 22.0, etc.&lt;br /&gt;
* Characters - Characters represent any single letter, number, space, punctuation mark, or symbol that can be typed on a computer, e.g. 'a', '9', ' ', '!' , '\n', etc.&lt;br /&gt;
* Strings - Strings represent the sequences of characters or simply any text, e.g. &amp;quot;Hello!&amp;quot;, &amp;quot;9 am to 6 pm&amp;quot;, etc. &lt;br /&gt;
* Booleans - Booleans represent the true or false values. Sometimes, instead of true and false, 1 and 0 are used to represent the boolean values.&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] languages provide support for primitive data types while some object-oriented programming languages provide support for primitive objects along with primitive types.&lt;br /&gt;
&lt;br /&gt;
== Definition ==&lt;br /&gt;
&lt;br /&gt;
Primitive objects refer to the objects of built-in classes which provide more functionality than the primitive types. Some object-oriented programming languages provide support for only primitive objects (i.e., in such languages all primitive types are objects).&lt;br /&gt;
&lt;br /&gt;
Different object-oriented programming languages implement these primitive data types and primitive objects in a different manner.&lt;br /&gt;
&lt;br /&gt;
== Primitive objects in different OO languages ==&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java], there are 8 primitive types: boolean, char, byte, short, int, long, float, and double. &amp;lt;ref&amp;gt;http://www.cafeaulait.org/course/week2/02.html Java's Primitive Data Types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each of these primitive types, Java provides [http://en.wikipedia.org/wiki/Primitive_wrapper_class wrapper classes] to create primitive objects which wrap the primitive data values. A wrapper  not only contains the primitive data value, but it also defines properties and methods that can be used to manipulate that data. In Java, the primitive values are not implicitly converted to primitive objects. Instead, methods are provided for doing explicit conversion.&lt;br /&gt;
The primitive objects are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack heap] in memory while the variables containing primitive values are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack stack].&amp;lt;ref&amp;gt;http://www.informit.com/articles/article.aspx?p=31755&amp;amp;seqNum=8 Stack and Heap memory&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class!! Size&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean || 1-bit&lt;br /&gt;
|-&lt;br /&gt;
| char || Character || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| byte || Byte || 8-bit&lt;br /&gt;
|-&lt;br /&gt;
| short || Short || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| int || Integer || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| long || Long || 64-bit&lt;br /&gt;
|-&lt;br /&gt;
| float || Float || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| double || Double || 64-bit&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 20;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I+II);            &lt;br /&gt;
    System.out.println(I.equals(II));    &lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    30&lt;br /&gt;
    false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find out if these wrapper classes are primitive or not, we can use the isPrimitive() method.&lt;br /&gt;
&lt;br /&gt;
    System.out.println(INTEGER.TYPE.isPrimitive());&lt;br /&gt;
    System.out.println(BOOLEAN.TYPE.isPrimitive());&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    true&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java, the comparison operations work in the same way on the primitive objects as well as any other class objects but different on the primitive types. The == operator when used on objects checks whether they refer to the same object but when used on variables of primitive types checks whether they contain the same value.&amp;lt;ref&amp;gt;http://leepoint.net/notes-java/data/expressions/22compareobjects.html Comparisons in Java&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 10;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I==II);            &lt;br /&gt;
    System.out.println(i==ii);&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    false&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29 C#] is a [http://en.wikipedia.org/wiki/Strong_typing strongly typed] language, where it is necessary to declare the data type of a variable and also be aware of the data type conversion. C# provides a significant number of primitive data types.&amp;lt;ref&amp;gt;http://condor.depaul.edu/sjost/ndp/notes/cs1/CSDatatypes.htm C# Primitive Datatypes&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.java2s.com/Tutorial/CSharp/0040__Data-Type/PrimitivesinC.htm Primitives in C#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type. For example:&lt;br /&gt;
 &lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        int x = 7;&lt;br /&gt;
        object o = x;&lt;br /&gt;
        System.Console.WriteLine(o.ToString());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Some data types (e.g. Decimal and String) can appear like primitives at first sight, but are actually not. So it is important to exercise caution before making such assumptions. To test whether a particular type is a primitive or not you can use the property Type.IsPrimitive.&lt;br /&gt;
&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;br /&gt;
    if (t.IsPrimitive)    // where t is the type&lt;br /&gt;
    {&lt;br /&gt;
        // Is Primitive&lt;br /&gt;
    } else if (t == typeof(Decimal))&lt;br /&gt;
    {&lt;br /&gt;
        // Is Decimal&lt;br /&gt;
    } else if (t == typeof(String))&lt;br /&gt;
    {&lt;br /&gt;
        // Is String&lt;br /&gt;
    } else&lt;br /&gt;
    {&lt;br /&gt;
        // Other type&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== JavaScript ===&lt;br /&gt;
&lt;br /&gt;
There are 5 primitive data types in [http://en.wikipedia.org/wiki/JavaScript JavaScript]: string, number, boolean, null and undefined. &amp;lt;ref&amp;gt;http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html JavaScript Data Types and Variables&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For string, number and boolean values, there are corresponding classes just like in Java to create primitive objects which wrap the primitive values. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class&lt;br /&gt;
|-&lt;br /&gt;
| string || String&lt;br /&gt;
|-&lt;br /&gt;
| number|| Number&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In JavaScript, the primitive value is implicitly converted to a primitive object whenever someone tries to access a property or invoke a method on the primitive value and the primitive object is used in place of the primitive value. Since the object contains properties and methods, the use of primitive value as an object succeeds. After the property is accessed or the method is processed, the primitive object is no longer needed and hence discarded. The same is true for the other primitive types and their corresponding primitive objects.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    var upperCaseString = &amp;quot;APPLE&amp;quot;;&lt;br /&gt;
    var lowerCaseString = upperCaseString.toLowerCase();  // assigns string &amp;quot;apple&amp;quot; to lowerCaseString &lt;br /&gt;
    var s = &amp;quot;Hello&amp;quot;&lt;br /&gt;
    var len = s.length;                                   // assigns value 5 to len&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
&lt;br /&gt;
Since [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] is a [http://www.jvoegele.com/software/langcomp.html pure object oriented] language, everything in Ruby is an object. Hence, all primitive types such as integers, floating point numbers, strings, are objects of a built-in class.&amp;lt;ref&amp;gt;http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Classes in Ruby&amp;lt;/ref&amp;gt; &lt;br /&gt;
All integers are primitive objects of either class [http://corelib.rubyonrails.org/classes/Fixnum.html Fixnum] or [http://corelib.rubyonrails.org/classes/Bignum.html Bignum]. A numeric literal with a decimal point and/or an exponent is a primitive object of [http://corelib.rubyonrails.org/classes/Float.html Float]. Single quoted literals and double quoted literals are primitive objects of [http://corelib.rubyonrails.org/classes/String.html String].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    puts 10.class&lt;br /&gt;
    puts 7.45.class&lt;br /&gt;
    puts 'hi'.class&lt;br /&gt;
    puts &amp;quot;hello&amp;quot;.class&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    Fixnum&lt;br /&gt;
    Float&lt;br /&gt;
    String&lt;br /&gt;
    String&lt;br /&gt;
&lt;br /&gt;
This indicates that 10 is converted into an object of type Fixnum, 7.45 is converted into an object of type Float, 'hi' and &amp;quot;hello&amp;quot; are both converted into an object of type String.&lt;br /&gt;
&lt;br /&gt;
Since all primitive types in Ruby are objects, we should be able to call methods of the Object class on them. Let us demonstrate the same for integer and float using the following example:&lt;br /&gt;
&lt;br /&gt;
    a=10&lt;br /&gt;
    puts a.to_f  &lt;br /&gt;
    b=20.5&lt;br /&gt;
    puts b.to_i&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    10.0&lt;br /&gt;
    20&lt;br /&gt;
&lt;br /&gt;
== Advantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
Advantages that use of primitive data type offers are as follows:&lt;br /&gt;
===Consistency===&lt;br /&gt;
Many of Java’s ideas originate in C and in C++, objects and primitive type also co-exist. When object-oriented constructs were grafted onto the C language, C’s data types remained as is. The motivation behind this is that Bjarne Stroustrup, C++’s designer, wanted to be as consistent as possible with the base C language, hoping to capitalize on programmers’ pre-C++ knowledge.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://www.research.ibm.com/people/a/alpert/ptch/ptch.html Primitive Types Considered Harmful&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Simplicity===&lt;br /&gt;
It is simple and intuitive to use primitive data type in basic utility.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
1. Recurring number in a loop.(C++)&lt;br /&gt;
&lt;br /&gt;
   for(int i=0;i&amp;lt;10;i++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Temp variables that record only one or two data.&lt;br /&gt;
&lt;br /&gt;
===Performance===&lt;br /&gt;
&lt;br /&gt;
====Time====&lt;br /&gt;
Processing primitive data type operation would be faster than processing composite data type in most cases. There are several reasons result in this differences. &lt;br /&gt;
*Hardware processing discrepancy&lt;br /&gt;
Many primitive data operations (like integer addition) can be performed as a single machine instruction while processing of composite data type would be transformed to a combination of primitive data types. eg. Some processors offer specific instructions to process sequences of characters with a single instruction.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
[http://www.research.ibm.com/people/a/alpert/ptch/ptch.html  Difference in data fetching between primitive data and composite data in Java]&lt;br /&gt;
 &lt;br /&gt;
*Allocating and Garbage collection overhead for composite data type&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Performance_implications Garbage collection&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.ibm.com/developerworks/java/library/j-jtp01274/index.html Java theory and practice: Garbage collection and performance&amp;lt;/ref&amp;gt;&lt;br /&gt;
There are many initialization operations for composite data type that will generate high overheads for example boxing and unboxing, constructors and destructors.Composite data type like class will also have garbage collection overheads that may be beyond the control of the programmer and can sometimes lead to performance problems. For example, commonly used stop-the-world garbage collectors, which pause program execution at arbitrary times, may make garbage collection inappropriate for some [http://en.wikipedia.org/wiki/Embedded_system embedded systems], high-performance [http://en.wikipedia.org/wiki/Server_(computing)  server] software, and applications with [http://en.wikipedia.org/wiki/Real-time_computing real-time] needs.In the early days of Java technology, allocating objects got a high overheads. There were lots of articles advising developers to avoid creating temporary objects unnecessarily because allocation (and the corresponding garbage-collection overhead) was expensive. Although the costs have been greatly reduced nowadays. It still much slower than primitive data type which don’t have such troubles.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
        public class Test{&lt;br /&gt;
        double dur1,dur2;&lt;br /&gt;
        int N=100000000;&lt;br /&gt;
        public void test1()&lt;br /&gt;
        {&lt;br /&gt;
           int a=1,b=1;&lt;br /&gt;
           long startTime1 = System.currentTimeMillis();&lt;br /&gt;
           for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
              a=a+b;&lt;br /&gt;
                          }&lt;br /&gt;
           long endTime1 = System.currentTimeMillis();&lt;br /&gt;
           System.out.println(endTime1-startTime1);&lt;br /&gt;
        }&lt;br /&gt;
        public void test2(){&lt;br /&gt;
            Integer c=new Integer(1);&lt;br /&gt;
            Integer d=new Integer(1);&lt;br /&gt;
            long startTime2 = System.currentTimeMillis();&lt;br /&gt;
            for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
               c=c+d;&lt;br /&gt;
            }&lt;br /&gt;
            long endTime2 = System.currentTimeMillis();&lt;br /&gt;
            System.out.println(endTime2-startTime2)&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
Average execution time for test1 is: 1 mm&lt;br /&gt;
&lt;br /&gt;
Average execution time for test2 is: 702mm&lt;br /&gt;
&lt;br /&gt;
(test case number: 1000 times )&lt;br /&gt;
&lt;br /&gt;
====Space====&lt;br /&gt;
Composite data type will cost more memory space than primitive data type in general. The reason is not only for the overheads generated by constructors, destructors etc, but also the feature of data alignment. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding Data structure alignment&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of data alignment （C++）&lt;br /&gt;
       struct compose&lt;br /&gt;
       {&lt;br /&gt;
           char name;&lt;br /&gt;
           int a;&lt;br /&gt;
           int b;&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
We all know the size of char is 1 byte, the size of int is 4 bytes. But the size of the struct compose as shown above is 12 bytes but not 9 bytes.&lt;br /&gt;
&lt;br /&gt;
== Disdvantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
The various disadvantages of using the primitive data types are as follows:&lt;br /&gt;
&lt;br /&gt;
===Cannot be extended===&lt;br /&gt;
We can use class or array to express the intricate data or functional structure. And programmers can create subtypes, modify their operations and even redefine them. In addition with the feature of class, programmers can make their variables unchangeable to any code outside the class, or make the implementation hidden to other code with call the methods. That means with composite data types, it will be more convenient for the programmers to handle sophisticated data and also make the code easier to maintain.&lt;br /&gt;
&lt;br /&gt;
We can create a Person type in RUBY. We defined a “talk” method to make a Person can talk about himself. We also hope to only make the variable “motherland” changeable by the code outside this class.&lt;br /&gt;
&lt;br /&gt;
Example：&lt;br /&gt;
&lt;br /&gt;
       class Person&lt;br /&gt;
  &lt;br /&gt;
           def initialize( name, age=18 )&lt;br /&gt;
               @name = name&lt;br /&gt;
               @age = age&lt;br /&gt;
               @motherland = &amp;quot;US&amp;quot;&lt;br /&gt;
           end&lt;br /&gt;
  &lt;br /&gt;
           def talk&lt;br /&gt;
               puts &amp;quot;my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
               if  @motherland == &amp;quot;US&amp;quot;&lt;br /&gt;
                  puts &amp;quot;I\'m American.&amp;quot;&lt;br /&gt;
               else&lt;br /&gt;
                  puts &amp;quot;I\'m International.&amp;quot;&lt;br /&gt;
               end&lt;br /&gt;
           end&lt;br /&gt;
           attr_writer :motherland   &lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
Later when we need to create a “Student” type, we can just inherent the “Person” type and make some adjustment based on our needs. Here we redefine the “talk” method to make a student talk in a different way.&lt;br /&gt;
&lt;br /&gt;
       class Student &amp;lt; Person&lt;br /&gt;
 &lt;br /&gt;
            def talk&lt;br /&gt;
                puts &amp;quot;I am a student. my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
            end  &lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
===Uncertainty===&lt;br /&gt;
Though it means more processing time, it is necessary for programmers to create composite type to handle the data whose length is too large or changing all the time. If we have a set or integers to maintain in memory, but the number of integers will change every minute, it will be impossible if we only use primitive types to handle. But we can make use of the “Arraylist” type in Java or other composite types. With the “Arraylist”, the programmers do not need to pay attention to the storage in the memory or the space it takes. The compiler of Java will reallocate more space automatically for the Arraylist if more elements are putted. &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.5.0/docs/api/java/util/ArrayList.html uncertainty of array&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example for the insert and sorting methods of the Arraylist type in Java:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       ArrayListaList=newArrayList();&lt;br /&gt;
       aList.Add(&amp;quot;a&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;b&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;c&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;d&amp;quot;); &lt;br /&gt;
       aList.Add(&amp;quot;e&amp;quot;);&lt;br /&gt;
       aList.Sort();&lt;br /&gt;
&lt;br /&gt;
===Limitation===&lt;br /&gt;
&lt;br /&gt;
For the primitive data types in most programming languages, there are some limits of the length. For example we can put an integer between -(2^16) and (2^16)-1 into an “int” in Java. That will be enough for some most of the cases but definitely not all of them. For example, the primitive types are not able for a scientific calculation if we need an accuracy on 10^-500. And a more extreme case is to calculate the last 100 numbers for the PI has a 100 million length.&amp;lt;ref&amp;gt;http://en.verysource.com/code/1285797_1/tlargefloat.h.html limitation of primitive&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For these situations, the programmers usually need to create a composite data type by themselves. They can even redefine the operators (“+”, “-”) to make the super-long float also can make addition, subtraction with ordinary operators instead of method calling. For more details to create a super long float please see reference.&lt;br /&gt;
&lt;br /&gt;
===Cannot simplify the utility function associated with non primitive data types===&lt;br /&gt;
&lt;br /&gt;
Most of the object oriented languages have certain utility functions associated with non primitive data types that ease their use as compared to primitive data types that do not have such functions. An especially useful example is the method of parsing integers in a specified radix in Java (Integer.parseInt). &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html utility function associated with non primitive data types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
       parseInt(&amp;quot;1100110&amp;quot;, 2); //returns 102&lt;br /&gt;
       parseInt(&amp;quot;-0&amp;quot;, 10); //returns 0&lt;br /&gt;
       parseInt(&amp;quot;-FF&amp;quot;, 16); //returns -255&lt;br /&gt;
       parseInt(&amp;quot;99&amp;quot;, 8); //throws a NumberFormatException&lt;br /&gt;
&lt;br /&gt;
From the above examples, it is obvious that “Integer” type not just support ordinary methods an integer should have (such as Integer.equals), but also some more utility methods which are helpful for the programmers.&lt;br /&gt;
&lt;br /&gt;
In addition, for some data structure which only take object but not primitive type (such as Vector in Java), it is necessary to box a primitive data type to a corresponding object. For example if a programmer needs to make use of a vector to store some integer, it is necessary to box the int first:&lt;br /&gt;
&lt;br /&gt;
      Vector　v=new Vector();  &lt;br /&gt;
      int k=121; &lt;br /&gt;
      v.addElemt(new Integer(k));&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63498</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w21 wi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63498"/>
		<updated>2012-09-11T02:21:39Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Time */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Primitive objects in object-oriented languages'''&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
In any programming language, the [http://en.wikipedia.org/wiki/Data_type data type] refers to the class of data which contains specific type or range of values. Data types are used along with variables used in the program. The data type tells us what kind of values the variable can store, what is the range of the values and how much space the values take in memory etc.&lt;br /&gt;
&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Primitive_data_type primitive data types] refer to the built-in data types which are supported by the programming language. Often 'data types' and 'primitive data types' are used interchangeably. But not all data types are primitive. Programming languages have some non-primitive data types or derived data types which are provided by the language by making use of its primitive data types.&lt;br /&gt;
&lt;br /&gt;
The common built-in data types or primitive data types are integers, floating point numbers, characters, strings and boolean.&lt;br /&gt;
* Integers - Integers represent the whole numbers which can be positive or negative or zero, e.g. 9999, 0, -25, etc. &lt;br /&gt;
* Floating point numbers - Floating point numbers represent the numbers which are fractions or contain floating-decimal points, e.g. -3.002, 2.5, 22.0, etc.&lt;br /&gt;
* Characters - Characters represent any single letter, number, space, punctuation mark, or symbol that can be typed on a computer, e.g. 'a', '9', ' ', '!' , '\n', etc.&lt;br /&gt;
* Strings - Strings represent the sequences of characters or simply any text, e.g. &amp;quot;Hello!&amp;quot;, &amp;quot;9 am to 6 pm&amp;quot;, etc. &lt;br /&gt;
* Booleans - Booleans represent the true or false values. Sometimes, instead of true and false, 1 and 0 are used to represent the boolean values.&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] languages provide support for primitive data types while some object-oriented programming languages provide support for primitive objects along with primitive types.&lt;br /&gt;
&lt;br /&gt;
== Definition ==&lt;br /&gt;
&lt;br /&gt;
Primitive objects refer to the objects of built-in classes which provide more functionality than the primitive types. Some object-oriented programming languages provide support for only primitive objects (i.e., in such languages all primitive types are objects).&lt;br /&gt;
&lt;br /&gt;
Different object-oriented programming languages implement these primitive data types and primitive objects in a different manner.&lt;br /&gt;
&lt;br /&gt;
== Primitive objects in different OO languages ==&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java], there are 8 primitive types: boolean, char, byte, short, int, long, float, and double. &amp;lt;ref&amp;gt;http://www.cafeaulait.org/course/week2/02.html Java's Primitive Data Types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each of these primitive types, Java provides [http://en.wikipedia.org/wiki/Primitive_wrapper_class wrapper classes] to create primitive objects which wrap the primitive data values. A wrapper  not only contains the primitive data value, but it also defines properties and methods that can be used to manipulate that data. In Java, the primitive values are not implicitly converted to primitive objects. Instead, methods are provided for doing explicit conversion.&lt;br /&gt;
The primitive objects are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack heap] in memory while the variables containing primitive values are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack stack].&amp;lt;ref&amp;gt;http://www.informit.com/articles/article.aspx?p=31755&amp;amp;seqNum=8 Stack and Heap memory&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class!! Size&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean || 1-bit&lt;br /&gt;
|-&lt;br /&gt;
| char || Character || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| byte || Byte || 8-bit&lt;br /&gt;
|-&lt;br /&gt;
| short || Short || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| int || Integer || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| long || Long || 64-bit&lt;br /&gt;
|-&lt;br /&gt;
| float || Float || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| double || Double || 64-bit&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 20;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I+II);            &lt;br /&gt;
    System.out.println(I.equals(II));    &lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    30&lt;br /&gt;
    false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find out if these wrapper classes are primitive or not, we can use the isPrimitive() method.&lt;br /&gt;
&lt;br /&gt;
    System.out.println(INTEGER.TYPE.isPrimitive());&lt;br /&gt;
    System.out.println(BOOLEAN.TYPE.isPrimitive());&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    true&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java, the comparison operations work in the same way on the primitive objects as well as any other class objects but different on the primitive types. The == operator when used on objects checks whether they refer to the same object but when used on variables of primitive types checks whether they contain the same value.&amp;lt;ref&amp;gt;http://leepoint.net/notes-java/data/expressions/22compareobjects.html Comparisons in Java&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 10;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I==II);            &lt;br /&gt;
    System.out.println(i==ii);&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    false&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29 C#] is a [http://en.wikipedia.org/wiki/Strong_typing strongly typed] language, where it is necessary to declare the data type of a variable and also be aware of the data type conversion. C# provides a significant number of primitive data types.&amp;lt;ref&amp;gt;http://condor.depaul.edu/sjost/ndp/notes/cs1/CSDatatypes.htm C# Primitive Datatypes&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.java2s.com/Tutorial/CSharp/0040__Data-Type/PrimitivesinC.htm Primitives in C#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type. For example:&lt;br /&gt;
 &lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        int x = 7;&lt;br /&gt;
        object o = x;&lt;br /&gt;
        System.Console.WriteLine(o.ToString());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Some data types (e.g. Decimal and String) can appear like primitives at first sight, but are actually not. So it is important to exercise caution before making such assumptions. To test whether a particular type is a primitive or not you can use the property Type.IsPrimitive.&lt;br /&gt;
&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;br /&gt;
    if (t.IsPrimitive)    // where t is the type&lt;br /&gt;
    {&lt;br /&gt;
        // Is Primitive&lt;br /&gt;
    } else if (t == typeof(Decimal))&lt;br /&gt;
    {&lt;br /&gt;
        // Is Decimal&lt;br /&gt;
    } else if (t == typeof(String))&lt;br /&gt;
    {&lt;br /&gt;
        // Is String&lt;br /&gt;
    } else&lt;br /&gt;
    {&lt;br /&gt;
        // Other type&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== JavaScript ===&lt;br /&gt;
&lt;br /&gt;
There are 5 primitive data types in [http://en.wikipedia.org/wiki/JavaScript JavaScript]: string, number, boolean, null and undefined. &amp;lt;ref&amp;gt;http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html JavaScript Data Types and Variables&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For string, number and boolean values, there are corresponding classes just like in Java to create primitive objects which wrap the primitive values. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class&lt;br /&gt;
|-&lt;br /&gt;
| string || String&lt;br /&gt;
|-&lt;br /&gt;
| number|| Number&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In JavaScript, the primitive value is implicitly converted to a primitive object whenever someone tries to access a property or invoke a method on the primitive value and the primitive object is used in place of the primitive value. Since the object contains properties and methods, the use of primitive value as an object succeeds. After the property is accessed or the method is processed, the primitive object is no longer needed and hence discarded. The same is true for the other primitive types and their corresponding primitive objects.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    var upperCaseString = &amp;quot;APPLE&amp;quot;;&lt;br /&gt;
    var lowerCaseString = upperCaseString.toLowerCase();  // assigns string &amp;quot;apple&amp;quot; to lowerCaseString &lt;br /&gt;
    var s = &amp;quot;Hello&amp;quot;&lt;br /&gt;
    var len = s.length;                                   // assigns value 5 to len&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
&lt;br /&gt;
Since [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] is a [http://www.jvoegele.com/software/langcomp.html pure object oriented] language, everything in Ruby is an object. Hence, all primitive types such as integers, floating point numbers, strings, are objects of a built-in class.&amp;lt;ref&amp;gt;http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Classes in Ruby&amp;lt;/ref&amp;gt; &lt;br /&gt;
All integers are primitive objects of either class [http://corelib.rubyonrails.org/classes/Fixnum.html Fixnum] or [http://corelib.rubyonrails.org/classes/Bignum.html Bignum]. A numeric literal with a decimal point and/or an exponent is a primitive object of [http://corelib.rubyonrails.org/classes/Float.html Float]. Single quoted literals and double quoted literals are primitive objects of [http://corelib.rubyonrails.org/classes/String.html String].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    puts 10.class&lt;br /&gt;
    puts 7.45.class&lt;br /&gt;
    puts 'hi'.class&lt;br /&gt;
    puts &amp;quot;hello&amp;quot;.class&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    Fixnum&lt;br /&gt;
    Float&lt;br /&gt;
    String&lt;br /&gt;
    String&lt;br /&gt;
&lt;br /&gt;
This indicates that 10 is converted into an object of type Fixnum, 7.45 is converted into an object of type Float, 'hi' and &amp;quot;hello&amp;quot; are both converted into an object of type String.&lt;br /&gt;
&lt;br /&gt;
Since all primitive types in Ruby are objects, we should be able to call methods of the Object class on them. Let us demonstrate the same for integer and float using the following example:&lt;br /&gt;
&lt;br /&gt;
    a=10&lt;br /&gt;
    puts a.to_f  &lt;br /&gt;
    b=20.5&lt;br /&gt;
    puts b.to_i&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    10.0&lt;br /&gt;
    20&lt;br /&gt;
&lt;br /&gt;
== Advantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
Advantages that use of primitive data type offers are as follows:&lt;br /&gt;
===Consistency===&lt;br /&gt;
Many of Java’s ideas originate in C and in C++, objects and primitive type also co-exist. When object-oriented constructs were grafted onto the C language, C’s data types remained as is. The motivation behind this is that Bjarne Stroustrup, C++’s designer, wanted to be as consistent as possible with the base C language, hoping to capitalize on programmers’ pre-C++ knowledge.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://www.research.ibm.com/people/a/alpert/ptch/ptch.html Primitive Types Considered Harmful&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Simplicity===&lt;br /&gt;
It is simple and intuitive to use primitive data type in basic utility.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
1. Recurring number in a loop.(C++)&lt;br /&gt;
&lt;br /&gt;
   for(int i=0;i&amp;lt;10;i++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Temp variables that record only one or two data.&lt;br /&gt;
&lt;br /&gt;
===Performance===&lt;br /&gt;
&lt;br /&gt;
====Time====&lt;br /&gt;
Processing primitive data type operation would be faster than processing composite data type in most cases. There are several reasons result in this differences. &lt;br /&gt;
*Hardware processing discrepancy&lt;br /&gt;
Many primitive data operations (like integer addition) can be performed as a single machine instruction while processing of composite data type would be transformed to a combination of primitive data types. eg. Some processors offer specific instructions to process sequences of characters with a single instruction.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
[http://www.research.ibm.com/people/a/alpert/ptch/ptch.html  Difference in data fetching between primitive data and composite data in Java]&lt;br /&gt;
 &lt;br /&gt;
*Allocating and Garbage collection overhead for composite data type&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Performance_implications Garbage collection&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.ibm.com/developerworks/java/library/j-jtp01274/index.html Java theory and practice: Garbage collection and performance&amp;lt;/ref&amp;gt;&lt;br /&gt;
There are many initialization operations for composite data type that will generate high overheads for example boxing and unboxing, constructors and destructors.Composite data type like class will also have garbage collection overheads that may be beyond the control of the programmer and can sometimes lead to performance problems. For example, commonly used stop-the-world garbage collectors, which pause program execution at arbitrary times, may make garbage collection inappropriate for some [http://en.wikipedia.org/wiki/Embedded_system embedded systems], high-performance [http://en.wikipedia.org/wiki/Server_(computing)  server] software, and applications with [http://en.wikipedia.org/wiki/Real-time_computing real-time] needs.In the early days of Java technology, allocating objects got a high overheads. There were lots of articles advising developers to avoid creating temporary objects unnecessarily because allocation (and the corresponding garbage-collection overhead) was expensive. Although the costs have been greatly reduced nowadays. It still much slower than primitive data type which don’t have such troubles.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
        public class Test{&lt;br /&gt;
        double dur1,dur2;&lt;br /&gt;
        int N=100000000;&lt;br /&gt;
        public void test1()&lt;br /&gt;
        {&lt;br /&gt;
           int a=1,b=1;&lt;br /&gt;
           long startTime1 = System.currentTimeMillis();&lt;br /&gt;
           for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
              a=a+b;&lt;br /&gt;
                          }&lt;br /&gt;
           long endTime1 = System.currentTimeMillis();&lt;br /&gt;
           System.out.println(endTime1-startTime1);&lt;br /&gt;
        }&lt;br /&gt;
        public void test2(){&lt;br /&gt;
            Integer c=new Integer(1);&lt;br /&gt;
            Integer d=new Integer(1);&lt;br /&gt;
            long startTime2 = System.currentTimeMillis();&lt;br /&gt;
            for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
               c=c+d;&lt;br /&gt;
            }&lt;br /&gt;
            long endTime2 = System.currentTimeMillis();&lt;br /&gt;
            System.out.println(endTime2-startTime2)&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
Average execution time for test1 is: 1 mm&lt;br /&gt;
&lt;br /&gt;
Average execution time for test2 is: 702mm&lt;br /&gt;
&lt;br /&gt;
(test case number: 1000 times )&lt;br /&gt;
&lt;br /&gt;
====Space====&lt;br /&gt;
Composite data type will cost more memory space than primitive data type in general. The reason is not only for the overheads generated by constructors, destructors etc, but also the feature of data alignment. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding Data structure alignment&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of data alignment （C++）&lt;br /&gt;
       struct compose&lt;br /&gt;
       {&lt;br /&gt;
           char name;&lt;br /&gt;
           int a;&lt;br /&gt;
           int b;&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
We all know the size of char is 1 byte, the size of int is 4 bytes. But the size of the struct compose as shown above is 12 bytes but not 9 bytes.&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
Discussion of advantages and disadvantages should concerned the functionality you want to implement. For example if you want to operate a serials of int number. The performance of array may be better than int. &amp;lt;ref&amp;gt;http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH05/CH05-2.html composite datatypes&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:1w1.gif]]&lt;br /&gt;
&lt;br /&gt;
To access an element of an array, you need a function that converts an array index into the address of the indexed element. For a single dimension array, this function is very simple. It is&lt;br /&gt;
Element_Address = Base_Address + ((Index - Initial_Index) * Element_Size)&lt;br /&gt;
However, If you use five primitive data type to implement the same function. It may cost more time for the cpu to search the address of each data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Disdvantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
The various disadvantages of using the primitive data types are as follows:&lt;br /&gt;
&lt;br /&gt;
===Cannot be extended===&lt;br /&gt;
We can use class or array to express the intricate data or functional structure. And programmers can create subtypes, modify their operations and even redefine them. In addition with the feature of class, programmers can make their variables unchangeable to any code outside the class, or make the implementation hidden to other code with call the methods. That means with composite data types, it will be more convenient for the programmers to handle sophisticated data and also make the code easier to maintain.&lt;br /&gt;
&lt;br /&gt;
We can create a Person type in RUBY. We defined a “talk” method to make a Person can talk about himself. We also hope to only make the variable “motherland” changeable by the code outside this class.&lt;br /&gt;
&lt;br /&gt;
Example：&lt;br /&gt;
&lt;br /&gt;
       class Person&lt;br /&gt;
  &lt;br /&gt;
           def initialize( name, age=18 )&lt;br /&gt;
               @name = name&lt;br /&gt;
               @age = age&lt;br /&gt;
               @motherland = &amp;quot;US&amp;quot;&lt;br /&gt;
           end&lt;br /&gt;
  &lt;br /&gt;
           def talk&lt;br /&gt;
               puts &amp;quot;my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
               if  @motherland == &amp;quot;US&amp;quot;&lt;br /&gt;
                  puts &amp;quot;I\'m American.&amp;quot;&lt;br /&gt;
               else&lt;br /&gt;
                  puts &amp;quot;I\'m International.&amp;quot;&lt;br /&gt;
               end&lt;br /&gt;
           end&lt;br /&gt;
           attr_writer :motherland   &lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
Later when we need to create a “Student” type, we can just inherent the “Person” type and make some adjustment based on our needs. Here we redefine the “talk” method to make a student talk in a different way.&lt;br /&gt;
&lt;br /&gt;
       class Student &amp;lt; Person&lt;br /&gt;
 &lt;br /&gt;
            def talk&lt;br /&gt;
                puts &amp;quot;I am a student. my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
            end  &lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
===Uncertainty===&lt;br /&gt;
Though it means more processing time, it is necessary for programmers to create composite type to handle the data whose length is too large or changing all the time. If we have a set or integers to maintain in memory, but the number of integers will change every minute, it will be impossible if we only use primitive types to handle. But we can make use of the “Arraylist” type in Java or other composite types. With the “Arraylist”, the programmers do not need to pay attention to the storage in the memory or the space it takes. The compiler of Java will reallocate more space automatically for the Arraylist if more elements are putted. &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.5.0/docs/api/java/util/ArrayList.html uncertainty of array&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example for the insert and sorting methods of the Arraylist type in Java:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       ArrayListaList=newArrayList();&lt;br /&gt;
       aList.Add(&amp;quot;a&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;b&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;c&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;d&amp;quot;); &lt;br /&gt;
       aList.Add(&amp;quot;e&amp;quot;);&lt;br /&gt;
       aList.Sort();&lt;br /&gt;
&lt;br /&gt;
===Limitation===&lt;br /&gt;
&lt;br /&gt;
For the primitive data types in most programming languages, there are some limits of the length. For example we can put an integer between -(2^16) and (2^16)-1 into an “int” in Java. That will be enough for some most of the cases but definitely not all of them. For example, the primitive types are not able for a scientific calculation if we need an accuracy on 10^-500. And a more extreme case is to calculate the last 100 numbers for the PI has a 100 million length.&amp;lt;ref&amp;gt;http://en.verysource.com/code/1285797_1/tlargefloat.h.html limitation of primitive&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For these situations, the programmers usually need to create a composite data type by themselves. They can even redefine the operators (“+”, “-”) to make the super-long float also can make addition, subtraction with ordinary operators instead of method calling. For more details to create a super long float please see reference.&lt;br /&gt;
&lt;br /&gt;
===Cannot simplify the utility function associated with non primitive data types===&lt;br /&gt;
&lt;br /&gt;
Most of the object oriented languages have certain utility functions associated with non primitive data types that ease their use as compared to primitive data types that do not have such functions. An especially useful example is the method of parsing integers in a specified radix in Java (Integer.parseInt). &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html utility function associated with non primitive data types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
       parseInt(&amp;quot;1100110&amp;quot;, 2); //returns 102&lt;br /&gt;
       parseInt(&amp;quot;-0&amp;quot;, 10); //returns 0&lt;br /&gt;
       parseInt(&amp;quot;-FF&amp;quot;, 16); //returns -255&lt;br /&gt;
       parseInt(&amp;quot;99&amp;quot;, 8); //throws a NumberFormatException&lt;br /&gt;
&lt;br /&gt;
From the above examples, it is obvious that “Integer” type not just support ordinary methods an integer should have (such as Integer.equals), but also some more utility methods which are helpful for the programmers.&lt;br /&gt;
&lt;br /&gt;
In addition, for some data structure which only take object but not primitive type (such as Vector in Java), it is necessary to box a primitive data type to a corresponding object. For example if a programmer needs to make use of a vector to store some integer, it is necessary to box the int first:&lt;br /&gt;
&lt;br /&gt;
      Vector　v=new Vector();  &lt;br /&gt;
      int k=121; &lt;br /&gt;
      v.addElemt(new Integer(k));&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63496</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w21 wi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63496"/>
		<updated>2012-09-11T02:18:01Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* cannot simplify the utility function associated with non primitive data types */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Primitive objects in object-oriented languages'''&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
In any programming language, the [http://en.wikipedia.org/wiki/Data_type data type] refers to the class of data which contains specific type or range of values. Data types are used along with variables used in the program. The data type tells us what kind of values the variable can store, what is the range of the values and how much space the values take in memory etc.&lt;br /&gt;
&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Primitive_data_type primitive data types] refer to the built-in data types which are supported by the programming language. Often 'data types' and 'primitive data types' are used interchangeably. But not all data types are primitive. Programming languages have some non-primitive data types or derived data types which are provided by the language by making use of its primitive data types.&lt;br /&gt;
&lt;br /&gt;
The common built-in data types or primitive data types are integers, floating point numbers, characters, strings and boolean.&lt;br /&gt;
* Integers - Integers represent the whole numbers which can be positive or negative or zero, e.g. 9999, 0, -25, etc. &lt;br /&gt;
* Floating point numbers - Floating point numbers represent the numbers which are fractions or contain floating-decimal points, e.g. -3.002, 2.5, 22.0, etc.&lt;br /&gt;
* Characters - Characters represent any single letter, number, space, punctuation mark, or symbol that can be typed on a computer, e.g. 'a', '9', ' ', '!' , '\n', etc.&lt;br /&gt;
* Strings - Strings represent the sequences of characters or simply any text, e.g. &amp;quot;Hello!&amp;quot;, &amp;quot;9 am to 6 pm&amp;quot;, etc. &lt;br /&gt;
* Booleans - Booleans represent the true or false values. Sometimes, instead of true and false, 1 and 0 are used to represent the boolean values.&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] languages provide support for primitive data types while some object-oriented programming languages provide support for primitive objects along with primitive types.&lt;br /&gt;
&lt;br /&gt;
== Definition ==&lt;br /&gt;
&lt;br /&gt;
Primitive objects refer to the objects of built-in classes which provide more functionality than the primitive types. Some object-oriented programming languages provide support for only primitive objects (i.e., in such languages all primitive types are objects).&lt;br /&gt;
&lt;br /&gt;
Different object-oriented programming languages implement these primitive data types and primitive objects in a different manner.&lt;br /&gt;
&lt;br /&gt;
== Primitive objects in different OO languages ==&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java], there are 8 primitive types: boolean, char, byte, short, int, long, float, and double. &amp;lt;ref&amp;gt;http://www.cafeaulait.org/course/week2/02.html Java's Primitive Data Types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each of these primitive types, Java provides [http://en.wikipedia.org/wiki/Primitive_wrapper_class wrapper classes] to create primitive objects which wrap the primitive data values. A wrapper  not only contains the primitive data value, but it also defines properties and methods that can be used to manipulate that data. In Java, the primitive values are not implicitly converted to primitive objects. Instead, methods are provided for doing explicit conversion.&lt;br /&gt;
The primitive objects are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack heap] in memory while the variables containing primitive values are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack stack].&amp;lt;ref&amp;gt;http://www.informit.com/articles/article.aspx?p=31755&amp;amp;seqNum=8 Stack and Heap memory&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class!! Size&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean || 1-bit&lt;br /&gt;
|-&lt;br /&gt;
| char || Character || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| byte || Byte || 8-bit&lt;br /&gt;
|-&lt;br /&gt;
| short || Short || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| int || Integer || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| long || Long || 64-bit&lt;br /&gt;
|-&lt;br /&gt;
| float || Float || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| double || Double || 64-bit&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 20;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I+II);            &lt;br /&gt;
    System.out.println(I.equals(II));    &lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    30&lt;br /&gt;
    false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find out if these wrapper classes are primitive or not, we can use the isPrimitive() method.&lt;br /&gt;
&lt;br /&gt;
    System.out.println(INTEGER.TYPE.isPrimitive());&lt;br /&gt;
    System.out.println(BOOLEAN.TYPE.isPrimitive());&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    true&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java, the comparison operations work in the same way on the primitive objects as well as any other class objects but different on the primitive types. The == operator when used on objects checks whether they refer to the same object but when used on variables of primitive types checks whether they contain the same value.&amp;lt;ref&amp;gt;http://leepoint.net/notes-java/data/expressions/22compareobjects.html Comparisons in Java&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 10;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I==II);            &lt;br /&gt;
    System.out.println(i==ii);&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    false&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29 C#] is a [http://en.wikipedia.org/wiki/Strong_typing strongly typed] language, where it is necessary to declare the data type of a variable and also be aware of the data type conversion. C# provides a significant number of primitive data types.&amp;lt;ref&amp;gt;http://condor.depaul.edu/sjost/ndp/notes/cs1/CSDatatypes.htm C# Primitive Datatypes&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.java2s.com/Tutorial/CSharp/0040__Data-Type/PrimitivesinC.htm Primitives in C#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type. For example:&lt;br /&gt;
 &lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        int x = 7;&lt;br /&gt;
        object o = x;&lt;br /&gt;
        System.Console.WriteLine(o.ToString());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Some data types (e.g. Decimal and String) can appear like primitives at first sight, but are actually not. So it is important to exercise caution before making such assumptions. To test whether a particular type is a primitive or not you can use the property Type.IsPrimitive.&lt;br /&gt;
&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;br /&gt;
    if (t.IsPrimitive)    // where t is the type&lt;br /&gt;
    {&lt;br /&gt;
        // Is Primitive&lt;br /&gt;
    } else if (t == typeof(Decimal))&lt;br /&gt;
    {&lt;br /&gt;
        // Is Decimal&lt;br /&gt;
    } else if (t == typeof(String))&lt;br /&gt;
    {&lt;br /&gt;
        // Is String&lt;br /&gt;
    } else&lt;br /&gt;
    {&lt;br /&gt;
        // Other type&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== JavaScript ===&lt;br /&gt;
&lt;br /&gt;
There are 5 primitive data types in [http://en.wikipedia.org/wiki/JavaScript JavaScript]: string, number, boolean, null and undefined. &amp;lt;ref&amp;gt;http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html JavaScript Data Types and Variables&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For string, number and boolean values, there are corresponding classes just like in Java to create primitive objects which wrap the primitive values. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class&lt;br /&gt;
|-&lt;br /&gt;
| string || String&lt;br /&gt;
|-&lt;br /&gt;
| number|| Number&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In JavaScript, the primitive value is implicitly converted to a primitive object whenever someone tries to access a property or invoke a method on the primitive value and the primitive object is used in place of the primitive value. Since the object contains properties and methods, the use of primitive value as an object succeeds. After the property is accessed or the method is processed, the primitive object is no longer needed and hence discarded. The same is true for the other primitive types and their corresponding primitive objects.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    var upperCaseString = &amp;quot;APPLE&amp;quot;;&lt;br /&gt;
    var lowerCaseString = upperCaseString.toLowerCase();  // assigns string &amp;quot;apple&amp;quot; to lowerCaseString &lt;br /&gt;
    var s = &amp;quot;Hello&amp;quot;&lt;br /&gt;
    var len = s.length;                                   // assigns value 5 to len&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
&lt;br /&gt;
Since [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] is a [http://www.jvoegele.com/software/langcomp.html pure object oriented] language, everything in Ruby is an object. Hence, all primitive types such as integers, floating point numbers, strings, are objects of a built-in class.&amp;lt;ref&amp;gt;http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Classes in Ruby&amp;lt;/ref&amp;gt; &lt;br /&gt;
All integers are primitive objects of either class [http://corelib.rubyonrails.org/classes/Fixnum.html Fixnum] or [http://corelib.rubyonrails.org/classes/Bignum.html Bignum]. A numeric literal with a decimal point and/or an exponent is a primitive object of [http://corelib.rubyonrails.org/classes/Float.html Float]. Single quoted literals and double quoted literals are primitive objects of [http://corelib.rubyonrails.org/classes/String.html String].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    puts 10.class&lt;br /&gt;
    puts 7.45.class&lt;br /&gt;
    puts 'hi'.class&lt;br /&gt;
    puts &amp;quot;hello&amp;quot;.class&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    Fixnum&lt;br /&gt;
    Float&lt;br /&gt;
    String&lt;br /&gt;
    String&lt;br /&gt;
&lt;br /&gt;
This indicates that 10 is converted into an object of type Fixnum, 7.45 is converted into an object of type Float, 'hi' and &amp;quot;hello&amp;quot; are both converted into an object of type String.&lt;br /&gt;
&lt;br /&gt;
Since all primitive types in Ruby are objects, we should be able to call methods of the Object class on them. Let us demonstrate the same for integer and float using the following example:&lt;br /&gt;
&lt;br /&gt;
    a=10&lt;br /&gt;
    puts a.to_f  &lt;br /&gt;
    b=20.5&lt;br /&gt;
    puts b.to_i&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    10.0&lt;br /&gt;
    20&lt;br /&gt;
&lt;br /&gt;
== Advantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
Advantages that use of primitive data type offers are as follows:&lt;br /&gt;
===Consistency===&lt;br /&gt;
Many of Java’s ideas originate in C and in C++, objects and primitive type also co-exist. When object-oriented constructs were grafted onto the C language, C’s data types remained as is. The motivation behind this is that Bjarne Stroustrup, C++’s designer, wanted to be as consistent as possible with the base C language, hoping to capitalize on programmers’ pre-C++ knowledge.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://www.research.ibm.com/people/a/alpert/ptch/ptch.html Primitive Types Considered Harmful&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Simplicity===&lt;br /&gt;
It is simple and intuitive to use primitive data type in basic utility.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
1. Recurring number in a loop.(C++)&lt;br /&gt;
&lt;br /&gt;
   for(int i=0;i&amp;lt;10;i++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Temp variables that record only one or two data.&lt;br /&gt;
&lt;br /&gt;
===Performance===&lt;br /&gt;
&lt;br /&gt;
====Time====&lt;br /&gt;
Processing primitive data type operation would be faster than processing composite data type in most cases. There are several reasons result in this differences. &lt;br /&gt;
*Hardware processing discrepancy&lt;br /&gt;
Many primitive data operations (like integer addition) can be performed as a single machine instruction while processing of composite data type would be transformed to a combination of primitive data types. eg. Some processors offer specific instructions to process sequences of characters with a single instruction.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
[http://www.research.ibm.com/people/a/alpert/ptch/ptch.html  Difference in data fetching between primitive data and composite data in Java]&lt;br /&gt;
 &lt;br /&gt;
*Allocating and Garbage collection overhead for composite data type&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Performance_implications Garbage collection&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.ibm.com/developerworks/java/library/j-jtp01274/index.html Java theory and practice: Garbage collection and performance&amp;lt;/ref&amp;gt;&lt;br /&gt;
There are many initialization operations for composite data type that will generate high overheads for example boxing and unboxing, constructors and destructors.Composite data type like class will also have garbage collection overheads that may be beyond the control of the programmer and can sometimes lead to performance problems. For example, commonly used stop-the-world garbage collectors, which pause program execution at arbitrary times, may make garbage collection inappropriate for some [http://en.wikipedia.org/wiki/Embedded_system embedded systems], high-performance [http://en.wikipedia.org/wiki/Server_(computing)  server] software, and applications with [http://en.wikipedia.org/wiki/Real-time_computing real-time] needs.In the early days of Java technology, allocating objects got a high overheads. There were lots of articles advising developers to avoid creating temporary objects unnecessarily because allocation (and the corresponding garbage-collection overhead) was expensive. Although the costs have been greatly reduced nowadays. It still much slower than primitive data type which don’t have such troubles.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
        public class Test{&lt;br /&gt;
        double dur1,dur2;&lt;br /&gt;
        int N=100000000;&lt;br /&gt;
        public void test1()&lt;br /&gt;
        {&lt;br /&gt;
           int a=1,b=1;&lt;br /&gt;
           long startTime1 = System.currentTimeMillis();&lt;br /&gt;
           for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
              a=a+b;&lt;br /&gt;
                          }&lt;br /&gt;
           long endTime1 = System.currentTimeMillis();&lt;br /&gt;
           System.out.println(endTime1-startTime1);&lt;br /&gt;
        }&lt;br /&gt;
        public void test2(){&lt;br /&gt;
            Integer c=new Integer(1);&lt;br /&gt;
            Integer d=new Integer(1);&lt;br /&gt;
            long startTime2 = System.currentTimeMillis();&lt;br /&gt;
            for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
               c=c+d;&lt;br /&gt;
            }&lt;br /&gt;
            long endTime2 = System.currentTimeMillis();&lt;br /&gt;
            System.out.println(endTime2-startTime2)&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
'''Average execution time for test1 is: 1 mm'''&lt;br /&gt;
&lt;br /&gt;
'''Average execution time for test2 is: 702mm'''&lt;br /&gt;
&lt;br /&gt;
'''(test case number: 1000 times )'''&lt;br /&gt;
&lt;br /&gt;
====Space====&lt;br /&gt;
Composite data type will cost more memory space than primitive data type in general. The reason is not only for the overheads generated by constructors, destructors etc, but also the feature of data alignment. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding Data structure alignment&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of data alignment （C++）&lt;br /&gt;
       struct compose&lt;br /&gt;
       {&lt;br /&gt;
           char name;&lt;br /&gt;
           int a;&lt;br /&gt;
           int b;&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
We all know the size of char is 1 byte, the size of int is 4 bytes. But the size of the struct compose as shown above is 12 bytes but not 9 bytes.&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
Discussion of advantages and disadvantages should concerned the functionality you want to implement. For example if you want to operate a serials of int number. The performance of array may be better than int. &amp;lt;ref&amp;gt;http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH05/CH05-2.html composite datatypes&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:1w1.gif]]&lt;br /&gt;
&lt;br /&gt;
To access an element of an array, you need a function that converts an array index into the address of the indexed element. For a single dimension array, this function is very simple. It is&lt;br /&gt;
Element_Address = Base_Address + ((Index - Initial_Index) * Element_Size)&lt;br /&gt;
However, If you use five primitive data type to implement the same function. It may cost more time for the cpu to search the address of each data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Disdvantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
The various disadvantages of using the primitive data types are as follows:&lt;br /&gt;
&lt;br /&gt;
===Cannot be extended===&lt;br /&gt;
We can use class or array to express the intricate data or functional structure. And programmers can create subtypes, modify their operations and even redefine them. In addition with the feature of class, programmers can make their variables unchangeable to any code outside the class, or make the implementation hidden to other code with call the methods. That means with composite data types, it will be more convenient for the programmers to handle sophisticated data and also make the code easier to maintain.&lt;br /&gt;
&lt;br /&gt;
We can create a Person type in RUBY. We defined a “talk” method to make a Person can talk about himself. We also hope to only make the variable “motherland” changeable by the code outside this class.&lt;br /&gt;
&lt;br /&gt;
Example：&lt;br /&gt;
&lt;br /&gt;
       class Person&lt;br /&gt;
  &lt;br /&gt;
           def initialize( name, age=18 )&lt;br /&gt;
               @name = name&lt;br /&gt;
               @age = age&lt;br /&gt;
               @motherland = &amp;quot;US&amp;quot;&lt;br /&gt;
           end&lt;br /&gt;
  &lt;br /&gt;
           def talk&lt;br /&gt;
               puts &amp;quot;my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
               if  @motherland == &amp;quot;US&amp;quot;&lt;br /&gt;
                  puts &amp;quot;I\'m American.&amp;quot;&lt;br /&gt;
               else&lt;br /&gt;
                  puts &amp;quot;I\'m International.&amp;quot;&lt;br /&gt;
               end&lt;br /&gt;
           end&lt;br /&gt;
           attr_writer :motherland   &lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
Later when we need to create a “Student” type, we can just inherent the “Person” type and make some adjustment based on our needs. Here we redefine the “talk” method to make a student talk in a different way.&lt;br /&gt;
&lt;br /&gt;
       class Student &amp;lt; Person&lt;br /&gt;
 &lt;br /&gt;
            def talk&lt;br /&gt;
                puts &amp;quot;I am a student. my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
            end  &lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
===Uncertainty===&lt;br /&gt;
Though it means more processing time, it is necessary for programmers to create composite type to handle the data whose length is too large or changing all the time. If we have a set or integers to maintain in memory, but the number of integers will change every minute, it will be impossible if we only use primitive types to handle. But we can make use of the “Arraylist” type in Java or other composite types. With the “Arraylist”, the programmers do not need to pay attention to the storage in the memory or the space it takes. The compiler of Java will reallocate more space automatically for the Arraylist if more elements are putted. &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.5.0/docs/api/java/util/ArrayList.html uncertainty of array&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example for the insert and sorting methods of the Arraylist type in Java:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       ArrayListaList=newArrayList();&lt;br /&gt;
       aList.Add(&amp;quot;a&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;b&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;c&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;d&amp;quot;); &lt;br /&gt;
       aList.Add(&amp;quot;e&amp;quot;);&lt;br /&gt;
       aList.Sort();&lt;br /&gt;
&lt;br /&gt;
===Limitation===&lt;br /&gt;
&lt;br /&gt;
For the primitive data types in most programming languages, there are some limits of the length. For example we can put an integer between -(2^16) and (2^16)-1 into an “int” in Java. That will be enough for some most of the cases but definitely not all of them. For example, the primitive types are not able for a scientific calculation if we need an accuracy on 10^-500. And a more extreme case is to calculate the last 100 numbers for the PI has a 100 million length.&amp;lt;ref&amp;gt;http://en.verysource.com/code/1285797_1/tlargefloat.h.html limitation of primitive&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For these situations, the programmers usually need to create a composite data type by themselves. They can even redefine the operators (“+”, “-”) to make the super-long float also can make addition, subtraction with ordinary operators instead of method calling. For more details to create a super long float please see reference.&lt;br /&gt;
&lt;br /&gt;
===Cannot simplify the utility function associated with non primitive data types===&lt;br /&gt;
&lt;br /&gt;
Most of the object oriented languages have certain utility functions associated with non primitive data types that ease their use as compared to primitive data types that do not have such functions. An especially useful example is the method of parsing integers in a specified radix in Java (Integer.parseInt). &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html utility function associated with non primitive data types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
       parseInt(&amp;quot;1100110&amp;quot;, 2); //returns 102&lt;br /&gt;
       parseInt(&amp;quot;-0&amp;quot;, 10); //returns 0&lt;br /&gt;
       parseInt(&amp;quot;-FF&amp;quot;, 16); //returns -255&lt;br /&gt;
       parseInt(&amp;quot;99&amp;quot;, 8); //throws a NumberFormatException&lt;br /&gt;
&lt;br /&gt;
From the above examples, it is obvious that “Integer” type not just support ordinary methods an integer should have (such as Integer.equals), but also some more utility methods which are helpful for the programmers.&lt;br /&gt;
&lt;br /&gt;
In addition, for some data structure which only take object but not primitive type (such as Vector in Java), it is necessary to box a primitive data type to a corresponding object. For example if a programmer needs to make use of a vector to store some integer, it is necessary to box the int first:&lt;br /&gt;
&lt;br /&gt;
      Vector　v=new Vector();  &lt;br /&gt;
      int k=121; &lt;br /&gt;
      v.addElemt(new Integer(k));&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63495</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w21 wi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63495"/>
		<updated>2012-09-11T02:17:52Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* limitation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Primitive objects in object-oriented languages'''&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
In any programming language, the [http://en.wikipedia.org/wiki/Data_type data type] refers to the class of data which contains specific type or range of values. Data types are used along with variables used in the program. The data type tells us what kind of values the variable can store, what is the range of the values and how much space the values take in memory etc.&lt;br /&gt;
&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Primitive_data_type primitive data types] refer to the built-in data types which are supported by the programming language. Often 'data types' and 'primitive data types' are used interchangeably. But not all data types are primitive. Programming languages have some non-primitive data types or derived data types which are provided by the language by making use of its primitive data types.&lt;br /&gt;
&lt;br /&gt;
The common built-in data types or primitive data types are integers, floating point numbers, characters, strings and boolean.&lt;br /&gt;
* Integers - Integers represent the whole numbers which can be positive or negative or zero, e.g. 9999, 0, -25, etc. &lt;br /&gt;
* Floating point numbers - Floating point numbers represent the numbers which are fractions or contain floating-decimal points, e.g. -3.002, 2.5, 22.0, etc.&lt;br /&gt;
* Characters - Characters represent any single letter, number, space, punctuation mark, or symbol that can be typed on a computer, e.g. 'a', '9', ' ', '!' , '\n', etc.&lt;br /&gt;
* Strings - Strings represent the sequences of characters or simply any text, e.g. &amp;quot;Hello!&amp;quot;, &amp;quot;9 am to 6 pm&amp;quot;, etc. &lt;br /&gt;
* Booleans - Booleans represent the true or false values. Sometimes, instead of true and false, 1 and 0 are used to represent the boolean values.&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] languages provide support for primitive data types while some object-oriented programming languages provide support for primitive objects along with primitive types.&lt;br /&gt;
&lt;br /&gt;
== Definition ==&lt;br /&gt;
&lt;br /&gt;
Primitive objects refer to the objects of built-in classes which provide more functionality than the primitive types. Some object-oriented programming languages provide support for only primitive objects (i.e., in such languages all primitive types are objects).&lt;br /&gt;
&lt;br /&gt;
Different object-oriented programming languages implement these primitive data types and primitive objects in a different manner.&lt;br /&gt;
&lt;br /&gt;
== Primitive objects in different OO languages ==&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java], there are 8 primitive types: boolean, char, byte, short, int, long, float, and double. &amp;lt;ref&amp;gt;http://www.cafeaulait.org/course/week2/02.html Java's Primitive Data Types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each of these primitive types, Java provides [http://en.wikipedia.org/wiki/Primitive_wrapper_class wrapper classes] to create primitive objects which wrap the primitive data values. A wrapper  not only contains the primitive data value, but it also defines properties and methods that can be used to manipulate that data. In Java, the primitive values are not implicitly converted to primitive objects. Instead, methods are provided for doing explicit conversion.&lt;br /&gt;
The primitive objects are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack heap] in memory while the variables containing primitive values are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack stack].&amp;lt;ref&amp;gt;http://www.informit.com/articles/article.aspx?p=31755&amp;amp;seqNum=8 Stack and Heap memory&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class!! Size&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean || 1-bit&lt;br /&gt;
|-&lt;br /&gt;
| char || Character || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| byte || Byte || 8-bit&lt;br /&gt;
|-&lt;br /&gt;
| short || Short || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| int || Integer || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| long || Long || 64-bit&lt;br /&gt;
|-&lt;br /&gt;
| float || Float || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| double || Double || 64-bit&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 20;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I+II);            &lt;br /&gt;
    System.out.println(I.equals(II));    &lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    30&lt;br /&gt;
    false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find out if these wrapper classes are primitive or not, we can use the isPrimitive() method.&lt;br /&gt;
&lt;br /&gt;
    System.out.println(INTEGER.TYPE.isPrimitive());&lt;br /&gt;
    System.out.println(BOOLEAN.TYPE.isPrimitive());&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    true&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java, the comparison operations work in the same way on the primitive objects as well as any other class objects but different on the primitive types. The == operator when used on objects checks whether they refer to the same object but when used on variables of primitive types checks whether they contain the same value.&amp;lt;ref&amp;gt;http://leepoint.net/notes-java/data/expressions/22compareobjects.html Comparisons in Java&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 10;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I==II);            &lt;br /&gt;
    System.out.println(i==ii);&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    false&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29 C#] is a [http://en.wikipedia.org/wiki/Strong_typing strongly typed] language, where it is necessary to declare the data type of a variable and also be aware of the data type conversion. C# provides a significant number of primitive data types.&amp;lt;ref&amp;gt;http://condor.depaul.edu/sjost/ndp/notes/cs1/CSDatatypes.htm C# Primitive Datatypes&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.java2s.com/Tutorial/CSharp/0040__Data-Type/PrimitivesinC.htm Primitives in C#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type. For example:&lt;br /&gt;
 &lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        int x = 7;&lt;br /&gt;
        object o = x;&lt;br /&gt;
        System.Console.WriteLine(o.ToString());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Some data types (e.g. Decimal and String) can appear like primitives at first sight, but are actually not. So it is important to exercise caution before making such assumptions. To test whether a particular type is a primitive or not you can use the property Type.IsPrimitive.&lt;br /&gt;
&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;br /&gt;
    if (t.IsPrimitive)    // where t is the type&lt;br /&gt;
    {&lt;br /&gt;
        // Is Primitive&lt;br /&gt;
    } else if (t == typeof(Decimal))&lt;br /&gt;
    {&lt;br /&gt;
        // Is Decimal&lt;br /&gt;
    } else if (t == typeof(String))&lt;br /&gt;
    {&lt;br /&gt;
        // Is String&lt;br /&gt;
    } else&lt;br /&gt;
    {&lt;br /&gt;
        // Other type&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== JavaScript ===&lt;br /&gt;
&lt;br /&gt;
There are 5 primitive data types in [http://en.wikipedia.org/wiki/JavaScript JavaScript]: string, number, boolean, null and undefined. &amp;lt;ref&amp;gt;http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html JavaScript Data Types and Variables&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For string, number and boolean values, there are corresponding classes just like in Java to create primitive objects which wrap the primitive values. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class&lt;br /&gt;
|-&lt;br /&gt;
| string || String&lt;br /&gt;
|-&lt;br /&gt;
| number|| Number&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In JavaScript, the primitive value is implicitly converted to a primitive object whenever someone tries to access a property or invoke a method on the primitive value and the primitive object is used in place of the primitive value. Since the object contains properties and methods, the use of primitive value as an object succeeds. After the property is accessed or the method is processed, the primitive object is no longer needed and hence discarded. The same is true for the other primitive types and their corresponding primitive objects.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    var upperCaseString = &amp;quot;APPLE&amp;quot;;&lt;br /&gt;
    var lowerCaseString = upperCaseString.toLowerCase();  // assigns string &amp;quot;apple&amp;quot; to lowerCaseString &lt;br /&gt;
    var s = &amp;quot;Hello&amp;quot;&lt;br /&gt;
    var len = s.length;                                   // assigns value 5 to len&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
&lt;br /&gt;
Since [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] is a [http://www.jvoegele.com/software/langcomp.html pure object oriented] language, everything in Ruby is an object. Hence, all primitive types such as integers, floating point numbers, strings, are objects of a built-in class.&amp;lt;ref&amp;gt;http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Classes in Ruby&amp;lt;/ref&amp;gt; &lt;br /&gt;
All integers are primitive objects of either class [http://corelib.rubyonrails.org/classes/Fixnum.html Fixnum] or [http://corelib.rubyonrails.org/classes/Bignum.html Bignum]. A numeric literal with a decimal point and/or an exponent is a primitive object of [http://corelib.rubyonrails.org/classes/Float.html Float]. Single quoted literals and double quoted literals are primitive objects of [http://corelib.rubyonrails.org/classes/String.html String].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    puts 10.class&lt;br /&gt;
    puts 7.45.class&lt;br /&gt;
    puts 'hi'.class&lt;br /&gt;
    puts &amp;quot;hello&amp;quot;.class&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    Fixnum&lt;br /&gt;
    Float&lt;br /&gt;
    String&lt;br /&gt;
    String&lt;br /&gt;
&lt;br /&gt;
This indicates that 10 is converted into an object of type Fixnum, 7.45 is converted into an object of type Float, 'hi' and &amp;quot;hello&amp;quot; are both converted into an object of type String.&lt;br /&gt;
&lt;br /&gt;
Since all primitive types in Ruby are objects, we should be able to call methods of the Object class on them. Let us demonstrate the same for integer and float using the following example:&lt;br /&gt;
&lt;br /&gt;
    a=10&lt;br /&gt;
    puts a.to_f  &lt;br /&gt;
    b=20.5&lt;br /&gt;
    puts b.to_i&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    10.0&lt;br /&gt;
    20&lt;br /&gt;
&lt;br /&gt;
== Advantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
Advantages that use of primitive data type offers are as follows:&lt;br /&gt;
===Consistency===&lt;br /&gt;
Many of Java’s ideas originate in C and in C++, objects and primitive type also co-exist. When object-oriented constructs were grafted onto the C language, C’s data types remained as is. The motivation behind this is that Bjarne Stroustrup, C++’s designer, wanted to be as consistent as possible with the base C language, hoping to capitalize on programmers’ pre-C++ knowledge.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://www.research.ibm.com/people/a/alpert/ptch/ptch.html Primitive Types Considered Harmful&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Simplicity===&lt;br /&gt;
It is simple and intuitive to use primitive data type in basic utility.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
1. Recurring number in a loop.(C++)&lt;br /&gt;
&lt;br /&gt;
   for(int i=0;i&amp;lt;10;i++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Temp variables that record only one or two data.&lt;br /&gt;
&lt;br /&gt;
===Performance===&lt;br /&gt;
&lt;br /&gt;
====Time====&lt;br /&gt;
Processing primitive data type operation would be faster than processing composite data type in most cases. There are several reasons result in this differences. &lt;br /&gt;
*Hardware processing discrepancy&lt;br /&gt;
Many primitive data operations (like integer addition) can be performed as a single machine instruction while processing of composite data type would be transformed to a combination of primitive data types. eg. Some processors offer specific instructions to process sequences of characters with a single instruction.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
[http://www.research.ibm.com/people/a/alpert/ptch/ptch.html  Difference in data fetching between primitive data and composite data in Java]&lt;br /&gt;
 &lt;br /&gt;
*Allocating and Garbage collection overhead for composite data type&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Performance_implications Garbage collection&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.ibm.com/developerworks/java/library/j-jtp01274/index.html Java theory and practice: Garbage collection and performance&amp;lt;/ref&amp;gt;&lt;br /&gt;
There are many initialization operations for composite data type that will generate high overheads for example boxing and unboxing, constructors and destructors.Composite data type like class will also have garbage collection overheads that may be beyond the control of the programmer and can sometimes lead to performance problems. For example, commonly used stop-the-world garbage collectors, which pause program execution at arbitrary times, may make garbage collection inappropriate for some [http://en.wikipedia.org/wiki/Embedded_system embedded systems], high-performance [http://en.wikipedia.org/wiki/Server_(computing)  server] software, and applications with [http://en.wikipedia.org/wiki/Real-time_computing real-time] needs.In the early days of Java technology, allocating objects got a high overheads. There were lots of articles advising developers to avoid creating temporary objects unnecessarily because allocation (and the corresponding garbage-collection overhead) was expensive. Although the costs have been greatly reduced nowadays. It still much slower than primitive data type which don’t have such troubles.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
        public class Test{&lt;br /&gt;
        double dur1,dur2;&lt;br /&gt;
        int N=100000000;&lt;br /&gt;
        public void test1()&lt;br /&gt;
        {&lt;br /&gt;
           int a=1,b=1;&lt;br /&gt;
           long startTime1 = System.currentTimeMillis();&lt;br /&gt;
           for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
              a=a+b;&lt;br /&gt;
                          }&lt;br /&gt;
           long endTime1 = System.currentTimeMillis();&lt;br /&gt;
           System.out.println(endTime1-startTime1);&lt;br /&gt;
        }&lt;br /&gt;
        public void test2(){&lt;br /&gt;
            Integer c=new Integer(1);&lt;br /&gt;
            Integer d=new Integer(1);&lt;br /&gt;
            long startTime2 = System.currentTimeMillis();&lt;br /&gt;
            for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
               c=c+d;&lt;br /&gt;
            }&lt;br /&gt;
            long endTime2 = System.currentTimeMillis();&lt;br /&gt;
            System.out.println(endTime2-startTime2)&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
'''Average execution time for test1 is: 1 mm'''&lt;br /&gt;
&lt;br /&gt;
'''Average execution time for test2 is: 702mm'''&lt;br /&gt;
&lt;br /&gt;
'''(test case number: 1000 times )'''&lt;br /&gt;
&lt;br /&gt;
====Space====&lt;br /&gt;
Composite data type will cost more memory space than primitive data type in general. The reason is not only for the overheads generated by constructors, destructors etc, but also the feature of data alignment. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding Data structure alignment&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of data alignment （C++）&lt;br /&gt;
       struct compose&lt;br /&gt;
       {&lt;br /&gt;
           char name;&lt;br /&gt;
           int a;&lt;br /&gt;
           int b;&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
We all know the size of char is 1 byte, the size of int is 4 bytes. But the size of the struct compose as shown above is 12 bytes but not 9 bytes.&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
Discussion of advantages and disadvantages should concerned the functionality you want to implement. For example if you want to operate a serials of int number. The performance of array may be better than int. &amp;lt;ref&amp;gt;http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH05/CH05-2.html composite datatypes&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:1w1.gif]]&lt;br /&gt;
&lt;br /&gt;
To access an element of an array, you need a function that converts an array index into the address of the indexed element. For a single dimension array, this function is very simple. It is&lt;br /&gt;
Element_Address = Base_Address + ((Index - Initial_Index) * Element_Size)&lt;br /&gt;
However, If you use five primitive data type to implement the same function. It may cost more time for the cpu to search the address of each data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Disdvantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
The various disadvantages of using the primitive data types are as follows:&lt;br /&gt;
&lt;br /&gt;
===Cannot be extended===&lt;br /&gt;
We can use class or array to express the intricate data or functional structure. And programmers can create subtypes, modify their operations and even redefine them. In addition with the feature of class, programmers can make their variables unchangeable to any code outside the class, or make the implementation hidden to other code with call the methods. That means with composite data types, it will be more convenient for the programmers to handle sophisticated data and also make the code easier to maintain.&lt;br /&gt;
&lt;br /&gt;
We can create a Person type in RUBY. We defined a “talk” method to make a Person can talk about himself. We also hope to only make the variable “motherland” changeable by the code outside this class.&lt;br /&gt;
&lt;br /&gt;
Example：&lt;br /&gt;
&lt;br /&gt;
       class Person&lt;br /&gt;
  &lt;br /&gt;
           def initialize( name, age=18 )&lt;br /&gt;
               @name = name&lt;br /&gt;
               @age = age&lt;br /&gt;
               @motherland = &amp;quot;US&amp;quot;&lt;br /&gt;
           end&lt;br /&gt;
  &lt;br /&gt;
           def talk&lt;br /&gt;
               puts &amp;quot;my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
               if  @motherland == &amp;quot;US&amp;quot;&lt;br /&gt;
                  puts &amp;quot;I\'m American.&amp;quot;&lt;br /&gt;
               else&lt;br /&gt;
                  puts &amp;quot;I\'m International.&amp;quot;&lt;br /&gt;
               end&lt;br /&gt;
           end&lt;br /&gt;
           attr_writer :motherland   &lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
Later when we need to create a “Student” type, we can just inherent the “Person” type and make some adjustment based on our needs. Here we redefine the “talk” method to make a student talk in a different way.&lt;br /&gt;
&lt;br /&gt;
       class Student &amp;lt; Person&lt;br /&gt;
 &lt;br /&gt;
            def talk&lt;br /&gt;
                puts &amp;quot;I am a student. my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
            end  &lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
===Uncertainty===&lt;br /&gt;
Though it means more processing time, it is necessary for programmers to create composite type to handle the data whose length is too large or changing all the time. If we have a set or integers to maintain in memory, but the number of integers will change every minute, it will be impossible if we only use primitive types to handle. But we can make use of the “Arraylist” type in Java or other composite types. With the “Arraylist”, the programmers do not need to pay attention to the storage in the memory or the space it takes. The compiler of Java will reallocate more space automatically for the Arraylist if more elements are putted. &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.5.0/docs/api/java/util/ArrayList.html uncertainty of array&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example for the insert and sorting methods of the Arraylist type in Java:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       ArrayListaList=newArrayList();&lt;br /&gt;
       aList.Add(&amp;quot;a&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;b&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;c&amp;quot;);&lt;br /&gt;
       aList.Add(&amp;quot;d&amp;quot;); &lt;br /&gt;
       aList.Add(&amp;quot;e&amp;quot;);&lt;br /&gt;
       aList.Sort();&lt;br /&gt;
&lt;br /&gt;
===Limitation===&lt;br /&gt;
&lt;br /&gt;
For the primitive data types in most programming languages, there are some limits of the length. For example we can put an integer between -(2^16) and (2^16)-1 into an “int” in Java. That will be enough for some most of the cases but definitely not all of them. For example, the primitive types are not able for a scientific calculation if we need an accuracy on 10^-500. And a more extreme case is to calculate the last 100 numbers for the PI has a 100 million length.&amp;lt;ref&amp;gt;http://en.verysource.com/code/1285797_1/tlargefloat.h.html limitation of primitive&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For these situations, the programmers usually need to create a composite data type by themselves. They can even redefine the operators (“+”, “-”) to make the super-long float also can make addition, subtraction with ordinary operators instead of method calling. For more details to create a super long float please see reference.&lt;br /&gt;
&lt;br /&gt;
===cannot simplify the utility function associated with non primitive data types===&lt;br /&gt;
&lt;br /&gt;
Most of the object oriented languages have certain utility functions associated with non primitive data types that ease their use as compared to primitive data types that do not have such functions. An especially useful example is the method of parsing integers in a specified radix in Java (Integer.parseInt). &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html utility function associated with non primitive data types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
       parseInt(&amp;quot;1100110&amp;quot;, 2); //returns 102&lt;br /&gt;
       parseInt(&amp;quot;-0&amp;quot;, 10); //returns 0&lt;br /&gt;
       parseInt(&amp;quot;-FF&amp;quot;, 16); //returns -255&lt;br /&gt;
       parseInt(&amp;quot;99&amp;quot;, 8); //throws a NumberFormatException&lt;br /&gt;
&lt;br /&gt;
From the above examples, it is obvious that “Integer” type not just support ordinary methods an integer should have (such as Integer.equals), but also some more utility methods which are helpful for the programmers.&lt;br /&gt;
&lt;br /&gt;
In addition, for some data structure which only take object but not primitive type (such as Vector in Java), it is necessary to box a primitive data type to a corresponding object. For example if a programmer needs to make use of a vector to store some integer, it is necessary to box the int first:&lt;br /&gt;
&lt;br /&gt;
      Vector　v=new Vector();  &lt;br /&gt;
      int k=121; &lt;br /&gt;
      v.addElemt(new Integer(k));&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63491</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w21 wi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63491"/>
		<updated>2012-09-11T02:07:12Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Time */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Primitive objects in object-oriented languages'''&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
In any programming language, the [http://en.wikipedia.org/wiki/Data_type data type] refers to the class of data which contains specific type or range of values. Data types are used along with variables used in the program. The data type tells us what kind of values the variable can store, what is the range of the values and how much space the values take in memory etc.&lt;br /&gt;
&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Primitive_data_type primitive data types] refer to the built-in data types which are supported by the programming language. Often 'data types' and 'primitive data types' are used interchangeably. But not all data types are primitive. Programming languages have some non-primitive data types or derived data types which are provided by the language by making use of its primitive data types.&lt;br /&gt;
&lt;br /&gt;
The common built-in data types or primitive data types are integers, floating point numbers, characters, strings and boolean.&lt;br /&gt;
* Integers - Integers represent the whole numbers which can be positive or negative or zero, e.g. 9999, 0, -25, etc. &lt;br /&gt;
* Floating point numbers - Floating point numbers represent the numbers which are fractions or contain floating-decimal points, e.g. -3.002, 2.5, 22.0, etc.&lt;br /&gt;
* Characters - Characters represent any single letter, number, space, punctuation mark, or symbol that can be typed on a computer, e.g. 'a', '9', ' ', '!' , '\n', etc.&lt;br /&gt;
* Strings - Strings represent the sequences of characters or simply any text, e.g. &amp;quot;Hello!&amp;quot;, &amp;quot;9 am to 6 pm&amp;quot;, etc. &lt;br /&gt;
* Booleans - Booleans represent the true or false values. Sometimes, instead of true and false, 1 and 0 are used to represent the boolean values.&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] languages provide support for primitive data types while some object-oriented programming languages provide support for primitive objects along with primitive types.&lt;br /&gt;
&lt;br /&gt;
== Definition ==&lt;br /&gt;
&lt;br /&gt;
Primitive objects refer to the objects of built-in classes which provide more functionality than the primitive types. Some object-oriented programming languages provide support for only primitive objects (i.e., in such languages all primitive types are objects).&lt;br /&gt;
&lt;br /&gt;
Different object-oriented programming languages implement these primitive data types and primitive objects in a different manner.&lt;br /&gt;
&lt;br /&gt;
== Primitive objects in different OO languages ==&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java], there are 8 primitive types: boolean, char, byte, short, int, long, float, and double. &amp;lt;ref&amp;gt;http://www.cafeaulait.org/course/week2/02.html Java's Primitive Data Types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each of these primitive types, Java provides [http://en.wikipedia.org/wiki/Primitive_wrapper_class wrapper classes] to create primitive objects which wrap the primitive data values. A wrapper  not only contains the primitive data value, but it also defines properties and methods that can be used to manipulate that data. In Java, the primitive values are not implicitly converted to primitive objects. Instead, methods are provided for doing explicit conversion.&lt;br /&gt;
The primitive objects are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack heap] in memory while the variables containing primitive values are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack stack].&amp;lt;ref&amp;gt;http://www.informit.com/articles/article.aspx?p=31755&amp;amp;seqNum=8 Stack and Heap memory&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class!! Size&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean || 1-bit&lt;br /&gt;
|-&lt;br /&gt;
| char || Character || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| byte || Byte || 8-bit&lt;br /&gt;
|-&lt;br /&gt;
| short || Short || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| int || Integer || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| long || Long || 64-bit&lt;br /&gt;
|-&lt;br /&gt;
| float || Float || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| double || Double || 64-bit&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 20;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I+II);            &lt;br /&gt;
    System.out.println(I.equals(II));    &lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    30&lt;br /&gt;
    false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find out if these wrapper classes are primitive or not, we can use the isPrimitive() method.&lt;br /&gt;
&lt;br /&gt;
    System.out.println(INTEGER.TYPE.isPrimitive());&lt;br /&gt;
    System.out.println(BOOLEAN.TYPE.isPrimitive());&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    true&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java, the comparison operations work in the same way on the primitive objects as well as any other class objects but different on the primitive types. The == operator when used on objects checks whether they refer to the same object but when used on variables of primitive types checks whether they contain the same value.&amp;lt;ref&amp;gt;http://leepoint.net/notes-java/data/expressions/22compareobjects.html Comparisons in Java&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 10;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I==II);            &lt;br /&gt;
    System.out.println(i==ii);&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    false&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29 C#] is a [http://en.wikipedia.org/wiki/Strong_typing strongly typed] language, where it is necessary to declare the data type of a variable and also be aware of the data type conversion. C# provides a significant number of primitive data types.&amp;lt;ref&amp;gt;http://condor.depaul.edu/sjost/ndp/notes/cs1/CSDatatypes.htm C# Primitive Datatypes&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.java2s.com/Tutorial/CSharp/0040__Data-Type/PrimitivesinC.htm Primitives in C#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type. For example:&lt;br /&gt;
 &lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        int x = 7;&lt;br /&gt;
        object o = x;&lt;br /&gt;
        System.Console.WriteLine(o.ToString());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Some data types (e.g. Decimal and String) can appear like primitives at first sight, but are actually not. So it is important to exercise caution before making such assumptions. To test whether a particular type is a primitive or not you can use the property Type.IsPrimitive.&lt;br /&gt;
&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;br /&gt;
    if (t.IsPrimitive)    // where t is the type&lt;br /&gt;
    {&lt;br /&gt;
        // Is Primitive&lt;br /&gt;
    } else if (t == typeof(Decimal))&lt;br /&gt;
    {&lt;br /&gt;
        // Is Decimal&lt;br /&gt;
    } else if (t == typeof(String))&lt;br /&gt;
    {&lt;br /&gt;
        // Is String&lt;br /&gt;
    } else&lt;br /&gt;
    {&lt;br /&gt;
        // Other type&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== JavaScript ===&lt;br /&gt;
&lt;br /&gt;
There are 5 primitive data types in [http://en.wikipedia.org/wiki/JavaScript JavaScript]: string, number, boolean, null and undefined. &amp;lt;ref&amp;gt;http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html JavaScript Data Types and Variables&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For string, number and boolean values, there are corresponding classes just like in Java to create primitive objects which wrap the primitive values. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class&lt;br /&gt;
|-&lt;br /&gt;
| string || String&lt;br /&gt;
|-&lt;br /&gt;
| number|| Number&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In JavaScript, the primitive value is implicitly converted to a primitive object whenever someone tries to access a property or invoke a method on the primitive value and the primitive object is used in place of the primitive value. Since the object contains properties and methods, the use of primitive value as an object succeeds. After the property is accessed or the method is processed, the primitive object is no longer needed and hence discarded. The same is true for the other primitive types and their corresponding primitive objects.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    var upperCaseString = &amp;quot;APPLE&amp;quot;;&lt;br /&gt;
    var lowerCaseString = upperCaseString.toLowerCase();  // assigns string &amp;quot;apple&amp;quot; to lowerCaseString &lt;br /&gt;
    var s = &amp;quot;Hello&amp;quot;&lt;br /&gt;
    var len = s.length;                                   // assigns value 5 to len&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
&lt;br /&gt;
Since [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] is a [http://www.jvoegele.com/software/langcomp.html pure object oriented] language, everything in Ruby is an object. Hence, all primitive types such as integers, floating point numbers, strings, are objects of a built-in class.&amp;lt;ref&amp;gt;http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Classes in Ruby&amp;lt;/ref&amp;gt; &lt;br /&gt;
All integers are primitive objects of either class [http://corelib.rubyonrails.org/classes/Fixnum.html Fixnum] or [http://corelib.rubyonrails.org/classes/Bignum.html Bignum]. A numeric literal with a decimal point and/or an exponent is a primitive object of [http://corelib.rubyonrails.org/classes/Float.html Float]. Single quoted literals and double quoted literals are primitive objects of [http://corelib.rubyonrails.org/classes/String.html String].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    puts 10.class&lt;br /&gt;
    puts 7.45.class&lt;br /&gt;
    puts 'hi'.class&lt;br /&gt;
    puts &amp;quot;hello&amp;quot;.class&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    Fixnum&lt;br /&gt;
    Float&lt;br /&gt;
    String&lt;br /&gt;
    String&lt;br /&gt;
&lt;br /&gt;
This indicates that 10 is converted into an object of type Fixnum, 7.45 is converted into an object of type Float, 'hi' and &amp;quot;hello&amp;quot; are both converted into an object of type String.&lt;br /&gt;
&lt;br /&gt;
Since all primitive types in Ruby are objects, we should be able to call methods of the Object class on them. Let us demonstrate the same for integer and float using the following example:&lt;br /&gt;
&lt;br /&gt;
    a=10&lt;br /&gt;
    puts a.to_f  &lt;br /&gt;
    b=20.5&lt;br /&gt;
    puts b.to_i&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    10.0&lt;br /&gt;
    20&lt;br /&gt;
&lt;br /&gt;
== Advantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
Advantages that use of primitive data type offers are as follows:&lt;br /&gt;
===Consistency===&lt;br /&gt;
Many of Java’s ideas originate in C and in C++, objects and primitive type also co-exist. When object-oriented constructs were grafted onto the C language, C’s data types remained as is. The motivation behind this is that Bjarne Stroustrup, C++’s designer, wanted to be as consistent as possible with the base C language, hoping to capitalize on programmers’ pre-C++ knowledge.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://www.research.ibm.com/people/a/alpert/ptch/ptch.html Primitive Types Considered Harmful&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Simplicity===&lt;br /&gt;
It is simple and intuitive to use primitive data type in basic utility.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
1. Recurring number in a loop.(C++)&lt;br /&gt;
&lt;br /&gt;
   for(int i=0;i&amp;lt;10;i++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Temp variables that record only one or two data.&lt;br /&gt;
&lt;br /&gt;
===Performance===&lt;br /&gt;
&lt;br /&gt;
====Time====&lt;br /&gt;
Processing primitive data type operation would be faster than processing composite data type in most cases. There are several reasons result in this differences. &lt;br /&gt;
*Hardware processing discrepancy&lt;br /&gt;
Many primitive data operations (like integer addition) can be performed as a single machine instruction while processing of composite data type would be transformed to a combination of primitive data types. eg. Some processors offer specific instructions to process sequences of characters with a single instruction.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
[http://www.research.ibm.com/people/a/alpert/ptch/ptch.html  Difference in data fetching between primitive data and composite data in Java]&lt;br /&gt;
 &lt;br /&gt;
*Allocating and Garbage collection overhead for composite data type&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Performance_implications garbage collection&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.ibm.com/developerworks/java/library/j-jtp01274/index.html Java theory and practice: Garbage collection and performance&amp;lt;/ref&amp;gt;&lt;br /&gt;
There are many initialization operations for composite data type that will generate high overheads for example boxing and unboxing, constructors and destructors.Composite data type like class will also have garbage collection overheads that may be beyond the control of the programmer and can sometimes lead to performance problems. For example, commonly used stop-the-world garbage collectors, which pause program execution at arbitrary times, may make garbage collection inappropriate for some [http://en.wikipedia.org/wiki/Embedded_system embedded systems], high-performance [http://en.wikipedia.org/wiki/Server_(computing)  server] software, and applications with [http://en.wikipedia.org/wiki/Real-time_computing real-time] needs.In the early days of Java technology, allocating objects got a high overheads. There were lots of articles advising developers to avoid creating temporary objects unnecessarily because allocation (and the corresponding garbage-collection overhead) was expensive. Although the costs have been greatly reduced nowadays. It still much slower than primitive data type which don’t have such troubles.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
        public class Test{&lt;br /&gt;
        double dur1,dur2;&lt;br /&gt;
        int N=100000000;&lt;br /&gt;
        public void test1()&lt;br /&gt;
        {&lt;br /&gt;
           int a=1,b=1;&lt;br /&gt;
           long startTime1 = System.currentTimeMillis();&lt;br /&gt;
           for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
              a=a+b;&lt;br /&gt;
                          }&lt;br /&gt;
           long endTime1 = System.currentTimeMillis();&lt;br /&gt;
           System.out.println(endTime1-startTime1);&lt;br /&gt;
        }&lt;br /&gt;
        public void test2(){&lt;br /&gt;
            Integer c=new Integer(1);&lt;br /&gt;
            Integer d=new Integer(1);&lt;br /&gt;
            long startTime2 = System.currentTimeMillis();&lt;br /&gt;
            for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
               c=c+d;&lt;br /&gt;
            }&lt;br /&gt;
            long endTime2 = System.currentTimeMillis();&lt;br /&gt;
            System.out.println(endTime2-startTime2)&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
'''Average execution time for test1 is: 1 mm'''&lt;br /&gt;
&lt;br /&gt;
'''Average execution time for test2 is: 702mm'''&lt;br /&gt;
&lt;br /&gt;
'''(test case number: 1000 times )'''&lt;br /&gt;
&lt;br /&gt;
====Space====&lt;br /&gt;
Composite data type will cost more memory space than primitive data type in general. The reason is not only for the overheads generated by constructors, destructors etc, but also the feature of data alignment. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding Data structure alignment&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of data alignment （C++）&lt;br /&gt;
       struct compose&lt;br /&gt;
       {&lt;br /&gt;
           char name;&lt;br /&gt;
           int a;&lt;br /&gt;
           int b;&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
We all know the size of char is 1 byte, the size of int is 4 bytes. But the size of the struct compose as shown above is 12 bytes but not 9 bytes.&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
Discussion of advantages and disadvantages should concerned the functionality you want to implement. For example if you want to operate a serials of int number. The performance of array may be better than int. &amp;lt;ref&amp;gt;http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH05/CH05-2.html composite datatypes&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:1w1.gif]]&lt;br /&gt;
&lt;br /&gt;
To access an element of an array, you need a function that converts an array index into the address of the indexed element. For a single dimension array, this function is very simple. It is&lt;br /&gt;
Element_Address = Base_Address + ((Index - Initial_Index) * Element_Size)&lt;br /&gt;
However, If you use five primitive data type to implement the same function. It may cost more time for the cpu to search the address of each data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Disdvantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
The various disadvantages of using the primitive data types are as follows:&lt;br /&gt;
&lt;br /&gt;
===Cannot be extended===&lt;br /&gt;
We can use class or array to express the intricate data or functional structure. And programmers can create subtypes, modify their operations and even redefine them. In addition with the feature of class, programmers can make their variables unchangeable to any code outside the class, or make the implementation hidden to other code with call the methods. That means with composite data types, it will be more convenient for the programmers to handle sophisticated data and also make the code easier to maintain.&lt;br /&gt;
&lt;br /&gt;
We can create a Person type in RUBY. We defined a “talk” method to make a Person can talk about himself. We also hope to only make the variable “motherland” changeable by the code outside this class.&lt;br /&gt;
&lt;br /&gt;
Example：&lt;br /&gt;
&lt;br /&gt;
       class Person&lt;br /&gt;
  &lt;br /&gt;
           def initialize( name, age=18 )&lt;br /&gt;
               @name = name&lt;br /&gt;
               @age = age&lt;br /&gt;
               @motherland = &amp;quot;US&amp;quot;&lt;br /&gt;
           end&lt;br /&gt;
  &lt;br /&gt;
           def talk&lt;br /&gt;
               puts &amp;quot;my name is &amp;quot;+@name+&amp;quot;, age is &amp;quot;+@age.to_s&lt;br /&gt;
               if  @motherland == &amp;quot;US&amp;quot;&lt;br /&gt;
                  puts &amp;quot;I\'m American.&amp;quot;&lt;br /&gt;
               else&lt;br /&gt;
                  puts &amp;quot;I\'m International.&amp;quot;&lt;br /&gt;
               end&lt;br /&gt;
           end&lt;br /&gt;
           attr_writer :motherland   &lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
Later when we need to create a “Student” type, we can just inherent the “Person” type and make some adjustment based on our needs. Here we redefine the “talk” method to make a student talk in a different way.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63488</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w21 wi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63488"/>
		<updated>2012-09-11T01:49:14Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Consistency */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Primitive objects in object-oriented languages'''&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
In any programming language, the [http://en.wikipedia.org/wiki/Data_type data type] refers to the class of data which contains specific type or range of values. Data types are used along with variables used in the program. The data type tells us what kind of values the variable can store, what is the range of the values and how much space the values take in memory etc.&lt;br /&gt;
&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Primitive_data_type primitive data types] refer to the built-in data types which are supported by the programming language. Often 'data types' and 'primitive data types' are used interchangeably. But not all data types are primitive. Programming languages have some non-primitive data types or derived data types which are provided by the language by making use of its primitive data types.&lt;br /&gt;
&lt;br /&gt;
The common built-in data types or primitive data types are integers, floating point numbers, characters, strings and boolean.&lt;br /&gt;
* Integers - Integers represent the whole numbers which can be positive or negative or zero, e.g. 9999, 0, -25, etc. &lt;br /&gt;
* Floating point numbers - Floating point numbers represent the numbers which are fractions or contain floating-decimal points, e.g. -3.002, 2.5, 22.0, etc.&lt;br /&gt;
* Characters - Characters represent any single letter, number, space, punctuation mark, or symbol that can be typed on a computer, e.g. 'a', '9', ' ', '!' , '\n', etc.&lt;br /&gt;
* Strings - Strings represent the sequences of characters or simply any text, e.g. &amp;quot;Hello!&amp;quot;, &amp;quot;9 am to 6 pm&amp;quot;, etc. &lt;br /&gt;
* Booleans - Booleans represent the true or false values. Sometimes, instead of true and false, 1 and 0 are used to represent the boolean values.&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] languages provide support for primitive data types while some object-oriented programming languages provide support for primitive objects along with primitive types.&lt;br /&gt;
&lt;br /&gt;
== Definition ==&lt;br /&gt;
&lt;br /&gt;
Primitive objects refer to the objects of built-in classes which provide more functionality than the primitive types. Some object-oriented programming languages provide support for only primitive objects (i.e., in such languages all primitive types are objects).&lt;br /&gt;
&lt;br /&gt;
Different object-oriented programming languages implement these primitive data types and primitive objects in a different manner.&lt;br /&gt;
&lt;br /&gt;
== Primitive objects in different OO languages ==&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java], there are 8 primitive types: boolean, char, byte, short, int, long, float, and double. &amp;lt;ref&amp;gt;http://www.cafeaulait.org/course/week2/02.html Java's Primitive Data Types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each of these primitive types, Java provides [http://en.wikipedia.org/wiki/Primitive_wrapper_class wrapper classes] to create primitive objects which wrap the primitive data values. A wrapper  not only contains the primitive data value, but it also defines properties and methods that can be used to manipulate that data. In Java, the primitive values are not implicitly converted to primitive objects. Instead, methods are provided for doing explicit conversion.&lt;br /&gt;
The primitive objects are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack heap] in memory while the variables containing primitive values are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack stack].&amp;lt;ref&amp;gt;http://www.informit.com/articles/article.aspx?p=31755&amp;amp;seqNum=8 Stack and Heap memory&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class!! Size&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean || 1-bit&lt;br /&gt;
|-&lt;br /&gt;
| char || Character || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| byte || Byte || 8-bit&lt;br /&gt;
|-&lt;br /&gt;
| short || Short || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| int || Integer || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| long || Long || 64-bit&lt;br /&gt;
|-&lt;br /&gt;
| float || Float || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| double || Double || 64-bit&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 20;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I+II);            &lt;br /&gt;
    System.out.println(I.equals(II));    &lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    30&lt;br /&gt;
    false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find out if these wrapper classes are primitive or not, we can use the isPrimitive() method.&lt;br /&gt;
&lt;br /&gt;
    System.out.println(INTEGER.TYPE.isPrimitive());&lt;br /&gt;
    System.out.println(BOOLEAN.TYPE.isPrimitive());&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    true&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java, the comparison operations work in the same way on the primitive objects as well as any other class objects but different on the primitive types. The == operator when used on objects checks whether they refer to the same object but when used on variables of primitive types checks whether they contain the same value.&amp;lt;ref&amp;gt;http://leepoint.net/notes-java/data/expressions/22compareobjects.html Comparisons in Java&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 10;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I==II);            &lt;br /&gt;
    System.out.println(i==ii);&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    false&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29 C#] is a [http://en.wikipedia.org/wiki/Strong_typing strongly typed] language, where it is necessary to declare the data type of a variable and also be aware of the data type conversion. C# provides a significant number of primitive data types.&amp;lt;ref&amp;gt;http://condor.depaul.edu/sjost/ndp/notes/cs1/CSDatatypes.htm C# Primitive Datatypes&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.java2s.com/Tutorial/CSharp/0040__Data-Type/PrimitivesinC.htm Primitives in C#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type. For example:&lt;br /&gt;
 &lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        int x = 7;&lt;br /&gt;
        object o = x;&lt;br /&gt;
        System.Console.WriteLine(o.ToString());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Some data types (e.g. Decimal and String) can appear like primitives at first sight, but are actually not. So it is important to exercise caution before making such assumptions. To test whether a particular type is a primitive or not you can use the property Type.IsPrimitive.&lt;br /&gt;
&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;br /&gt;
    if (t.IsPrimitive)    // where t is the type&lt;br /&gt;
    {&lt;br /&gt;
        // Is Primitive&lt;br /&gt;
    } else if (t == typeof(Decimal))&lt;br /&gt;
    {&lt;br /&gt;
        // Is Decimal&lt;br /&gt;
    } else if (t == typeof(String))&lt;br /&gt;
    {&lt;br /&gt;
        // Is String&lt;br /&gt;
    } else&lt;br /&gt;
    {&lt;br /&gt;
        // Other type&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== JavaScript ===&lt;br /&gt;
&lt;br /&gt;
There are 5 primitive data types in [http://en.wikipedia.org/wiki/JavaScript JavaScript]: string, number, boolean, null and undefined. &amp;lt;ref&amp;gt;http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html JavaScript Data Types and Variables&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For string, number and boolean values, there are corresponding classes just like in Java to create primitive objects which wrap the primitive values. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class&lt;br /&gt;
|-&lt;br /&gt;
| string || String&lt;br /&gt;
|-&lt;br /&gt;
| number|| Number&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In JavaScript, the primitive value is implicitly converted to a primitive object whenever someone tries to access a property or invoke a method on the primitive value and the primitive object is used in place of the primitive value. Since the object contains properties and methods, the use of primitive value as an object succeeds. After the property is accessed or the method is processed, the primitive object is no longer needed and hence discarded. The same is true for the other primitive types and their corresponding primitive objects.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    var upperCaseString = &amp;quot;APPLE&amp;quot;;&lt;br /&gt;
    var lowerCaseString = upperCaseString.toLowerCase();  // assigns string &amp;quot;apple&amp;quot; to lowerCaseString &lt;br /&gt;
    var s = &amp;quot;Hello&amp;quot;&lt;br /&gt;
    var len = s.length;                                   // assigns value 5 to len&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
&lt;br /&gt;
Since [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] is a [http://www.jvoegele.com/software/langcomp.html pure object oriented] language, everything in Ruby is an object. Hence, all primitive types such as integers, floating point numbers, strings, are objects of a built-in class.&amp;lt;ref&amp;gt;http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Classes in Ruby&amp;lt;/ref&amp;gt; &lt;br /&gt;
All integers are primitive objects of either class [http://corelib.rubyonrails.org/classes/Fixnum.html Fixnum] or [http://corelib.rubyonrails.org/classes/Bignum.html Bignum]. A numeric literal with a decimal point and/or an exponent is a primitive object of [http://corelib.rubyonrails.org/classes/Float.html Float]. Single quoted literals and double quoted literals are primitive objects of [http://corelib.rubyonrails.org/classes/String.html String].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    puts 10.class&lt;br /&gt;
    puts 7.45.class&lt;br /&gt;
    puts 'hi'.class&lt;br /&gt;
    puts &amp;quot;hello&amp;quot;.class&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    Fixnum&lt;br /&gt;
    Float&lt;br /&gt;
    String&lt;br /&gt;
    String&lt;br /&gt;
&lt;br /&gt;
This indicates that 10 is converted into an object of type Fixnum, 7.45 is converted into an object of type Float, 'hi' and &amp;quot;hello&amp;quot; are both converted into an object of type String.&lt;br /&gt;
&lt;br /&gt;
Since all primitive types in Ruby are objects, we should be able to call methods of the Object class on them. Let us demonstrate the same for integer and float using the following example:&lt;br /&gt;
&lt;br /&gt;
    a=10&lt;br /&gt;
    puts a.to_f  &lt;br /&gt;
    b=20.5&lt;br /&gt;
    puts b.to_i&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    10.0&lt;br /&gt;
    20&lt;br /&gt;
&lt;br /&gt;
== Advantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
Advantages that use of primitive data type offers are as follows:&lt;br /&gt;
===Consistency===&lt;br /&gt;
Many of Java’s ideas originate in C and in C++, objects and primitive type also co-exist. When object-oriented constructs were grafted onto the C language, C’s data types remained as is. The motivation behind this is that Bjarne Stroustrup, C++’s designer, wanted to be as consistent as possible with the base C language, hoping to capitalize on programmers’ pre-C++ knowledge.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://www.research.ibm.com/people/a/alpert/ptch/ptch.html Primitive Types Considered Harmful&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Simplicity===&lt;br /&gt;
It is simple and intuitive to use primitive data type in basic utility.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
1. Recurring number in a loop.(C++)&lt;br /&gt;
&lt;br /&gt;
   for(int i=0;i&amp;lt;10;i++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Temp variables that record only one or two data.&lt;br /&gt;
&lt;br /&gt;
===Performance===&lt;br /&gt;
&lt;br /&gt;
====Time====&lt;br /&gt;
Processing primitive data type operation would be faster than processing composite data type in most cases. There are several reasons result in this differences. &lt;br /&gt;
*Hardware processing discrepancy&lt;br /&gt;
Many primitive data operations (like integer addition) can be performed as a single machine instruction while processing of composite data type would be transformed to a combination of primitive data types. eg. Some processors offer specific instructions to process sequences of characters with a single instruction.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
[http://www.research.ibm.com/people/a/alpert/ptch/ptch.html  Difference in data fetching between primitive data and composite data in Java]&lt;br /&gt;
 &lt;br /&gt;
*Initialization overheads for composite data type&lt;br /&gt;
There are many initialization operations for composite data type. for example boxing and unboxing, constructors and destructors.&lt;br /&gt;
*Allocating and Garbage collection overhead for composite data type&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Performance_implications garbage collection&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.ibm.com/developerworks/java/library/j-jtp01274/index.html Java theory and practice: Garbage collection and performance&amp;lt;/ref&amp;gt;&lt;br /&gt;
Composite data type like class will have allocation and garbage collection overhead that may be beyond the control of the programmer and can sometimes lead to performance problems. For example, commonly used stop-the-world garbage collectors, which pause program execution at arbitrary times, may make garbage collection inappropriate for some [http://en.wikipedia.org/wiki/Embedded_system embedded systems], high-performance [http://en.wikipedia.org/wiki/Server_(computing)  server] software, and applications with [http://en.wikipedia.org/wiki/Real-time_computing real-time] needs.In the early days of Java technology, allocating objects got a high overheads. There were lots of articles advising developers to avoid creating temporary objects unnecessarily because allocation (and the corresponding garbage-collection overhead) was expensive. Although the costs have been greatly reduced nowadays. It still much slower than primitive data type which don’t have such troubles.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
        public class Test{&lt;br /&gt;
        double dur1,dur2;&lt;br /&gt;
        int N=100000000;&lt;br /&gt;
        public void test1()&lt;br /&gt;
        {&lt;br /&gt;
           int a=1,b=1;&lt;br /&gt;
           long startTime1 = System.currentTimeMillis();&lt;br /&gt;
           for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
              a=a+b;&lt;br /&gt;
                          }&lt;br /&gt;
           long endTime1 = System.currentTimeMillis();&lt;br /&gt;
           System.out.println(endTime1-startTime1);&lt;br /&gt;
        }&lt;br /&gt;
        public void test2(){&lt;br /&gt;
            Integer c=new Integer(1);&lt;br /&gt;
            Integer d=new Integer(1);&lt;br /&gt;
            long startTime2 = System.currentTimeMillis();&lt;br /&gt;
            for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
               c=c+d;&lt;br /&gt;
            }&lt;br /&gt;
            long endTime2 = System.currentTimeMillis();&lt;br /&gt;
            System.out.println(endTime2-startTime2)&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
'''Average execution time for test1 is: 1 mm'''&lt;br /&gt;
&lt;br /&gt;
'''Average execution time for test2 is: 702mm'''&lt;br /&gt;
&lt;br /&gt;
'''(test case number: 1000 times )'''&lt;br /&gt;
&lt;br /&gt;
====Space====&lt;br /&gt;
Composite data type will cost more memory space than primitive data type in general. The reason is not only for the overheads generated by constructors, destructors etc, but also the feature of data alignment. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding Data structure alignment&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of data alignment （C++）&lt;br /&gt;
       struct compose&lt;br /&gt;
       {&lt;br /&gt;
           char name;&lt;br /&gt;
           int a;&lt;br /&gt;
           int b;&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
We all know the size of char is 1 byte, the size of int is 4 bytes. But the size of the struct compose as shown above is 12 bytes but not 9 bytes.&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
Discussion of advantages and disadvantages should concerned the functionality you want to implement. For example if you want to operate a serials of int number. The performance of array may be better than int. &amp;lt;ref&amp;gt;http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH05/CH05-2.html composite datatypes&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:1w1.gif]]&lt;br /&gt;
&lt;br /&gt;
To access an element of an array, you need a function that converts an array index into the address of the indexed element. For a single dimension array, this function is very simple. It is&lt;br /&gt;
Element_Address = Base_Address + ((Index - Initial_Index) * Element_Size)&lt;br /&gt;
However, If you use five primitive data type to implement the same function. It may cost more time for the cpu to search the address of each data.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63485</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w21 wi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63485"/>
		<updated>2012-09-11T01:47:26Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* [Consistency][http://www.research.ibm.com/people/a/alpert/ptch/ptch.html] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Primitive objects in object-oriented languages'''&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
In any programming language, the [http://en.wikipedia.org/wiki/Data_type data type] refers to the class of data which contains specific type or range of values. Data types are used along with variables used in the program. The data type tells us what kind of values the variable can store, what is the range of the values and how much space the values take in memory etc.&lt;br /&gt;
&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Primitive_data_type primitive data types] refer to the built-in data types which are supported by the programming language. Often 'data types' and 'primitive data types' are used interchangeably. But not all data types are primitive. Programming languages have some non-primitive data types or derived data types which are provided by the language by making use of its primitive data types.&lt;br /&gt;
&lt;br /&gt;
The common built-in data types or primitive data types are integers, floating point numbers, characters, strings and boolean.&lt;br /&gt;
* Integers - Integers represent the whole numbers which can be positive or negative or zero, e.g. 9999, 0, -25, etc. &lt;br /&gt;
* Floating point numbers - Floating point numbers represent the numbers which are fractions or contain floating-decimal points, e.g. -3.002, 2.5, 22.0, etc.&lt;br /&gt;
* Characters - Characters represent any single letter, number, space, punctuation mark, or symbol that can be typed on a computer, e.g. 'a', '9', ' ', '!' , '\n', etc.&lt;br /&gt;
* Strings - Strings represent the sequences of characters or simply any text, e.g. &amp;quot;Hello!&amp;quot;, &amp;quot;9 am to 6 pm&amp;quot;, etc. &lt;br /&gt;
* Booleans - Booleans represent the true or false values. Sometimes, instead of true and false, 1 and 0 are used to represent the boolean values.&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] languages provide support for primitive data types while some object-oriented programming languages provide support for primitive objects along with primitive types.&lt;br /&gt;
&lt;br /&gt;
== Definition ==&lt;br /&gt;
&lt;br /&gt;
Primitive objects refer to the objects of built-in classes which provide more functionality than the primitive types. Some object-oriented programming languages provide support for only primitive objects (i.e., in such languages all primitive types are objects).&lt;br /&gt;
&lt;br /&gt;
Different object-oriented programming languages implement these primitive data types and primitive objects in a different manner.&lt;br /&gt;
&lt;br /&gt;
== Primitive objects in different OO languages ==&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java], there are 8 primitive types: boolean, char, byte, short, int, long, float, and double. &amp;lt;ref&amp;gt;http://www.cafeaulait.org/course/week2/02.html Java's Primitive Data Types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each of these primitive types, Java provides [http://en.wikipedia.org/wiki/Primitive_wrapper_class wrapper classes] to create primitive objects which wrap the primitive data values. A wrapper  not only contains the primitive data value, but it also defines properties and methods that can be used to manipulate that data. In Java, the primitive values are not implicitly converted to primitive objects. Instead, methods are provided for doing explicit conversion.&lt;br /&gt;
The primitive objects are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack heap] in memory while the variables containing primitive values are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack stack].&amp;lt;ref&amp;gt;http://www.informit.com/articles/article.aspx?p=31755&amp;amp;seqNum=8 Stack and Heap memory&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class!! Size&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean || 1-bit&lt;br /&gt;
|-&lt;br /&gt;
| char || Character || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| byte || Byte || 8-bit&lt;br /&gt;
|-&lt;br /&gt;
| short || Short || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| int || Integer || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| long || Long || 64-bit&lt;br /&gt;
|-&lt;br /&gt;
| float || Float || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| double || Double || 64-bit&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 20;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I+II);            &lt;br /&gt;
    System.out.println(I.equals(II));    &lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    30&lt;br /&gt;
    false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find out if these wrapper classes are primitive or not, we can use the isPrimitive() method.&lt;br /&gt;
&lt;br /&gt;
    System.out.println(INTEGER.TYPE.isPrimitive());&lt;br /&gt;
    System.out.println(BOOLEAN.TYPE.isPrimitive());&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    true&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java, the comparison operations work in the same way on the primitive objects as well as any other class objects but different on the primitive types. The == operator when used on objects checks whether they refer to the same object but when used on variables of primitive types checks whether they contain the same value.&amp;lt;ref&amp;gt;http://leepoint.net/notes-java/data/expressions/22compareobjects.html Comparisons in Java&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 10;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I==II);            &lt;br /&gt;
    System.out.println(i==ii);&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    false&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29 C#] is a [http://en.wikipedia.org/wiki/Strong_typing strongly typed] language, where it is necessary to declare the data type of a variable and also be aware of the data type conversion. C# provides a significant number of primitive data types.&amp;lt;ref&amp;gt;http://condor.depaul.edu/sjost/ndp/notes/cs1/CSDatatypes.htm C# Primitive Datatypes&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.java2s.com/Tutorial/CSharp/0040__Data-Type/PrimitivesinC.htm Primitives in C#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type. For example:&lt;br /&gt;
 &lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        int x = 7;&lt;br /&gt;
        object o = x;&lt;br /&gt;
        System.Console.WriteLine(o.ToString());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Some data types (e.g. Decimal and String) can appear like primitives at first sight, but are actually not. So it is important to exercise caution before making such assumptions. To test whether a particular type is a primitive or not you can use the property Type.IsPrimitive.&lt;br /&gt;
&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;br /&gt;
    if (t.IsPrimitive)    // where t is the type&lt;br /&gt;
    {&lt;br /&gt;
        // Is Primitive&lt;br /&gt;
    } else if (t == typeof(Decimal))&lt;br /&gt;
    {&lt;br /&gt;
        // Is Decimal&lt;br /&gt;
    } else if (t == typeof(String))&lt;br /&gt;
    {&lt;br /&gt;
        // Is String&lt;br /&gt;
    } else&lt;br /&gt;
    {&lt;br /&gt;
        // Other type&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== JavaScript ===&lt;br /&gt;
&lt;br /&gt;
There are 5 primitive data types in [http://en.wikipedia.org/wiki/JavaScript JavaScript]: string, number, boolean, null and undefined. &amp;lt;ref&amp;gt;http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html JavaScript Data Types and Variables&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For string, number and boolean values, there are corresponding classes just like in Java to create primitive objects which wrap the primitive values. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class&lt;br /&gt;
|-&lt;br /&gt;
| string || String&lt;br /&gt;
|-&lt;br /&gt;
| number|| Number&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In JavaScript, the primitive value is implicitly converted to a primitive object whenever someone tries to access a property or invoke a method on the primitive value and the primitive object is used in place of the primitive value. Since the object contains properties and methods, the use of primitive value as an object succeeds. After the property is accessed or the method is processed, the primitive object is no longer needed and hence discarded. The same is true for the other primitive types and their corresponding primitive objects.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    var upperCaseString = &amp;quot;APPLE&amp;quot;;&lt;br /&gt;
    var lowerCaseString = upperCaseString.toLowerCase();  // assigns string &amp;quot;apple&amp;quot; to lowerCaseString &lt;br /&gt;
    var s = &amp;quot;Hello&amp;quot;&lt;br /&gt;
    var len = s.length;                                   // assigns value 5 to len&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
&lt;br /&gt;
Since [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] is a [http://www.jvoegele.com/software/langcomp.html pure object oriented] language, everything in Ruby is an object. Hence, all primitive types such as integers, floating point numbers, strings, are objects of a built-in class.&amp;lt;ref&amp;gt;http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Classes in Ruby&amp;lt;/ref&amp;gt; &lt;br /&gt;
All integers are primitive objects of either class [http://corelib.rubyonrails.org/classes/Fixnum.html Fixnum] or [http://corelib.rubyonrails.org/classes/Bignum.html Bignum]. A numeric literal with a decimal point and/or an exponent is a primitive object of [http://corelib.rubyonrails.org/classes/Float.html Float]. Single quoted literals and double quoted literals are primitive objects of [http://corelib.rubyonrails.org/classes/String.html String].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    puts 10.class&lt;br /&gt;
    puts 7.45.class&lt;br /&gt;
    puts 'hi'.class&lt;br /&gt;
    puts &amp;quot;hello&amp;quot;.class&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    Fixnum&lt;br /&gt;
    Float&lt;br /&gt;
    String&lt;br /&gt;
    String&lt;br /&gt;
&lt;br /&gt;
This indicates that 10 is converted into an object of type Fixnum, 7.45 is converted into an object of type Float, 'hi' and &amp;quot;hello&amp;quot; are both converted into an object of type String.&lt;br /&gt;
&lt;br /&gt;
Since all primitive types in Ruby are objects, we should be able to call methods of the Object class on them. Let us demonstrate the same for integer and float using the following example:&lt;br /&gt;
&lt;br /&gt;
    a=10&lt;br /&gt;
    puts a.to_f  &lt;br /&gt;
    b=20.5&lt;br /&gt;
    puts b.to_i&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    10.0&lt;br /&gt;
    20&lt;br /&gt;
&lt;br /&gt;
== Advantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
Advantages that use of primitive data type offers are as follows:&lt;br /&gt;
===Consistency===&lt;br /&gt;
Many of Java’s ideas originate in C++ and in C++, objects and primitive type also co-exist. When object-oriented constructs were grafted onto the C language, C’s data types remained as is. The motivation behind this is that Bjarne Stroustrup, C++’s designer, wanted to be as consistent as possible with the base C language, hoping to capitalize on programmers’ pre-C++ knowledge.&lt;br /&gt;
&lt;br /&gt;
===Simplicity===&lt;br /&gt;
It is simple and intuitive to use primitive data type in basic utility.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
1. Recurring number in a loop.(C++)&lt;br /&gt;
&lt;br /&gt;
   for(int i=0;i&amp;lt;10;i++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Temp variables that record only one or two data.&lt;br /&gt;
&lt;br /&gt;
===Performance===&lt;br /&gt;
&lt;br /&gt;
====Time====&lt;br /&gt;
Processing primitive data type operation would be faster than processing composite data type in most cases. There are several reasons result in this differences. &lt;br /&gt;
*Hardware processing discrepancy&lt;br /&gt;
Many primitive data operations (like integer addition) can be performed as a single machine instruction while processing of composite data type would be transformed to a combination of primitive data types. eg. Some processors offer specific instructions to process sequences of characters with a single instruction.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
[http://www.research.ibm.com/people/a/alpert/ptch/ptch.html  Difference in data fetching between primitive data and composite data in Java]&lt;br /&gt;
 &lt;br /&gt;
*Initialization overheads for composite data type&lt;br /&gt;
There are many initialization operations for composite data type. for example boxing and unboxing, constructors and destructors.&lt;br /&gt;
*Allocating and Garbage collection overhead for composite data type&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Performance_implications garbage collection&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.ibm.com/developerworks/java/library/j-jtp01274/index.html Java theory and practice: Garbage collection and performance&amp;lt;/ref&amp;gt;&lt;br /&gt;
Composite data type like class will have allocation and garbage collection overhead that may be beyond the control of the programmer and can sometimes lead to performance problems. For example, commonly used stop-the-world garbage collectors, which pause program execution at arbitrary times, may make garbage collection inappropriate for some [http://en.wikipedia.org/wiki/Embedded_system embedded systems], high-performance [http://en.wikipedia.org/wiki/Server_(computing)  server] software, and applications with [http://en.wikipedia.org/wiki/Real-time_computing real-time] needs.In the early days of Java technology, allocating objects got a high overheads. There were lots of articles advising developers to avoid creating temporary objects unnecessarily because allocation (and the corresponding garbage-collection overhead) was expensive. Although the costs have been greatly reduced nowadays. It still much slower than primitive data type which don’t have such troubles.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
        public class Test{&lt;br /&gt;
        double dur1,dur2;&lt;br /&gt;
        int N=100000000;&lt;br /&gt;
        public void test1()&lt;br /&gt;
        {&lt;br /&gt;
           int a=1,b=1;&lt;br /&gt;
           long startTime1 = System.currentTimeMillis();&lt;br /&gt;
           for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
              a=a+b;&lt;br /&gt;
                          }&lt;br /&gt;
           long endTime1 = System.currentTimeMillis();&lt;br /&gt;
           System.out.println(endTime1-startTime1);&lt;br /&gt;
        }&lt;br /&gt;
        public void test2(){&lt;br /&gt;
            Integer c=new Integer(1);&lt;br /&gt;
            Integer d=new Integer(1);&lt;br /&gt;
            long startTime2 = System.currentTimeMillis();&lt;br /&gt;
            for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
               c=c+d;&lt;br /&gt;
            }&lt;br /&gt;
            long endTime2 = System.currentTimeMillis();&lt;br /&gt;
            System.out.println(endTime2-startTime2)&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
'''Average execution time for test1 is: 1 mm'''&lt;br /&gt;
&lt;br /&gt;
'''Average execution time for test2 is: 702mm'''&lt;br /&gt;
&lt;br /&gt;
'''(test case number: 1000 times )'''&lt;br /&gt;
&lt;br /&gt;
====Space====&lt;br /&gt;
Composite data type will cost more memory space than primitive data type in general. The reason is not only for the overheads generated by constructors, destructors etc, but also the feature of data alignment. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding Data structure alignment&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of data alignment （C++）&lt;br /&gt;
       struct compose&lt;br /&gt;
       {&lt;br /&gt;
           char name;&lt;br /&gt;
           int a;&lt;br /&gt;
           int b;&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
We all know the size of char is 1 byte, the size of int is 4 bytes. But the size of the struct compose as shown above is 12 bytes but not 9 bytes.&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
Discussion of advantages and disadvantages should concerned the functionality you want to implement. For example if you want to operate a serials of int number. The performance of array may be better than int. &amp;lt;ref&amp;gt;http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH05/CH05-2.html composite datatypes&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:1w1.gif]]&lt;br /&gt;
&lt;br /&gt;
To access an element of an array, you need a function that converts an array index into the address of the indexed element. For a single dimension array, this function is very simple. It is&lt;br /&gt;
Element_Address = Base_Address + ((Index - Initial_Index) * Element_Size)&lt;br /&gt;
However, If you use five primitive data type to implement the same function. It may cost more time for the cpu to search the address of each data.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63484</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w21 wi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63484"/>
		<updated>2012-09-11T01:47:01Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Consistency */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Primitive objects in object-oriented languages'''&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
In any programming language, the [http://en.wikipedia.org/wiki/Data_type data type] refers to the class of data which contains specific type or range of values. Data types are used along with variables used in the program. The data type tells us what kind of values the variable can store, what is the range of the values and how much space the values take in memory etc.&lt;br /&gt;
&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Primitive_data_type primitive data types] refer to the built-in data types which are supported by the programming language. Often 'data types' and 'primitive data types' are used interchangeably. But not all data types are primitive. Programming languages have some non-primitive data types or derived data types which are provided by the language by making use of its primitive data types.&lt;br /&gt;
&lt;br /&gt;
The common built-in data types or primitive data types are integers, floating point numbers, characters, strings and boolean.&lt;br /&gt;
* Integers - Integers represent the whole numbers which can be positive or negative or zero, e.g. 9999, 0, -25, etc. &lt;br /&gt;
* Floating point numbers - Floating point numbers represent the numbers which are fractions or contain floating-decimal points, e.g. -3.002, 2.5, 22.0, etc.&lt;br /&gt;
* Characters - Characters represent any single letter, number, space, punctuation mark, or symbol that can be typed on a computer, e.g. 'a', '9', ' ', '!' , '\n', etc.&lt;br /&gt;
* Strings - Strings represent the sequences of characters or simply any text, e.g. &amp;quot;Hello!&amp;quot;, &amp;quot;9 am to 6 pm&amp;quot;, etc. &lt;br /&gt;
* Booleans - Booleans represent the true or false values. Sometimes, instead of true and false, 1 and 0 are used to represent the boolean values.&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] languages provide support for primitive data types while some object-oriented programming languages provide support for primitive objects along with primitive types.&lt;br /&gt;
&lt;br /&gt;
== Definition ==&lt;br /&gt;
&lt;br /&gt;
Primitive objects refer to the objects of built-in classes which provide more functionality than the primitive types. Some object-oriented programming languages provide support for only primitive objects (i.e., in such languages all primitive types are objects).&lt;br /&gt;
&lt;br /&gt;
Different object-oriented programming languages implement these primitive data types and primitive objects in a different manner.&lt;br /&gt;
&lt;br /&gt;
== Primitive objects in different OO languages ==&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java], there are 8 primitive types: boolean, char, byte, short, int, long, float, and double. &amp;lt;ref&amp;gt;http://www.cafeaulait.org/course/week2/02.html Java's Primitive Data Types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each of these primitive types, Java provides [http://en.wikipedia.org/wiki/Primitive_wrapper_class wrapper classes] to create primitive objects which wrap the primitive data values. A wrapper  not only contains the primitive data value, but it also defines properties and methods that can be used to manipulate that data. In Java, the primitive values are not implicitly converted to primitive objects. Instead, methods are provided for doing explicit conversion.&lt;br /&gt;
The primitive objects are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack heap] in memory while the variables containing primitive values are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack stack].&amp;lt;ref&amp;gt;http://www.informit.com/articles/article.aspx?p=31755&amp;amp;seqNum=8 Stack and Heap memory&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class!! Size&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean || 1-bit&lt;br /&gt;
|-&lt;br /&gt;
| char || Character || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| byte || Byte || 8-bit&lt;br /&gt;
|-&lt;br /&gt;
| short || Short || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| int || Integer || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| long || Long || 64-bit&lt;br /&gt;
|-&lt;br /&gt;
| float || Float || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| double || Double || 64-bit&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 20;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I+II);            &lt;br /&gt;
    System.out.println(I.equals(II));    &lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    30&lt;br /&gt;
    false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find out if these wrapper classes are primitive or not, we can use the isPrimitive() method.&lt;br /&gt;
&lt;br /&gt;
    System.out.println(INTEGER.TYPE.isPrimitive());&lt;br /&gt;
    System.out.println(BOOLEAN.TYPE.isPrimitive());&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    true&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java, the comparison operations work in the same way on the primitive objects as well as any other class objects but different on the primitive types. The == operator when used on objects checks whether they refer to the same object but when used on variables of primitive types checks whether they contain the same value.&amp;lt;ref&amp;gt;http://leepoint.net/notes-java/data/expressions/22compareobjects.html Comparisons in Java&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 10;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I==II);            &lt;br /&gt;
    System.out.println(i==ii);&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    false&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29 C#] is a [http://en.wikipedia.org/wiki/Strong_typing strongly typed] language, where it is necessary to declare the data type of a variable and also be aware of the data type conversion. C# provides a significant number of primitive data types.&amp;lt;ref&amp;gt;http://condor.depaul.edu/sjost/ndp/notes/cs1/CSDatatypes.htm C# Primitive Datatypes&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.java2s.com/Tutorial/CSharp/0040__Data-Type/PrimitivesinC.htm Primitives in C#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type. For example:&lt;br /&gt;
 &lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        int x = 7;&lt;br /&gt;
        object o = x;&lt;br /&gt;
        System.Console.WriteLine(o.ToString());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Some data types (e.g. Decimal and String) can appear like primitives at first sight, but are actually not. So it is important to exercise caution before making such assumptions. To test whether a particular type is a primitive or not you can use the property Type.IsPrimitive.&lt;br /&gt;
&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;br /&gt;
    if (t.IsPrimitive)    // where t is the type&lt;br /&gt;
    {&lt;br /&gt;
        // Is Primitive&lt;br /&gt;
    } else if (t == typeof(Decimal))&lt;br /&gt;
    {&lt;br /&gt;
        // Is Decimal&lt;br /&gt;
    } else if (t == typeof(String))&lt;br /&gt;
    {&lt;br /&gt;
        // Is String&lt;br /&gt;
    } else&lt;br /&gt;
    {&lt;br /&gt;
        // Other type&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== JavaScript ===&lt;br /&gt;
&lt;br /&gt;
There are 5 primitive data types in [http://en.wikipedia.org/wiki/JavaScript JavaScript]: string, number, boolean, null and undefined. &amp;lt;ref&amp;gt;http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html JavaScript Data Types and Variables&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For string, number and boolean values, there are corresponding classes just like in Java to create primitive objects which wrap the primitive values. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class&lt;br /&gt;
|-&lt;br /&gt;
| string || String&lt;br /&gt;
|-&lt;br /&gt;
| number|| Number&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In JavaScript, the primitive value is implicitly converted to a primitive object whenever someone tries to access a property or invoke a method on the primitive value and the primitive object is used in place of the primitive value. Since the object contains properties and methods, the use of primitive value as an object succeeds. After the property is accessed or the method is processed, the primitive object is no longer needed and hence discarded. The same is true for the other primitive types and their corresponding primitive objects.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    var upperCaseString = &amp;quot;APPLE&amp;quot;;&lt;br /&gt;
    var lowerCaseString = upperCaseString.toLowerCase();  // assigns string &amp;quot;apple&amp;quot; to lowerCaseString &lt;br /&gt;
    var s = &amp;quot;Hello&amp;quot;&lt;br /&gt;
    var len = s.length;                                   // assigns value 5 to len&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
&lt;br /&gt;
Since [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] is a [http://www.jvoegele.com/software/langcomp.html pure object oriented] language, everything in Ruby is an object. Hence, all primitive types such as integers, floating point numbers, strings, are objects of a built-in class.&amp;lt;ref&amp;gt;http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Classes in Ruby&amp;lt;/ref&amp;gt; &lt;br /&gt;
All integers are primitive objects of either class [http://corelib.rubyonrails.org/classes/Fixnum.html Fixnum] or [http://corelib.rubyonrails.org/classes/Bignum.html Bignum]. A numeric literal with a decimal point and/or an exponent is a primitive object of [http://corelib.rubyonrails.org/classes/Float.html Float]. Single quoted literals and double quoted literals are primitive objects of [http://corelib.rubyonrails.org/classes/String.html String].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    puts 10.class&lt;br /&gt;
    puts 7.45.class&lt;br /&gt;
    puts 'hi'.class&lt;br /&gt;
    puts &amp;quot;hello&amp;quot;.class&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    Fixnum&lt;br /&gt;
    Float&lt;br /&gt;
    String&lt;br /&gt;
    String&lt;br /&gt;
&lt;br /&gt;
This indicates that 10 is converted into an object of type Fixnum, 7.45 is converted into an object of type Float, 'hi' and &amp;quot;hello&amp;quot; are both converted into an object of type String.&lt;br /&gt;
&lt;br /&gt;
Since all primitive types in Ruby are objects, we should be able to call methods of the Object class on them. Let us demonstrate the same for integer and float using the following example:&lt;br /&gt;
&lt;br /&gt;
    a=10&lt;br /&gt;
    puts a.to_f  &lt;br /&gt;
    b=20.5&lt;br /&gt;
    puts b.to_i&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    10.0&lt;br /&gt;
    20&lt;br /&gt;
&lt;br /&gt;
== Advantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
Advantages that use of primitive data type offers are as follows:&lt;br /&gt;
===[Consistency][http://www.research.ibm.com/people/a/alpert/ptch/ptch.html]===&lt;br /&gt;
Many of Java’s ideas originate in C++ and in C++, objects and primitive type also co-exist. When object-oriented constructs were grafted onto the C language, C’s data types remained as is. The motivation behind this is that Bjarne Stroustrup, C++’s designer, wanted to be as consistent as possible with the base C language, hoping to capitalize on programmers’ pre-C++ knowledge.&lt;br /&gt;
&lt;br /&gt;
===Simplicity===&lt;br /&gt;
It is simple and intuitive to use primitive data type in basic utility.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
1. Recurring number in a loop.(C++)&lt;br /&gt;
&lt;br /&gt;
   for(int i=0;i&amp;lt;10;i++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Temp variables that record only one or two data.&lt;br /&gt;
&lt;br /&gt;
===Performance===&lt;br /&gt;
&lt;br /&gt;
====Time====&lt;br /&gt;
Processing primitive data type operation would be faster than processing composite data type in most cases. There are several reasons result in this differences. &lt;br /&gt;
*Hardware processing discrepancy&lt;br /&gt;
Many primitive data operations (like integer addition) can be performed as a single machine instruction while processing of composite data type would be transformed to a combination of primitive data types. eg. Some processors offer specific instructions to process sequences of characters with a single instruction.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
[http://www.research.ibm.com/people/a/alpert/ptch/ptch.html  Difference in data fetching between primitive data and composite data in Java]&lt;br /&gt;
 &lt;br /&gt;
*Initialization overheads for composite data type&lt;br /&gt;
There are many initialization operations for composite data type. for example boxing and unboxing, constructors and destructors.&lt;br /&gt;
*Allocating and Garbage collection overhead for composite data type&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Performance_implications garbage collection&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.ibm.com/developerworks/java/library/j-jtp01274/index.html Java theory and practice: Garbage collection and performance&amp;lt;/ref&amp;gt;&lt;br /&gt;
Composite data type like class will have allocation and garbage collection overhead that may be beyond the control of the programmer and can sometimes lead to performance problems. For example, commonly used stop-the-world garbage collectors, which pause program execution at arbitrary times, may make garbage collection inappropriate for some [http://en.wikipedia.org/wiki/Embedded_system embedded systems], high-performance [http://en.wikipedia.org/wiki/Server_(computing)  server] software, and applications with [http://en.wikipedia.org/wiki/Real-time_computing real-time] needs.In the early days of Java technology, allocating objects got a high overheads. There were lots of articles advising developers to avoid creating temporary objects unnecessarily because allocation (and the corresponding garbage-collection overhead) was expensive. Although the costs have been greatly reduced nowadays. It still much slower than primitive data type which don’t have such troubles.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
        public class Test{&lt;br /&gt;
        double dur1,dur2;&lt;br /&gt;
        int N=100000000;&lt;br /&gt;
        public void test1()&lt;br /&gt;
        {&lt;br /&gt;
           int a=1,b=1;&lt;br /&gt;
           long startTime1 = System.currentTimeMillis();&lt;br /&gt;
           for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
              a=a+b;&lt;br /&gt;
                          }&lt;br /&gt;
           long endTime1 = System.currentTimeMillis();&lt;br /&gt;
           System.out.println(endTime1-startTime1);&lt;br /&gt;
        }&lt;br /&gt;
        public void test2(){&lt;br /&gt;
            Integer c=new Integer(1);&lt;br /&gt;
            Integer d=new Integer(1);&lt;br /&gt;
            long startTime2 = System.currentTimeMillis();&lt;br /&gt;
            for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
               c=c+d;&lt;br /&gt;
            }&lt;br /&gt;
            long endTime2 = System.currentTimeMillis();&lt;br /&gt;
            System.out.println(endTime2-startTime2)&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
'''Average execution time for test1 is: 1 mm'''&lt;br /&gt;
&lt;br /&gt;
'''Average execution time for test2 is: 702mm'''&lt;br /&gt;
&lt;br /&gt;
'''(test case number: 1000 times )'''&lt;br /&gt;
&lt;br /&gt;
====Space====&lt;br /&gt;
Composite data type will cost more memory space than primitive data type in general. The reason is not only for the overheads generated by constructors, destructors etc, but also the feature of data alignment. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding Data structure alignment&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of data alignment （C++）&lt;br /&gt;
       struct compose&lt;br /&gt;
       {&lt;br /&gt;
           char name;&lt;br /&gt;
           int a;&lt;br /&gt;
           int b;&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
We all know the size of char is 1 byte, the size of int is 4 bytes. But the size of the struct compose as shown above is 12 bytes but not 9 bytes.&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
Discussion of advantages and disadvantages should concerned the functionality you want to implement. For example if you want to operate a serials of int number. The performance of array may be better than int. &amp;lt;ref&amp;gt;http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH05/CH05-2.html composite datatypes&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:1w1.gif]]&lt;br /&gt;
&lt;br /&gt;
To access an element of an array, you need a function that converts an array index into the address of the indexed element. For a single dimension array, this function is very simple. It is&lt;br /&gt;
Element_Address = Base_Address + ((Index - Initial_Index) * Element_Size)&lt;br /&gt;
However, If you use five primitive data type to implement the same function. It may cost more time for the cpu to search the address of each data.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63482</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w21 wi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63482"/>
		<updated>2012-09-11T01:46:01Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Advantages of primitives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Primitive objects in object-oriented languages'''&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
In any programming language, the [http://en.wikipedia.org/wiki/Data_type data type] refers to the class of data which contains specific type or range of values. Data types are used along with variables used in the program. The data type tells us what kind of values the variable can store, what is the range of the values and how much space the values take in memory etc.&lt;br /&gt;
&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Primitive_data_type primitive data types] refer to the built-in data types which are supported by the programming language. Often 'data types' and 'primitive data types' are used interchangeably. But not all data types are primitive. Programming languages have some non-primitive data types or derived data types which are provided by the language by making use of its primitive data types.&lt;br /&gt;
&lt;br /&gt;
The common built-in data types or primitive data types are integers, floating point numbers, characters, strings and boolean.&lt;br /&gt;
* Integers - Integers represent the whole numbers which can be positive or negative or zero, e.g. 9999, 0, -25, etc. &lt;br /&gt;
* Floating point numbers - Floating point numbers represent the numbers which are fractions or contain floating-decimal points, e.g. -3.002, 2.5, 22.0, etc.&lt;br /&gt;
* Characters - Characters represent any single letter, number, space, punctuation mark, or symbol that can be typed on a computer, e.g. 'a', '9', ' ', '!' , '\n', etc.&lt;br /&gt;
* Strings - Strings represent the sequences of characters or simply any text, e.g. &amp;quot;Hello!&amp;quot;, &amp;quot;9 am to 6 pm&amp;quot;, etc. &lt;br /&gt;
* Booleans - Booleans represent the true or false values. Sometimes, instead of true and false, 1 and 0 are used to represent the boolean values.&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] languages provide support for primitive data types while some object-oriented programming languages provide support for primitive objects along with primitive types.&lt;br /&gt;
&lt;br /&gt;
== Definition ==&lt;br /&gt;
&lt;br /&gt;
Primitive objects refer to the objects of built-in classes which provide more functionality than the primitive types. Some object-oriented programming languages provide support for only primitive objects (i.e., in such languages all primitive types are objects).&lt;br /&gt;
&lt;br /&gt;
Different object-oriented programming languages implement these primitive data types and primitive objects in a different manner.&lt;br /&gt;
&lt;br /&gt;
== Primitive objects in different OO languages ==&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java], there are 8 primitive types: boolean, char, byte, short, int, long, float, and double. &amp;lt;ref&amp;gt;http://www.cafeaulait.org/course/week2/02.html Java's Primitive Data Types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each of these primitive types, Java provides [http://en.wikipedia.org/wiki/Primitive_wrapper_class wrapper classes] to create primitive objects which wrap the primitive data values. A wrapper  not only contains the primitive data value, but it also defines properties and methods that can be used to manipulate that data. In Java, the primitive values are not implicitly converted to primitive objects. Instead, methods are provided for doing explicit conversion.&lt;br /&gt;
The primitive objects are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack heap] in memory while the variables containing primitive values are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack stack].&amp;lt;ref&amp;gt;http://www.informit.com/articles/article.aspx?p=31755&amp;amp;seqNum=8 Stack and Heap memory&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class!! Size&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean || 1-bit&lt;br /&gt;
|-&lt;br /&gt;
| char || Character || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| byte || Byte || 8-bit&lt;br /&gt;
|-&lt;br /&gt;
| short || Short || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| int || Integer || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| long || Long || 64-bit&lt;br /&gt;
|-&lt;br /&gt;
| float || Float || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| double || Double || 64-bit&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 20;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I+II);            &lt;br /&gt;
    System.out.println(I.equals(II));    &lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    30&lt;br /&gt;
    false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find out if these wrapper classes are primitive or not, we can use the isPrimitive() method.&lt;br /&gt;
&lt;br /&gt;
    System.out.println(INTEGER.TYPE.isPrimitive());&lt;br /&gt;
    System.out.println(BOOLEAN.TYPE.isPrimitive());&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    true&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java, the comparison operations work in the same way on the primitive objects as well as any other class objects but different on the primitive types. The == operator when used on objects checks whether they refer to the same object but when used on variables of primitive types checks whether they contain the same value.&amp;lt;ref&amp;gt;http://leepoint.net/notes-java/data/expressions/22compareobjects.html Comparisons in Java&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 10;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I==II);            &lt;br /&gt;
    System.out.println(i==ii);&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    false&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29 C#] is a [http://en.wikipedia.org/wiki/Strong_typing strongly typed] language, where it is necessary to declare the data type of a variable and also be aware of the data type conversion. C# provides a significant number of primitive data types.&amp;lt;ref&amp;gt;http://condor.depaul.edu/sjost/ndp/notes/cs1/CSDatatypes.htm C# Primitive Datatypes&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.java2s.com/Tutorial/CSharp/0040__Data-Type/PrimitivesinC.htm Primitives in C#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type. For example:&lt;br /&gt;
 &lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        int x = 7;&lt;br /&gt;
        object o = x;&lt;br /&gt;
        System.Console.WriteLine(o.ToString());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Some data types (e.g. Decimal and String) can appear like primitives at first sight, but are actually not. So it is important to exercise caution before making such assumptions. To test whether a particular type is a primitive or not you can use the property Type.IsPrimitive.&lt;br /&gt;
&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;br /&gt;
    if (t.IsPrimitive)    // where t is the type&lt;br /&gt;
    {&lt;br /&gt;
        // Is Primitive&lt;br /&gt;
    } else if (t == typeof(Decimal))&lt;br /&gt;
    {&lt;br /&gt;
        // Is Decimal&lt;br /&gt;
    } else if (t == typeof(String))&lt;br /&gt;
    {&lt;br /&gt;
        // Is String&lt;br /&gt;
    } else&lt;br /&gt;
    {&lt;br /&gt;
        // Other type&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== JavaScript ===&lt;br /&gt;
&lt;br /&gt;
There are 5 primitive data types in [http://en.wikipedia.org/wiki/JavaScript JavaScript]: string, number, boolean, null and undefined. &amp;lt;ref&amp;gt;http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html JavaScript Data Types and Variables&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For string, number and boolean values, there are corresponding classes just like in Java to create primitive objects which wrap the primitive values. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class&lt;br /&gt;
|-&lt;br /&gt;
| string || String&lt;br /&gt;
|-&lt;br /&gt;
| number|| Number&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In JavaScript, the primitive value is implicitly converted to a primitive object whenever someone tries to access a property or invoke a method on the primitive value and the primitive object is used in place of the primitive value. Since the object contains properties and methods, the use of primitive value as an object succeeds. After the property is accessed or the method is processed, the primitive object is no longer needed and hence discarded. The same is true for the other primitive types and their corresponding primitive objects.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    var upperCaseString = &amp;quot;APPLE&amp;quot;;&lt;br /&gt;
    var lowerCaseString = upperCaseString.toLowerCase();  // assigns string &amp;quot;apple&amp;quot; to lowerCaseString &lt;br /&gt;
    var s = &amp;quot;Hello&amp;quot;&lt;br /&gt;
    var len = s.length;                                   // assigns value 5 to len&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
&lt;br /&gt;
Since [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] is a [http://www.jvoegele.com/software/langcomp.html pure object oriented] language, everything in Ruby is an object. Hence, all primitive types such as integers, floating point numbers, strings, are objects of a built-in class.&amp;lt;ref&amp;gt;http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Classes in Ruby&amp;lt;/ref&amp;gt; &lt;br /&gt;
All integers are primitive objects of either class [http://corelib.rubyonrails.org/classes/Fixnum.html Fixnum] or [http://corelib.rubyonrails.org/classes/Bignum.html Bignum]. A numeric literal with a decimal point and/or an exponent is a primitive object of [http://corelib.rubyonrails.org/classes/Float.html Float]. Single quoted literals and double quoted literals are primitive objects of [http://corelib.rubyonrails.org/classes/String.html String].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    puts 10.class&lt;br /&gt;
    puts 7.45.class&lt;br /&gt;
    puts 'hi'.class&lt;br /&gt;
    puts &amp;quot;hello&amp;quot;.class&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    Fixnum&lt;br /&gt;
    Float&lt;br /&gt;
    String&lt;br /&gt;
    String&lt;br /&gt;
&lt;br /&gt;
This indicates that 10 is converted into an object of type Fixnum, 7.45 is converted into an object of type Float, 'hi' and &amp;quot;hello&amp;quot; are both converted into an object of type String.&lt;br /&gt;
&lt;br /&gt;
Since all primitive types in Ruby are objects, we should be able to call methods of the Object class on them. Let us demonstrate the same for integer and float using the following example:&lt;br /&gt;
&lt;br /&gt;
    a=10&lt;br /&gt;
    puts a.to_f  &lt;br /&gt;
    b=20.5&lt;br /&gt;
    puts b.to_i&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    10.0&lt;br /&gt;
    20&lt;br /&gt;
&lt;br /&gt;
== Advantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
Advantages that use of primitive data type offers are as follows:&lt;br /&gt;
===Consistency===&lt;br /&gt;
many of Java’s ideas originate in C++ and in C++, objects and primitive type also co-exist. When object-oriented constructs were grafted onto the C language, C’s data types remained as is. The motivation behind this is that Bjarne Stroustrup, C++’s designer, wanted to be as consistent as possible with the base C language, hoping to capitalize on programmers’ pre-C++ knowledge. &lt;br /&gt;
&lt;br /&gt;
===Simplicity===&lt;br /&gt;
It is simple and intuitive to use primitive data type in basic utility.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
1. Recurring number in a loop.(C++)&lt;br /&gt;
&lt;br /&gt;
   for(int i=0;i&amp;lt;10;i++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Temp variables that record only one or two data.&lt;br /&gt;
&lt;br /&gt;
===Performance===&lt;br /&gt;
&lt;br /&gt;
====Time====&lt;br /&gt;
Processing primitive data type operation would be faster than processing composite data type in most cases. There are several reasons result in this differences. &lt;br /&gt;
*Hardware processing discrepancy&lt;br /&gt;
Many primitive data operations (like integer addition) can be performed as a single machine instruction while processing of composite data type would be transformed to a combination of primitive data types. eg. Some processors offer specific instructions to process sequences of characters with a single instruction.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
[http://www.research.ibm.com/people/a/alpert/ptch/ptch.html  Difference in data fetching between primitive data and composite data in Java]&lt;br /&gt;
 &lt;br /&gt;
*Initialization overheads for composite data type&lt;br /&gt;
There are many initialization operations for composite data type. for example boxing and unboxing, constructors and destructors.&lt;br /&gt;
*Allocating and Garbage collection overhead for composite data type&lt;br /&gt;
Composite data type like class will have allocation and garbage collection overhead that may be beyond the control of the programmer and can sometimes lead to performance problems. For example, commonly used stop-the-world garbage collectors, which pause program execution at arbitrary times, may make garbage collection inappropriate for some [http://en.wikipedia.org/wiki/Embedded_system embedded systems], high-performance [http://en.wikipedia.org/wiki/Server_(computing)  server] software, and applications with [http://en.wikipedia.org/wiki/Real-time_computing real-time] needs.In the early days of Java technology, allocating objects got a high overheads. There were lots of articles advising developers to avoid creating temporary objects unnecessarily because allocation (and the corresponding garbage-collection overhead) was expensive. Although the costs have been greatly reduced nowadays. It still much slower than primitive data type which don’t have such troubles.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
        public class Test{&lt;br /&gt;
        double dur1,dur2;&lt;br /&gt;
        int N=100000000;&lt;br /&gt;
        public void test1()&lt;br /&gt;
        {&lt;br /&gt;
           int a=1,b=1;&lt;br /&gt;
           long startTime1 = System.currentTimeMillis();&lt;br /&gt;
           for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
              a=a+b;&lt;br /&gt;
                          }&lt;br /&gt;
           long endTime1 = System.currentTimeMillis();&lt;br /&gt;
           System.out.println(endTime1-startTime1);&lt;br /&gt;
        }&lt;br /&gt;
        public void test2(){&lt;br /&gt;
            Integer c=new Integer(1);&lt;br /&gt;
            Integer d=new Integer(1);&lt;br /&gt;
            long startTime2 = System.currentTimeMillis();&lt;br /&gt;
            for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
               c=c+d;&lt;br /&gt;
            }&lt;br /&gt;
            long endTime2 = System.currentTimeMillis();&lt;br /&gt;
            System.out.println(endTime2-startTime2)&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
'''Average execution time for test1 is: 1 mm'''&lt;br /&gt;
&lt;br /&gt;
'''Average execution time for test2 is: 702mm'''&lt;br /&gt;
&lt;br /&gt;
'''(test case number: 1000 times )'''&lt;br /&gt;
&lt;br /&gt;
====Space====&lt;br /&gt;
Composite data type will cost more memory space than primitive data type in general. The reason is not only for the overheads generated by constructors, destructors etc, but also the feature of data alignment.&lt;br /&gt;
&lt;br /&gt;
Example of data alignment （C++）&lt;br /&gt;
       struct compose&lt;br /&gt;
       {&lt;br /&gt;
           char name;&lt;br /&gt;
           int a;&lt;br /&gt;
           int b;&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
We all know the size of char is 1 byte, the size of int is 4 bytes. But the size of the struct compose as shown above is 12 bytes but not 9 bytes.&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
Discussion of advantages and disadvantages should concerned the functionality you want to implement. For example if you want to operate a serials of int number. The performance of array may be better than int.&lt;br /&gt;
&lt;br /&gt;
[[File:1w1.gif]]&lt;br /&gt;
&lt;br /&gt;
To access an element of an array, you need a function that converts an array index into the address of the indexed element. For a single dimension array, this function is very simple. It is&lt;br /&gt;
Element_Address = Base_Address + ((Index - Initial_Index) * Element_Size)&lt;br /&gt;
However, If you use five primitive data type to implement the same function. It may cost more time for the cpu to search the address of each data.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63476</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w21 wi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w21_wi&amp;diff=63476"/>
		<updated>2012-09-11T01:26:44Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Space */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Primitive objects in object-oriented languages'''&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
In any programming language, the [http://en.wikipedia.org/wiki/Data_type data type] refers to the class of data which contains specific type or range of values. Data types are used along with variables used in the program. The data type tells us what kind of values the variable can store, what is the range of the values and how much space the values take in memory etc.&lt;br /&gt;
&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Primitive_data_type primitive data types] refer to the built-in data types which are supported by the programming language. Often 'data types' and 'primitive data types' are used interchangeably. But not all data types are primitive. Programming languages have some non-primitive data types or derived data types which are provided by the language by making use of its primitive data types.&lt;br /&gt;
&lt;br /&gt;
The common built-in data types or primitive data types are integers, floating point numbers, characters, strings and boolean.&lt;br /&gt;
* Integers - Integers represent the whole numbers which can be positive or negative or zero, e.g. 9999, 0, -25, etc. &lt;br /&gt;
* Floating point numbers - Floating point numbers represent the numbers which are fractions or contain floating-decimal points, e.g. -3.002, 2.5, 22.0, etc.&lt;br /&gt;
* Characters - Characters represent any single letter, number, space, punctuation mark, or symbol that can be typed on a computer, e.g. 'a', '9', ' ', '!' , '\n', etc.&lt;br /&gt;
* Strings - Strings represent the sequences of characters or simply any text, e.g. &amp;quot;Hello!&amp;quot;, &amp;quot;9 am to 6 pm&amp;quot;, etc. &lt;br /&gt;
* Booleans - Booleans represent the true or false values. Sometimes, instead of true and false, 1 and 0 are used to represent the boolean values.&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] languages provide support for primitive data types while some object-oriented programming languages provide support for primitive objects along with primitive types.&lt;br /&gt;
&lt;br /&gt;
== Definition ==&lt;br /&gt;
&lt;br /&gt;
Primitive objects refer to the objects of built-in classes which provide more functionality than the primitive types. Some object-oriented programming languages provide support for only primitive objects (i.e., in such languages all primitive types are objects).&lt;br /&gt;
&lt;br /&gt;
Different object-oriented programming languages implement these primitive data types and primitive objects in a different manner.&lt;br /&gt;
&lt;br /&gt;
== Primitive objects in different OO languages ==&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java], there are 8 primitive types: boolean, char, byte, short, int, long, float, and double. &amp;lt;ref&amp;gt;http://www.cafeaulait.org/course/week2/02.html Java's Primitive Data Types&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each of these primitive types, Java provides [http://en.wikipedia.org/wiki/Primitive_wrapper_class wrapper classes] to create primitive objects which wrap the primitive data values. A wrapper  not only contains the primitive data value, but it also defines properties and methods that can be used to manipulate that data. In Java, the primitive values are not implicitly converted to primitive objects. Instead, methods are provided for doing explicit conversion.&lt;br /&gt;
The primitive objects are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack heap] in memory while the variables containing primitive values are stored on [http://www.maxi-pedia.com/what+is+heap+and+stack stack].&amp;lt;ref&amp;gt;http://www.informit.com/articles/article.aspx?p=31755&amp;amp;seqNum=8 Stack and Heap memory&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class!! Size&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean || 1-bit&lt;br /&gt;
|-&lt;br /&gt;
| char || Character || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| byte || Byte || 8-bit&lt;br /&gt;
|-&lt;br /&gt;
| short || Short || 16-bit&lt;br /&gt;
|-&lt;br /&gt;
| int || Integer || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| long || Long || 64-bit&lt;br /&gt;
|-&lt;br /&gt;
| float || Float || 32-bit&lt;br /&gt;
|-&lt;br /&gt;
| double || Double || 64-bit&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 20;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I+II);            &lt;br /&gt;
    System.out.println(I.equals(II));    &lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    30&lt;br /&gt;
    false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find out if these wrapper classes are primitive or not, we can use the isPrimitive() method.&lt;br /&gt;
&lt;br /&gt;
    System.out.println(INTEGER.TYPE.isPrimitive());&lt;br /&gt;
    System.out.println(BOOLEAN.TYPE.isPrimitive());&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    true&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java, the comparison operations work in the same way on the primitive objects as well as any other class objects but different on the primitive types. The == operator when used on objects checks whether they refer to the same object but when used on variables of primitive types checks whether they contain the same value.&amp;lt;ref&amp;gt;http://leepoint.net/notes-java/data/expressions/22compareobjects.html Comparisons in Java&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
    int i = 10;&lt;br /&gt;
    int ii = 10;&lt;br /&gt;
    Integer I = new Integer(i);&lt;br /&gt;
    Integer II = new Integer(ii);&lt;br /&gt;
    System.out.println(I==II);            &lt;br /&gt;
    System.out.println(i==ii);&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    false&lt;br /&gt;
    true&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29 C#] is a [http://en.wikipedia.org/wiki/Strong_typing strongly typed] language, where it is necessary to declare the data type of a variable and also be aware of the data type conversion. C# provides a significant number of primitive data types.&amp;lt;ref&amp;gt;http://condor.depaul.edu/sjost/ndp/notes/cs1/CSDatatypes.htm C# Primitive Datatypes&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.java2s.com/Tutorial/CSharp/0040__Data-Type/PrimitivesinC.htm Primitives in C#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type. For example:&lt;br /&gt;
 &lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        int x = 7;&lt;br /&gt;
        object o = x;&lt;br /&gt;
        System.Console.WriteLine(o.ToString());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Some data types (e.g. Decimal and String) can appear like primitives at first sight, but are actually not. So it is important to exercise caution before making such assumptions. To test whether a particular type is a primitive or not you can use the property Type.IsPrimitive.&lt;br /&gt;
&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;br /&gt;
    if (t.IsPrimitive)    // where t is the type&lt;br /&gt;
    {&lt;br /&gt;
        // Is Primitive&lt;br /&gt;
    } else if (t == typeof(Decimal))&lt;br /&gt;
    {&lt;br /&gt;
        // Is Decimal&lt;br /&gt;
    } else if (t == typeof(String))&lt;br /&gt;
    {&lt;br /&gt;
        // Is String&lt;br /&gt;
    } else&lt;br /&gt;
    {&lt;br /&gt;
        // Other type&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== JavaScript ===&lt;br /&gt;
&lt;br /&gt;
There are 5 primitive data types in [http://en.wikipedia.org/wiki/JavaScript JavaScript]: string, number, boolean, null and undefined. &amp;lt;ref&amp;gt;http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html JavaScript Data Types and Variables&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For string, number and boolean values, there are corresponding classes just like in Java to create primitive objects which wrap the primitive values. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &lt;br /&gt;
|-&lt;br /&gt;
! Primitive Type !! Wrapper Class&lt;br /&gt;
|-&lt;br /&gt;
| string || String&lt;br /&gt;
|-&lt;br /&gt;
| number|| Number&lt;br /&gt;
|-&lt;br /&gt;
| boolean || Boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In JavaScript, the primitive value is implicitly converted to a primitive object whenever someone tries to access a property or invoke a method on the primitive value and the primitive object is used in place of the primitive value. Since the object contains properties and methods, the use of primitive value as an object succeeds. After the property is accessed or the method is processed, the primitive object is no longer needed and hence discarded. The same is true for the other primitive types and their corresponding primitive objects.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    var upperCaseString = &amp;quot;APPLE&amp;quot;;&lt;br /&gt;
    var lowerCaseString = upperCaseString.toLowerCase();  // assigns string &amp;quot;apple&amp;quot; to lowerCaseString &lt;br /&gt;
    var s = &amp;quot;Hello&amp;quot;&lt;br /&gt;
    var len = s.length;                                   // assigns value 5 to len&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
&lt;br /&gt;
Since [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] is a [http://www.jvoegele.com/software/langcomp.html pure object oriented] language, everything in Ruby is an object. Hence, all primitive types such as integers, floating point numbers, strings, are objects of a built-in class.&amp;lt;ref&amp;gt;http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Classes in Ruby&amp;lt;/ref&amp;gt; &lt;br /&gt;
All integers are primitive objects of either class [http://corelib.rubyonrails.org/classes/Fixnum.html Fixnum] or [http://corelib.rubyonrails.org/classes/Bignum.html Bignum]. A numeric literal with a decimal point and/or an exponent is a primitive object of [http://corelib.rubyonrails.org/classes/Float.html Float]. Single quoted literals and double quoted literals are primitive objects of [http://corelib.rubyonrails.org/classes/String.html String].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
    puts 10.class&lt;br /&gt;
    puts 7.45.class&lt;br /&gt;
    puts 'hi'.class&lt;br /&gt;
    puts &amp;quot;hello&amp;quot;.class&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    Fixnum&lt;br /&gt;
    Float&lt;br /&gt;
    String&lt;br /&gt;
    String&lt;br /&gt;
&lt;br /&gt;
This indicates that 10 is converted into an object of type Fixnum, 7.45 is converted into an object of type Float, 'hi' and &amp;quot;hello&amp;quot; are both converted into an object of type String.&lt;br /&gt;
&lt;br /&gt;
Since all primitive types in Ruby are objects, we should be able to call methods of the Object class on them. Let us demonstrate the same for integer and float using the following example:&lt;br /&gt;
&lt;br /&gt;
    a=10&lt;br /&gt;
    puts a.to_f  &lt;br /&gt;
    b=20.5&lt;br /&gt;
    puts b.to_i&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
    10.0&lt;br /&gt;
    20&lt;br /&gt;
&lt;br /&gt;
== Advantages of primitives ==&lt;br /&gt;
&lt;br /&gt;
Advantages that use of primitive data type offers are as follows:&lt;br /&gt;
===Simplicity===&lt;br /&gt;
It is simple and intuitive to use primitive data type in basic utility.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
1. Recurring number in a loop.(C++)&lt;br /&gt;
&lt;br /&gt;
   for(int i=0;i&amp;lt;10;i++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Temp variables that record only one or two data.&lt;br /&gt;
&lt;br /&gt;
===Performance===&lt;br /&gt;
&lt;br /&gt;
====Time====&lt;br /&gt;
Processing primitive data type operation would be faster than processing composite data type in most cases. There are several reasons result in this differences. &lt;br /&gt;
*Hardware processing discrepancy&lt;br /&gt;
Many primitive data operations (like integer addition) can be performed as a single machine instruction while processing of composite data type would be transformed to a combination of primitive data types. eg. Some processors offer specific instructions to process sequences of characters with a single instruction.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
[http://www.research.ibm.com/people/a/alpert/ptch/ptch.html  Difference in data fetching between primitive data and composite data in Java]&lt;br /&gt;
 &lt;br /&gt;
*Initialization overheads for composite data type&lt;br /&gt;
There are many initialization operations for composite data type. for example boxing and unboxing, constructors and destructors.&lt;br /&gt;
*Allocating and Garbage collection overhead for composite data type&lt;br /&gt;
Composite data type like class will have allocation and garbage collection overhead that may be beyond the control of the programmer and can sometimes lead to performance problems. For example, commonly used stop-the-world garbage collectors, which pause program execution at arbitrary times, may make garbage collection inappropriate for some [http://en.wikipedia.org/wiki/Embedded_system embedded systems], high-performance [http://en.wikipedia.org/wiki/Server_(computing)  server] software, and applications with [http://en.wikipedia.org/wiki/Real-time_computing real-time] needs.In the early days of Java technology, allocating objects got a high overheads. There were lots of articles advising developers to avoid creating temporary objects unnecessarily because allocation (and the corresponding garbage-collection overhead) was expensive. Although the costs have been greatly reduced nowadays. It still much slower than primitive data type which don’t have such troubles.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
        public class Test{&lt;br /&gt;
        double dur1,dur2;&lt;br /&gt;
        int N=100000000;&lt;br /&gt;
        public void test1()&lt;br /&gt;
        {&lt;br /&gt;
           int a=1,b=1;&lt;br /&gt;
           long startTime1 = System.currentTimeMillis();&lt;br /&gt;
           for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
              a=a+b;&lt;br /&gt;
                          }&lt;br /&gt;
           long endTime1 = System.currentTimeMillis();&lt;br /&gt;
           System.out.println(endTime1-startTime1);&lt;br /&gt;
        }&lt;br /&gt;
        public void test2(){&lt;br /&gt;
            Integer c=new Integer(1);&lt;br /&gt;
            Integer d=new Integer(1);&lt;br /&gt;
            long startTime2 = System.currentTimeMillis();&lt;br /&gt;
            for(int i=0;i&amp;lt;N;i++){&lt;br /&gt;
               c=c+d;&lt;br /&gt;
            }&lt;br /&gt;
            long endTime2 = System.currentTimeMillis();&lt;br /&gt;
            System.out.println(endTime2-startTime2)&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
'''Average execution time for test1 is: 1 mm'''&lt;br /&gt;
&lt;br /&gt;
'''Average execution time for test2 is: 702mm'''&lt;br /&gt;
&lt;br /&gt;
'''(test case number: 1000 times )'''&lt;br /&gt;
&lt;br /&gt;
====Space====&lt;br /&gt;
Composite data type will cost more memory space than primitive data type in general. The reason is not only for the overheads generated by constructors, destructors etc, but also the feature of data alignment.&lt;br /&gt;
&lt;br /&gt;
Example of data alignment （C++）&lt;br /&gt;
       struct compose&lt;br /&gt;
       {&lt;br /&gt;
           char name;&lt;br /&gt;
           int a;&lt;br /&gt;
           int b;&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
We all know the size of char is 1 byte, the size of int is 4 bytes. But the size of the struct compose as shown above is 12 bytes but not 9 bytes.&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
Discussion of advantages and disadvantages should concerned the functionality you want to implement. For example if you want to operate a serials of int number. The performance of array may be better than int.&lt;br /&gt;
&lt;br /&gt;
[[File:1w1.gif]]&lt;br /&gt;
&lt;br /&gt;
To access an element of an array, you need a function that converts an array index into the address of the indexed element. For a single dimension array, this function is very simple. It is&lt;br /&gt;
Element_Address = Base_Address + ((Index - Initial_Index) * Element_Size)&lt;br /&gt;
However, If you use five primitive data type to implement the same function. It may cost more time for the cpu to search the address of each data.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=63272</id>
		<title>CSC/ECE 517 Fall 2012</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=63272"/>
		<updated>2012-09-10T02:02:40Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE 517 Fall 2012/ch1 n xx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w1 rk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w20 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w6 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w7 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w8 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w10 pk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w14 gv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w17 ir]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w22 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 aa]]&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w17_ss&amp;diff=63271</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w17 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w17_ss&amp;diff=63271"/>
		<updated>2012-09-10T02:02:27Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: Blanked the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w17_ss&amp;diff=63270</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w17 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w17_ss&amp;diff=63270"/>
		<updated>2012-09-10T01:21:12Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== '''Extending objects''' ==&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w17_ss&amp;diff=63269</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w17 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w17_ss&amp;diff=63269"/>
		<updated>2012-09-10T01:20:50Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Extending objects */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
&lt;br /&gt;
'''== Extending objects =='''&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w17_ss&amp;diff=63268</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w17 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w17_ss&amp;diff=63268"/>
		<updated>2012-09-10T01:20:29Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== Extending objects ==&lt;br /&gt;
'''&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w17_ss&amp;diff=63267</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w17 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w17_ss&amp;diff=63267"/>
		<updated>2012-09-10T01:20:07Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: /* Extending objects */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
'''== Extending objects =='''&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w17_ss&amp;diff=63266</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w17 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w17_ss&amp;diff=63266"/>
		<updated>2012-09-10T01:19:10Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: Created page with &amp;quot; == Extending objects ==&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Extending objects ==&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=63265</id>
		<title>CSC/ECE 517 Fall 2012</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=63265"/>
		<updated>2012-09-10T01:18:36Z</updated>

		<summary type="html">&lt;p&gt;Yliu63: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE 517 Fall 2012/ch1 n xx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w1 rk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w20 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w6 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w7 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w8 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w10 pk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w14 gv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w17 ir]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w22 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w17 ss]]&lt;/div&gt;</summary>
		<author><name>Yliu63</name></author>
	</entry>
</feed>