<?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=Kkalker</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=Kkalker"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Kkalker"/>
	<updated>2026-07-14T03:43:50Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=55760</id>
		<title>CSC/ECE 517 Fall 2011/ch6 6c sj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=55760"/>
		<updated>2011-11-18T00:44:04Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Generic Programming==&lt;br /&gt;
&amp;lt;p&amp;gt;Generic programming is a style of computer programming in which algorithms are written in terms of &amp;lt;i&amp;gt;to-be-specified-later&amp;lt;/i&amp;gt; types that are then instantiated when needed for specific types provided as parameters. This enables writing common set of functions which differ only in the types on which they operate. This reduces duplication. Software entities created using generic programming are known as ''generics'' in [http://en.wikipedia.org/wiki/Ada_(programming_language) Ada], [http://en.wikipedia.org/wiki/Eiffel_(programming_language) Eiffel], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/F_Sharp_(programming_language) F#], and [http://en.wikipedia.org/wiki/Visual_Basic_.NET Visual Basic .NET]; parametric polymorphism in [http://en.wikipedia.org/wiki/ML_(programming_language) ML], [http://en.wikipedia.org/wiki/Scala_(programming_language Scala] and [http://en.wikipedia.org/wiki/Haskell_(programming_language) Haskell], [http://en.wikipedia.org/wiki/template_(programming) template]s in [http://en.wikipedia.org/wiki/C++ C++].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;For example, given various data structures and several algorithms, the brute force way would be implement them for each data structure which would mean that various combinations of implementations will be necessary. Generic programming reduces this effort.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Generics in Java==&lt;br /&gt;
===What are Generics?===&lt;br /&gt;
Generics were added to Java programming language as a part of J2SE 5.0 release in 2004. They allow programmers to develop generic and compile safe applications which enables a type or method to operate on objects of various type. This feature is well utilized while implementing [http://en.wikipedia.org/wiki/Java_Collections Java Collections]. The reason why people went into generic programming can be well explained using the below example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  List list = new ArrayList();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = (Integer)list.get(0);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this example, we insert a &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; into an &amp;lt;code&amp;gt;ArrayList&amp;lt;/code&amp;gt; and retrieve element by typecasting with Integer wrapper class. This throws a runtime exception because of Illegal class cast. But if we use generics, runtime exceptions can be avoided and the compiler will be able to catch such issues which in turn help a programmer to build a bug free code. So if we convert the above code to use generic then it would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  List&amp;lt;String&amp;gt; list = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = list.get(0); //line 1 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here at line 1 the compiler throws an error because the compiler on seeing the declaration of ArrayList will be expecting the list to have just &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; and thereby the return type of &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt; to be &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Implementing Generics:===&lt;br /&gt;
Java provides a feature which helps one to implement your own generic types and this will help to build more sophisticated and runtime error free applications. Consider the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
   interface List&amp;lt;N&amp;gt; {&lt;br /&gt;
                         void add(N i);&lt;br /&gt;
                         Iterator&amp;lt;N&amp;gt; iterator();&lt;br /&gt;
                      }&lt;br /&gt;
   interface Iterator&amp;lt;N&amp;gt; {&lt;br /&gt;
                            N next();&lt;br /&gt;
                            boolean hasNext();&lt;br /&gt;
                         }&lt;br /&gt;
   class LinkedList&amp;lt;N&amp;gt; implements List&amp;lt;N&amp;gt; {&lt;br /&gt;
                          //Business Logic   &lt;br /&gt;
                 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
So here, &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; can be replaced with any primitive data types or wrapper classes in the business logic. But we need to make sure that placeholders to be replaced with valid subtypes of Object. Generics implementation is not restricted for classes or interfaces, we can have for static/non static methods and constructors.&lt;br /&gt;
&lt;br /&gt;
Example for generic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;T&amp;gt; void fromArrayToCollection(T[] a, Collection&amp;lt;T&amp;gt; c) {&lt;br /&gt;
    for (T o : a) {&lt;br /&gt;
        c.add(o); // Correct&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Pros and Cons===&lt;br /&gt;
&amp;lt;b&amp;gt;Pros:&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduces the number of casts in the program, which in turn reduces the number of potential bugs in the program.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Improves code clarity and maintenance.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Cons:&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Parameter type information is not available at run time.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;The automatically generated casts may fail when interoperating with ill-behaved legacy code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Templates in C++==&lt;br /&gt;
===What are templates?===&lt;br /&gt;
&amp;lt;p&amp;gt;Templates are functions that can operate with &amp;lt;i&amp;gt;generic types&amp;lt;/i&amp;gt; which means that the functionality can be adapted for more than one type of data without repeating the entire code for each type. &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
===Overview===&lt;br /&gt;
Templates can be either function templates or class templates.&lt;br /&gt;
====Function Templates====&lt;br /&gt;
These are just like regular functions except that they can have arguments of different types. A single function definition works with different kinds of data types. During compile time, the actual functions are generated once the compiler knows the data type being used. This kind of template does not save any memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;typename Type&amp;gt;&lt;br /&gt;
Type max(Type a, Type b) {&lt;br /&gt;
    return a &amp;gt; b ? a : b;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  // This will call max &amp;lt;int&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3, 7) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This will call max&amp;lt;double&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3.0, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This type is ambiguous, so explicitly instantiate max&amp;lt;double&amp;gt;&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max&amp;lt;double&amp;gt;(3, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Class Templates====&lt;br /&gt;
A class template provides a specification for generating classes based on parameters. A class template is instantiated by passing a given set of types to it as template arguments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;class T&amp;gt;&lt;br /&gt;
class mypair {&lt;br /&gt;
    T values [2];&lt;br /&gt;
  public:&lt;br /&gt;
    mypair (T first, T second)&lt;br /&gt;
    {&lt;br /&gt;
      values[0]=first; values[1]=second;&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Features of C++ Templates===&lt;br /&gt;
Some of the features of C++ templates are:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Implemented in the compiler.&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;No runtime overhead&amp;lt;/ul&amp;gt;&amp;lt;ul&amp;gt;Requires template source to be in headers&amp;lt;/ul&amp;gt;&amp;lt;ul&amp;gt;Latent typing means template instantiator does no type checking&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Gloriﬁed macro facility&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;“Macros done right”/“Macros that look like classes”&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Can use template arguments for both classes and straight function&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Template specialization&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;Speciﬁc implementation of a templated type or method&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pattern matching and text replacement&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;Declarative model (like [http://en.wikipedia.org/wiki/Prolog Prolog])&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pros and Cons===&lt;br /&gt;
Usage of templates have both advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Pros&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduction in code size.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They are type-safe, that is, type-checking is done at compile time.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Cons&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Since all compilers are not good at their support for templates, they may not be very portable.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Compilers generate additional code for each template type, this could lead to huge code if usage of templates is not checked.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Information hiding is not achieved as the code is all exposed in the header.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Templates (C++) versus Generics (Java)==&lt;br /&gt;
We can compare templates in C++ versus generics in Java based on the following models of comparison,&lt;br /&gt;
1. Translation model - discussion based on the way generic code is translated.&lt;br /&gt;
2. Type model - discussion based on implementations in type interference, type aliasing and associated types.&lt;br /&gt;
3. Security model - discussion based on security loopholes, if any.&lt;br /&gt;
Let's look at these with some examples.&lt;br /&gt;
&lt;br /&gt;
===Translation Model===&lt;br /&gt;
====Java====&lt;br /&gt;
One of the design reasons behind Java's generics was to provide backward compatibility of legacy Java code. To achieve this, Java implementation has adopted the same representation policy for the raw type and the parametric type. The parametric type Collection&amp;lt;T&amp;gt; can be passed safely where the corresponding raw type Collection is expected. Hence the translation model of Java Generics is based on the “type erasure” model, where the translation erases the generic type parameter, replaces them by the bounding type (Object) and inserts casts to the actual places of usage. In order for method overriding to work correctly, the translation process also adds “bridge methods”, as illustrated in the following example.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class C&amp;lt;A&amp;gt; { abstract A id(A x); } &lt;br /&gt;
class D extends C&amp;lt;String&amp;gt; { String id(String x) { return x; } } &lt;br /&gt;
This will be translated to: &lt;br /&gt;
class C { abstract Object id(Object x); } &lt;br /&gt;
class D extends C { &lt;br /&gt;
    String id(String x) { return x; } &lt;br /&gt;
    // bridge method introduced by the translator to make  &lt;br /&gt;
    // overriding work correctly &lt;br /&gt;
    Object id(Object x) { return id((String)x); }  &lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====C++====&lt;br /&gt;
The translation model of C++ is based on instantiation – no static type checking is done on the generic code. The compiler generates separate copies of the component (class or function) for each instantiation with a distinct type and the type checking is performed after instantiation at each call site. Type checking of the bound types can only succeed when the input types have satisfied the type requirements of the function template body. It is because of this, that misleading error messages are thrown in by the compiler when a generic component is instantiated with an improper type.&lt;br /&gt;
&lt;br /&gt;
====Comparison====&lt;br /&gt;
The C++ model is loss-less in the sense that no type information is lost during runtime, though the implementation of the translation suffers from the drawbacks of the possibility of introducing code bloats and misleading error messages. On the other hand, the Java model emphasizes on retrofitting the raw types with the generic counterparts, but the type-erasure model delegates the generic types to “second class” status compared to the conventional types.&lt;br /&gt;
&lt;br /&gt;
===Type Model===&lt;br /&gt;
====Java====&lt;br /&gt;
Type requirements can be defined on arguments as a set of formal abstractions – this feature is called constrained genericity. The generic types of the classes have to honor these requirements in order to participate in the valid instantiation. Java Generics use interfaces to represent a concept and employ the mechanism of subtyping to model a concept – any type T modeling a concept C will have to implement the corresponding interface.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public interface VertexListGraph&amp;lt;Vertex,  &lt;br /&gt;
                      VertexIterator extends Iterator&amp;lt;Vertex&amp;gt;&amp;gt; { &lt;br /&gt;
    VertexIterator vertices(); &lt;br /&gt;
    int num_vertices(); &lt;br /&gt;
} &lt;br /&gt;
public interface IncidenceGraph&amp;lt;Vertex, Edge, &lt;br /&gt;
                      OutEdgeIterator extends Iterator&amp;lt;Edge&amp;gt;&amp;gt; { &lt;br /&gt;
    OutEdgeIterator out_edges(Vertex v); &lt;br /&gt;
    int out_degree(Vertex v); &lt;br /&gt;
} &lt;br /&gt;
public interface VertexListAndIncidenceGraph&amp;lt;…&amp;gt; &lt;br /&gt;
        extends VertexListGraph&amp;lt;…&amp;gt;, IncidenceGraph&amp;lt;…&amp;gt; {} &lt;br /&gt;
public class adjacency_list &lt;br /&gt;
        implements VertexListAndIncidenceGraph&amp;lt;Integer, &lt;br /&gt;
                      Simple_edge&amp;lt;Integer&amp;gt;, Iterator&amp;lt;Integer&amp;gt;, &lt;br /&gt;
                      Integer, Iterator&amp;lt;simple_edge&amp;lt;Integer&amp;gt;&amp;gt;, &lt;br /&gt;
                      Integer, Iterator&amp;lt;simple_edge&amp;lt;Integer&amp;gt;&amp;gt;&amp;gt; { &lt;br /&gt;
…… &lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The implements clause makes the adjacency_list a model of Vertex List Graph and Incidence Graph concepts.&lt;br /&gt;
&lt;br /&gt;
====C++====&lt;br /&gt;
C++ does not offer any means to constrain the template parameters. However, techniques for checking constraints in C++ have been implemented as a library using the notion of compile time assertions.&lt;br /&gt;
&lt;br /&gt;
====Comparison====&lt;br /&gt;
Java Generics come without two of the very important features of generic programming – type aliasing and associated types. C++ templates offer both of them, type aliasing through typedefs and the associated types through the traits mechanism. Though typedef s are not part of &lt;br /&gt;
the C++ templates per se, but without them writing generic code often becomes extremely &lt;br /&gt;
verbose and error prone.&lt;br /&gt;
&lt;br /&gt;
Java has no type aliasing as seen below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dijkstra_visitor&amp;lt;VertexListAndIncidenceGraph&amp;lt;Vertex, &lt;br /&gt;
   Edge, &lt;br /&gt;
   VertexIterator, &lt;br /&gt;
   OutEdgeIterator&amp;gt;,  &lt;br /&gt;
                 mutable_queue&amp;lt;Vertex, indirect_cmp&amp;lt;Vertex,  &lt;br /&gt;
                          Distance, DistanceMap, DistanceCompare&amp;gt;&amp;gt;,  &lt;br /&gt;
                 WeightMap,  &lt;br /&gt;
                 PredecessorMap,  &lt;br /&gt;
                 DistanceMap,  &lt;br /&gt;
                 DistanceCombine,  &lt;br /&gt;
                 DistanceCompare,  &lt;br /&gt;
                 Vertex,  &lt;br /&gt;
                 Edge,  &lt;br /&gt;
                 Distance&amp;gt; vis  &lt;br /&gt;
      = new dijkstra_visitor&amp;lt;VertexListAndIncidenceGraph&amp;lt;Vertex, &lt;br /&gt;
                                                     Edge, &lt;br /&gt;
                                                     VertexIterator, &lt;br /&gt;
                                                     OutEdgeIterator&amp;gt;,  &lt;br /&gt;
                             mutable_queue&amp;lt;Vertex,  &lt;br /&gt;
                                 indirect_cmp&amp;lt;Vertex, Distance,  &lt;br /&gt;
                                      DistanceMap, DistanceCompare&amp;gt;&amp;gt;,  &lt;br /&gt;
                             WeightMap,  &lt;br /&gt;
                             PredecessorMap,  &lt;br /&gt;
                             DistanceMap,  &lt;br /&gt;
                             DistanceCombine,  &lt;br /&gt;
                             DistanceCompare,  &lt;br /&gt;
                             Vertex,  &lt;br /&gt;
                             Edge,  &lt;br /&gt;
                             Distance&amp;gt; (Q, weight, predecessor, &lt;br /&gt;
distance, combine, compare, zero); &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Java has no support for associated types:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// breadth_first_search prototype in C++ &lt;br /&gt;
template &amp;lt;class VertexListGraph, class Buffer, class BFSVisitor, &lt;br /&gt;
          class ColorMap&amp;gt; &lt;br /&gt;
  void breadth_first_search &lt;br /&gt;
    (const VertexListGraph&amp;amp; g, &lt;br /&gt;
     typename graph_traits&amp;lt;VertexListGraph&amp;gt;::vertex_descriptor s, &lt;br /&gt;
     Buffer&amp;amp; Q, BFSVisitor vis, ColorMap color) &lt;br /&gt;
// breadth_first_search prototype in Java &lt;br /&gt;
public static &amp;lt;Vertex, &lt;br /&gt;
               Edge extends GraphEdge&amp;lt;Vertex&amp;gt;, &lt;br /&gt;
               VertexIterator extends java.util.Iterator&amp;lt;Vertex&amp;gt;, &lt;br /&gt;
               OutEdgeIterator extends java.util.Iterator&amp;lt;Edge&amp;gt;, &lt;br /&gt;
               Vis extends Visitor, &lt;br /&gt;
               ColorMap extends &lt;br /&gt;
                    ReadWritePropertyMap&amp;lt;Vertex,java.lang.Integer&amp;gt;, &lt;br /&gt;
               QueueType extends Buffer&amp;lt;Vertex&amp;gt;&amp;gt; &lt;br /&gt;
  void breadth_first_search(VertexListAndIncidenceGraph&amp;lt;Vertex, &lt;br /&gt;
                               Edge,VertexIterator,OutEdgeIterator&amp;gt; g, &lt;br /&gt;
                               Vertex s, Visitor vis, ColorMap color) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Security Model===&lt;br /&gt;
====Java====&lt;br /&gt;
Java Generics translation model replaces all generic types by the bound type, Object, thereby removing all type information from the runtime system. This is referred to as the homogeneous model of implementing Generics, since all generic types are mapped to a single supertype.&lt;br /&gt;
&lt;br /&gt;
====C++====&lt;br /&gt;
C++ implements the heterogeneous model, where the compiler generates a separate copy of the type for each specific instantiation of the type parameter. Hence a generic container Stack&amp;lt;T&amp;gt; will generate separate concrete classes Stack&amp;lt;int&amp;gt; for integers, Stack&amp;lt;double&amp;gt; for double precision numbers, Stack&amp;lt;string&amp;gt; for string data type. While in Java, Stack&amp;lt;T&amp;gt; will be instantiated as Stack collection class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class BroadcastList&amp;lt;C extends Channel&amp;gt; { &lt;br /&gt;
    C channels[]; &lt;br /&gt;
    void add(C c) { … } &lt;br /&gt;
    void broadcast(String s) { &lt;br /&gt;
        int I; &lt;br /&gt;
        for(I = 0; I &amp;lt; channels.length; i++) &lt;br /&gt;
            channels[i].send(s); &lt;br /&gt;
    } &lt;br /&gt;
    …… &lt;br /&gt;
} &lt;br /&gt;
Class EncryptedChannel extends Channel; &lt;br /&gt;
Class UnencryptedChannel extends Channel; &lt;br /&gt;
BroadcastList&amp;lt;EncryptedChannel&amp;gt; list = ……; &lt;br /&gt;
list.add(new EncryptedChannel()); &lt;br /&gt;
(*) &lt;br /&gt;
list.broadcast(“Hello”); &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Comparison====&lt;br /&gt;
&lt;br /&gt;
Because of the homogeneous implementation, during instantiation of the generic class BroadCastList, C will not contain the exact type, since the translation of Java Generics will erase C. Hence it becomes vulnerable to a malicious program who can add an unencrypted channel to the list (possibly at position marked by (*)) through hand-written byte codes, which will bypass all compile time checking and the compiler generated run-time checks guaranteeing JDK 1.5 (beta) includes a workaround to prevent this security hole; it has a means of constructing a dynamically typesafe view of a specified collection (Collections.checkedCollection()). This ensures that any attempt to insert an element of incorrect type will result in a ClassCastException. But this approach introduces a counterintuitive programming model specifically to address an existing loophole in the security of the JVM. &lt;br /&gt;
&lt;br /&gt;
In C++, this security loophole does not exist since strict type-checking is employed at the points of instantiation of templates. However, this heterogeneous translation model employed by C++ will not fit with the current security model of the Java virtual machine. The JVM offers two levels of visibility – global level (public) and package level. Hence in some cases it becomes impossible to find out the proper package where the instantiated class will be placed honoring the visibility model of the JVM.&lt;br /&gt;
==Evolution of Generics==&lt;br /&gt;
Here we take Java programming language as an example to explain evolution of generics. Generics were introduced with Java 1.5. However, before that, the codes were bulky and messy but the results were same. Rather than simply using a List&amp;lt;Integer&amp;gt; or Comparable&amp;lt;String&amp;gt;, developers had to deal with a significant amount of inheritance, casting, and instanceof testing. For example, an ArrayList to store only Integers pre-generics might look like the below snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class IntegerList extends ArrayList{&lt;br /&gt;
     public boolean add(Object o){&lt;br /&gt;
            if(o instanceof Integer)&lt;br /&gt;
                return super.add(o);&lt;br /&gt;
             return false;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      public Integer get(int index){&lt;br /&gt;
           return (Integer)super.get(index);&lt;br /&gt;
      }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generics allows to write more modular and reusable code that is adaptable to various datatypes, yet logically restrictive as well. Currently, generics are implemented using erasure, which means that the generic type information is not available at runtime, which makes some kind of code hard to write. Generics were implemented this way to support backwards compatibility with older non-generic code. Reified generics would make the generic type information available at runtime, which would break legacy non-generic code. Generics are implemented using erasure, in which generic type parameters are simply removed at runtime. That doesn't render generics useless, because you get typechecking at compile-time based on the generic type parameters, and also because the compiler inserts casts in the code based on the type parameters.&lt;br /&gt;
===Erasure v/s Reification===&lt;br /&gt;
&lt;br /&gt;
Consider the below example, it won't work because of erasure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Test&amp;lt;Key, Val&amp;gt; {&lt;br /&gt;
  public void test(Key key) {&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
  public void test(Val value) {&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This would give a name clash error for having same erasure and one way to avoid the error is by renaming the method name but this will not the serve the purpose of overloading. Similarly, the below example would give errors because the JVM is not aware of the type T instead views it just as an Object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Test {&lt;br /&gt;
  public &amp;lt;T&amp;gt; void f() {&lt;br /&gt;
    T t = new T();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So reified generics have support in the compiler for preserving type information whereas type erased generics don't have and that &amp;quot;remember&amp;quot; the class they were created with during runtime. Below are some of the reasons why Java should have reified generics:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Type argument erasure cripples frameworks that works with generic types and this results in horrid workarounds&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reified generics allows Typesafe narrowing. Currently in Java, we first test the type of the object using the instanceof operator, and then attempt to downcast it using a C-style typecast&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Interoperability between statically-typed is difficult since few support reified generics.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But at the same time reified generics have issues and one of the main concern is incompatible with the current collections. So a test on &amp;lt;code&amp;gt;instanceof List&amp;lt;String&amp;gt;&amp;lt;/code&amp;gt; would now test that the object is an instance of &amp;lt;code&amp;gt;List&amp;lt;/code&amp;gt; but also that its elements are of type &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;. This requires a lot of work around since we need to distinguish between collections making used of reified types from their older types.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Despite their deceptively similar syntax, C++ and Java are two very different languages. Likewise, the original goals, programming models, and under-currents shaping their continued evolution are very different. Not surprisingly, their approaches to support generic programming are very different—&amp;quot;simple and comprehensible&amp;quot; in Java and meticulous and comprehensive in C++.&lt;br /&gt;
&lt;br /&gt;
Java Generics substantially improves type safety, encourages software reuse, and adds some basic support for generic programming. For Java, it is a serious step forward in the area of commercial software development. However, Java Generics in its proposed form does not qualify to be called generics (as in generic programming) as yet.&lt;br /&gt;
&lt;br /&gt;
Although some generic programming concepts are difficult in C++, compared to Java, C++ is well advanced and Java has a lot to catch up with. Consequently, claims of Java Generics being &amp;quot;better than C++ templates&amp;quot; are naive and ungrounded at best.&lt;br /&gt;
&lt;br /&gt;
Nevertheless, both languages have their applications and their devoted users. There is enough room for everyone.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generic_programming&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generics_in_Java&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.oracle.com/technetwork/articles/javase/generics-136597.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://download.oracle.com/javase/tutorial/extra/generics/methods.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.cplusplus.com/doc/tutorial/templates/&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Template_(programming)&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.cs.binghamton.edu/~mike/presentations/java-generics-cs580c-fall-2007.pdf&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://jnb.ociweb.com/jnb/jnbJul2003.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://tech.puredanger.com/java7/#reified&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://gafter.blogspot.com/2006/11/reified-generics-for-java.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://relation.to/21406.lace&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://beust.com/weblog/2011/07/29/erasure-vs-reification&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://aszt.inf.elte.hu/~gsd/s/cikkek/java/p40-ghosh.pdf&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://drdobbs.com/184401818&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=55759</id>
		<title>CSC/ECE 517 Fall 2011/ch6 6c sj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=55759"/>
		<updated>2011-11-18T00:42:10Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Generic Programming==&lt;br /&gt;
&amp;lt;p&amp;gt;Generic programming is a style of computer programming in which algorithms are written in terms of &amp;lt;i&amp;gt;to-be-specified-later&amp;lt;/i&amp;gt; types that are then instantiated when needed for specific types provided as parameters. This enables writing common set of functions which differ only in the types on which they operate. This reduces duplication. Software entities created using generic programming are known as ''generics'' in [http://en.wikipedia.org/wiki/Ada_(programming_language) Ada], [http://en.wikipedia.org/wiki/Eiffel_(programming_language) Eiffel], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/F_Sharp_(programming_language) F#], and [http://en.wikipedia.org/wiki/Visual_Basic_.NET Visual Basic .NET]; parametric polymorphism in [http://en.wikipedia.org/wiki/ML_(programming_language) ML], [http://en.wikipedia.org/wiki/Scala_(programming_language Scala] and [http://en.wikipedia.org/wiki/Haskell_(programming_language) Haskell], [http://en.wikipedia.org/wiki/template_(programming) template]s in [http://en.wikipedia.org/wiki/C++ C++].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;For example, given various data structures and several algorithms, the brute force way would be implement them for each data structure which would mean that various combinations of implementations will be necessary. Generic programming reduces this effort.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Generics in Java==&lt;br /&gt;
===What are Generics?===&lt;br /&gt;
Generics were added to Java programming language as a part of J2SE 5.0 release in 2004. They allow programmers to develop generic and compile safe applications which enables a type or method to operate on objects of various type. This feature is well utilized while implementing [http://en.wikipedia.org/wiki/Java_Collections Java Collections]. The reason why people went into generic programming can be well explained using the below example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  List list = new ArrayList();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = (Integer)list.get(0);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this example, we insert a &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; into an &amp;lt;code&amp;gt;ArrayList&amp;lt;/code&amp;gt; and retrieve element by typecasting with Integer wrapper class. This throws a runtime exception because of Illegal class cast. But if we use generics, runtime exceptions can be avoided and the compiler will be able to catch such issues which in turn help a programmer to build a bug free code. So if we convert the above code to use generic then it would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  List&amp;lt;String&amp;gt; list = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = list.get(0); //line 1 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here at line 1 the compiler throws an error because the compiler on seeing the declaration of ArrayList will be expecting the list to have just &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; and thereby the return type of &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt; to be &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Implementing Generics:===&lt;br /&gt;
Java provides a feature which helps one to implement your own generic types and this will help to build more sophisticated and runtime error free applications. Consider the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
   interface List&amp;lt;N&amp;gt; {&lt;br /&gt;
                         void add(N i);&lt;br /&gt;
                         Iterator&amp;lt;N&amp;gt; iterator();&lt;br /&gt;
                      }&lt;br /&gt;
   interface Iterator&amp;lt;N&amp;gt; {&lt;br /&gt;
                            N next();&lt;br /&gt;
                            boolean hasNext();&lt;br /&gt;
                         }&lt;br /&gt;
   class LinkedList&amp;lt;N&amp;gt; implements List&amp;lt;N&amp;gt; {&lt;br /&gt;
                          //Business Logic   &lt;br /&gt;
                 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
So here, &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; can be replaced with any primitive data types or wrapper classes in the business logic. But we need to make sure that placeholders to be replaced with valid subtypes of Object. Generics implementation is not restricted for classes or interfaces, we can have for static/non static methods and constructors.&lt;br /&gt;
&lt;br /&gt;
Example for generic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;T&amp;gt; void fromArrayToCollection(T[] a, Collection&amp;lt;T&amp;gt; c) {&lt;br /&gt;
    for (T o : a) {&lt;br /&gt;
        c.add(o); // Correct&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Pros and Cons===&lt;br /&gt;
&amp;lt;b&amp;gt;Pros:&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduces the number of casts in the program, which in turn reduces the number of potential bugs in the program.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Improves code clarity and maintenance.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Cons:&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Parameter type information is not available at run time.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;The automatically generated casts may fail when interoperating with ill-behaved legacy code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Templates in C++==&lt;br /&gt;
===What are templates?===&lt;br /&gt;
&amp;lt;p&amp;gt;Templates are functions that can operate with &amp;lt;i&amp;gt;generic types&amp;lt;/i&amp;gt; which means that the functionality can be adapted for more than one type of data without repeating the entire code for each type. &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
===Overview===&lt;br /&gt;
Templates can be either function templates or class templates.&lt;br /&gt;
====Function Templates====&lt;br /&gt;
These are just like regular functions except that they can have arguments of different types. A single function definition works with different kinds of data types. During compile time, the actual functions are generated once the compiler knows the data type being used. This kind of template does not save any memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;typename Type&amp;gt;&lt;br /&gt;
Type max(Type a, Type b) {&lt;br /&gt;
    return a &amp;gt; b ? a : b;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  // This will call max &amp;lt;int&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3, 7) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This will call max&amp;lt;double&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3.0, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This type is ambiguous, so explicitly instantiate max&amp;lt;double&amp;gt;&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max&amp;lt;double&amp;gt;(3, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Class Templates====&lt;br /&gt;
A class template provides a specification for generating classes based on parameters. A class template is instantiated by passing a given set of types to it as template arguments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;class T&amp;gt;&lt;br /&gt;
class mypair {&lt;br /&gt;
    T values [2];&lt;br /&gt;
  public:&lt;br /&gt;
    mypair (T first, T second)&lt;br /&gt;
    {&lt;br /&gt;
      values[0]=first; values[1]=second;&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Features of C++ Templates===&lt;br /&gt;
Some of the features of C++ templates are:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Implemented in the compiler.&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;No runtime overhead&amp;lt;/ul&amp;gt;&amp;lt;ul&amp;gt;Requires template source to be in headers&amp;lt;/ul&amp;gt;&amp;lt;ul&amp;gt;Latent typing means template instantiator does no type checking&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Gloriﬁed macro facility&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;“Macros done right”/“Macros that look like classes”&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Can use template arguments for both classes and straight function&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Template specialization&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;Speciﬁc implementation of a templated type or method&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pattern matching and text replacement&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;Declarative model (like [http://en.wikipedia.org/wiki/Prolog Prolog])&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pros and Cons===&lt;br /&gt;
Usage of templates have both advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Pros&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduction in code size.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They are type-safe, that is, type-checking is done at compile time.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Cons&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Since all compilers are not good at their support for templates, they may not be very portable.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Compilers generate additional code for each template type, this could lead to huge code if usage of templates is not checked.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Information hiding is not achieved as the code is all exposed in the header.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Templates (C++) versus Generics (Java)==&lt;br /&gt;
We can compare templates in C++ versus generics in Java based on the following models of comparison,&lt;br /&gt;
1. Translation model - discussion based on the way generic code is translated.&lt;br /&gt;
2. Type model - discussion based on implementations in type interference, type aliasing and associated types.&lt;br /&gt;
3. Security model - discussion based on security loopholes, if any.&lt;br /&gt;
Let's look at these with some examples.&lt;br /&gt;
&lt;br /&gt;
===Translation Model===&lt;br /&gt;
====Java====&lt;br /&gt;
One of the design reasons behind Java's generics was to provide backward compatibility of legacy Java code. To achieve this, Java implementation has adopted the same representation policy for the raw type and the parametric type. The parametric type Collection&amp;lt;T&amp;gt; can be passed safely where the corresponding raw type Collection is expected. Hence the translation model of Java Generics is based on the “type erasure” model, where the translation erases the generic type parameter, replaces them by the bounding type (Object) and inserts casts to the actual places of usage. In order for method overriding to work correctly, the translation process also adds “bridge methods”, as illustrated in the following example.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class C&amp;lt;A&amp;gt; { abstract A id(A x); } &lt;br /&gt;
class D extends C&amp;lt;String&amp;gt; { String id(String x) { return x; } } &lt;br /&gt;
This will be translated to: &lt;br /&gt;
class C { abstract Object id(Object x); } &lt;br /&gt;
class D extends C { &lt;br /&gt;
    String id(String x) { return x; } &lt;br /&gt;
    // bridge method introduced by the translator to make  &lt;br /&gt;
    // overriding work correctly &lt;br /&gt;
    Object id(Object x) { return id((String)x); }  &lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====C++====&lt;br /&gt;
The translation model of C++ is based on instantiation – no static type checking is done on the generic code. The compiler generates separate copies of the component (class or function) for each instantiation with a distinct type and the type checking is performed after instantiation at each call site. Type checking of the bound types can only succeed when the input types have satisfied the type requirements of the function template body. It is because of this, that misleading error messages are thrown in by the compiler when a generic component is instantiated with an improper type.&lt;br /&gt;
&lt;br /&gt;
====Comparison====&lt;br /&gt;
The C++ model is loss-less in the sense that no type information is lost during runtime, though the implementation of the translation suffers from the drawbacks of the possibility of introducing code bloats and misleading error messages. On the other hand, the Java model emphasizes on retrofitting the raw types with the generic counterparts, but the type-erasure model delegates the generic types to “second class” status compared to the conventional types.&lt;br /&gt;
&lt;br /&gt;
===Type Model===&lt;br /&gt;
====Java====&lt;br /&gt;
Type requirements can be defined on arguments as a set of formal abstractions – this feature is called constrained genericity. The generic types of the classes have to honor these requirements in order to participate in the valid instantiation. Java Generics use interfaces to represent a concept and employ the mechanism of subtyping to model a concept – any type T modeling a concept C will have to implement the corresponding interface.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public interface VertexListGraph&amp;lt;Vertex,  &lt;br /&gt;
                      VertexIterator extends Iterator&amp;lt;Vertex&amp;gt;&amp;gt; { &lt;br /&gt;
    VertexIterator vertices(); &lt;br /&gt;
    int num_vertices(); &lt;br /&gt;
} &lt;br /&gt;
public interface IncidenceGraph&amp;lt;Vertex, Edge, &lt;br /&gt;
                      OutEdgeIterator extends Iterator&amp;lt;Edge&amp;gt;&amp;gt; { &lt;br /&gt;
    OutEdgeIterator out_edges(Vertex v); &lt;br /&gt;
    int out_degree(Vertex v); &lt;br /&gt;
} &lt;br /&gt;
public interface VertexListAndIncidenceGraph&amp;lt;…&amp;gt; &lt;br /&gt;
        extends VertexListGraph&amp;lt;…&amp;gt;, IncidenceGraph&amp;lt;…&amp;gt; {} &lt;br /&gt;
public class adjacency_list &lt;br /&gt;
        implements VertexListAndIncidenceGraph&amp;lt;Integer, &lt;br /&gt;
                      Simple_edge&amp;lt;Integer&amp;gt;, Iterator&amp;lt;Integer&amp;gt;, &lt;br /&gt;
                      Integer, Iterator&amp;lt;simple_edge&amp;lt;Integer&amp;gt;&amp;gt;, &lt;br /&gt;
                      Integer, Iterator&amp;lt;simple_edge&amp;lt;Integer&amp;gt;&amp;gt;&amp;gt; { &lt;br /&gt;
…… &lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The implements clause makes the adjacency_list a model of Vertex List Graph and Incidence Graph concepts.&lt;br /&gt;
&lt;br /&gt;
====C++====&lt;br /&gt;
C++ does not offer any means to constrain the template parameters. However, techniques for checking constraints in C++ have been implemented as a library using the notion of compile time assertions.&lt;br /&gt;
&lt;br /&gt;
====Comparison====&lt;br /&gt;
Java Generics come without two of the very important features of generic programming – type aliasing and associated types. C++ templates offer both of them, type aliasing through typedefs and the associated types through the traits mechanism. Though typedef s are not part of &lt;br /&gt;
the C++ templates per se, but without them writing generic code often becomes extremely &lt;br /&gt;
verbose and error prone.&lt;br /&gt;
&lt;br /&gt;
Java has no type aliasing as seen below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dijkstra_visitor&amp;lt;VertexListAndIncidenceGraph&amp;lt;Vertex, &lt;br /&gt;
   Edge, &lt;br /&gt;
   VertexIterator, &lt;br /&gt;
   OutEdgeIterator&amp;gt;,  &lt;br /&gt;
                 mutable_queue&amp;lt;Vertex, indirect_cmp&amp;lt;Vertex,  &lt;br /&gt;
                          Distance, DistanceMap, DistanceCompare&amp;gt;&amp;gt;,  &lt;br /&gt;
                 WeightMap,  &lt;br /&gt;
                 PredecessorMap,  &lt;br /&gt;
                 DistanceMap,  &lt;br /&gt;
                 DistanceCombine,  &lt;br /&gt;
                 DistanceCompare,  &lt;br /&gt;
                 Vertex,  &lt;br /&gt;
                 Edge,  &lt;br /&gt;
                 Distance&amp;gt; vis  &lt;br /&gt;
      = new dijkstra_visitor&amp;lt;VertexListAndIncidenceGraph&amp;lt;Vertex, &lt;br /&gt;
                                                     Edge, &lt;br /&gt;
                                                     VertexIterator, &lt;br /&gt;
                                                     OutEdgeIterator&amp;gt;,  &lt;br /&gt;
                             mutable_queue&amp;lt;Vertex,  &lt;br /&gt;
                                 indirect_cmp&amp;lt;Vertex, Distance,  &lt;br /&gt;
                                      DistanceMap, DistanceCompare&amp;gt;&amp;gt;,  &lt;br /&gt;
                             WeightMap,  &lt;br /&gt;
                             PredecessorMap,  &lt;br /&gt;
                             DistanceMap,  &lt;br /&gt;
                             DistanceCombine,  &lt;br /&gt;
                             DistanceCompare,  &lt;br /&gt;
                             Vertex,  &lt;br /&gt;
                             Edge,  &lt;br /&gt;
                             Distance&amp;gt; (Q, weight, predecessor, &lt;br /&gt;
distance, combine, compare, zero); &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Java has no support for associated types:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// breadth_first_search prototype in C++ &lt;br /&gt;
template &amp;lt;class VertexListGraph, class Buffer, class BFSVisitor, &lt;br /&gt;
          class ColorMap&amp;gt; &lt;br /&gt;
  void breadth_first_search &lt;br /&gt;
    (const VertexListGraph&amp;amp; g, &lt;br /&gt;
     typename graph_traits&amp;lt;VertexListGraph&amp;gt;::vertex_descriptor s, &lt;br /&gt;
     Buffer&amp;amp; Q, BFSVisitor vis, ColorMap color) &lt;br /&gt;
// breadth_first_search prototype in Java &lt;br /&gt;
public static &amp;lt;Vertex, &lt;br /&gt;
               Edge extends GraphEdge&amp;lt;Vertex&amp;gt;, &lt;br /&gt;
               VertexIterator extends java.util.Iterator&amp;lt;Vertex&amp;gt;, &lt;br /&gt;
               OutEdgeIterator extends java.util.Iterator&amp;lt;Edge&amp;gt;, &lt;br /&gt;
               Vis extends Visitor, &lt;br /&gt;
               ColorMap extends &lt;br /&gt;
                    ReadWritePropertyMap&amp;lt;Vertex,java.lang.Integer&amp;gt;, &lt;br /&gt;
               QueueType extends Buffer&amp;lt;Vertex&amp;gt;&amp;gt; &lt;br /&gt;
  void breadth_first_search(VertexListAndIncidenceGraph&amp;lt;Vertex, &lt;br /&gt;
                               Edge,VertexIterator,OutEdgeIterator&amp;gt; g, &lt;br /&gt;
                               Vertex s, Visitor vis, ColorMap color) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Security Model===&lt;br /&gt;
====Java====&lt;br /&gt;
Java Generics translation model replaces all generic types by the bound type, Object, thereby removing all type information from the runtime system. This is referred to as the homogeneous model of implementing Generics, since all generic types are mapped to a single supertype.&lt;br /&gt;
&lt;br /&gt;
====C++====&lt;br /&gt;
C++ implements the heterogeneous model, where the compiler generates a separate copy of the type for each specific instantiation of the type parameter. Hence a generic container Stack&amp;lt;T&amp;gt; will generate separate concrete classes Stack&amp;lt;int&amp;gt; for integers, Stack&amp;lt;double&amp;gt; for double precision numbers, Stack&amp;lt;string&amp;gt; for string data type. While in Java, Stack&amp;lt;T&amp;gt; will be instantiated as Stack collection class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class BroadcastList&amp;lt;C extends Channel&amp;gt; { &lt;br /&gt;
    C channels[]; &lt;br /&gt;
    void add(C c) { … } &lt;br /&gt;
    void broadcast(String s) { &lt;br /&gt;
        int I; &lt;br /&gt;
        for(I = 0; I &amp;lt; channels.length; i++) &lt;br /&gt;
            channels[i].send(s); &lt;br /&gt;
    } &lt;br /&gt;
    …… &lt;br /&gt;
} &lt;br /&gt;
Class EncryptedChannel extends Channel; &lt;br /&gt;
Class UnencryptedChannel extends Channel; &lt;br /&gt;
BroadcastList&amp;lt;EncryptedChannel&amp;gt; list = ……; &lt;br /&gt;
list.add(new EncryptedChannel()); &lt;br /&gt;
(*) &lt;br /&gt;
list.broadcast(“Hello”); &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Comparison====&lt;br /&gt;
&lt;br /&gt;
Because of the homogeneous implementation, during instantiation of the generic class BroadCastList, C will not contain the exact type, since the translation of Java Generics will erase C. Hence it becomes vulnerable to a malicious program who can add an unencrypted channel to the list (possibly at position marked by (*)) through hand-written byte codes, which will bypass all compile time checking and the compiler generated run-time checks guaranteeing JDK 1.5 (beta) includes a workaround to prevent this security hole; it has a means of constructing a dynamically typesafe view of a specified collection (Collections.checkedCollection()). This ensures that any attempt to insert an element of incorrect type will result in a ClassCastException. But this approach introduces a counterintuitive programming model specifically to address an existing loophole in the security of the JVM. &lt;br /&gt;
&lt;br /&gt;
In C++, this security loophole does not exist since strict type-checking is employed at the points of instantiation of templates. However, this heterogeneous translation model employed by C++ will not fit with the current security model of the Java virtual machine. The JVM offers two levels of visibility – global level (public) and package level. Hence in some cases it becomes impossible to find out the proper package where the instantiated class will be placed honoring the visibility model of the JVM.&lt;br /&gt;
==Evolution of Generics==&lt;br /&gt;
Here we take Java programming language as an example to explain evolution of generics. Generics were introduced with Java 1.5. However, before that, the codes were bulky and messy but the results were same. Rather than simply using a List&amp;lt;Integer&amp;gt; or Comparable&amp;lt;String&amp;gt;, developers had to deal with a significant amount of inheritance, casting, and instanceof testing. For example, an ArrayList to store only Integers pre-generics might look like the below snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class IntegerList extends ArrayList{&lt;br /&gt;
     public boolean add(Object o){&lt;br /&gt;
            if(o instanceof Integer)&lt;br /&gt;
                return super.add(o);&lt;br /&gt;
             return false;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      public Integer get(int index){&lt;br /&gt;
           return (Integer)super.get(index);&lt;br /&gt;
      }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generics allows to write more modular and reusable code that is adaptable to various datatypes, yet logically restrictive as well. Currently, generics are implemented using erasure, which means that the generic type information is not available at runtime, which makes some kind of code hard to write. Generics were implemented this way to support backwards compatibility with older non-generic code. Reified generics would make the generic type information available at runtime, which would break legacy non-generic code. Generics are implemented using erasure, in which generic type parameters are simply removed at runtime. That doesn't render generics useless, because you get typechecking at compile-time based on the generic type parameters, and also because the compiler inserts casts in the code based on the type parameters.&lt;br /&gt;
===Erasure v/s Reification===&lt;br /&gt;
&lt;br /&gt;
Consider the below example, it won't work because of erasure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Test&amp;lt;Key, Val&amp;gt; {&lt;br /&gt;
  public void test(Key key) {&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
  public void test(Val value) {&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This would give a name clash error for having same erasure and one way to avoid the error is by renaming the method name but this will not the serve the purpose of overloading. Similarly, the below example would give errors because the JVM is not aware of the type T instead views it just as an Object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Test {&lt;br /&gt;
  public &amp;lt;T&amp;gt; void f() {&lt;br /&gt;
    T t = new T();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So reified generics have support in the compiler for preserving type information whereas type erased generics don't have and that &amp;quot;remember&amp;quot; the class they were created with during runtime. Below are some of the reasons why Java should have reified generics:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Type argument erasure cripples frameworks that works with generic types and this results in horrid workarounds&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reified generics allows Typesafe narrowing. Currently in Java, we first test the type of the object using the instanceof operator, and then attempt to downcast it using a C-style typecast&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Interoperability between statically-typed is difficult since few support reified generics.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But at the same time reified generics have issues and one of the main concern is incompatible with the current collections. So a test on &amp;lt;code&amp;gt;instanceof List&amp;lt;String&amp;gt;&amp;lt;/code&amp;gt; would now test that the object is an instance of &amp;lt;code&amp;gt;List&amp;lt;/code&amp;gt; but also that its elements are of type &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;. This requires a lot of work around since we need to distinguish between collections making used of reified types from their older types.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generic_programming&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generics_in_Java&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.oracle.com/technetwork/articles/javase/generics-136597.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://download.oracle.com/javase/tutorial/extra/generics/methods.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.cplusplus.com/doc/tutorial/templates/&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Template_(programming)&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.cs.binghamton.edu/~mike/presentations/java-generics-cs580c-fall-2007.pdf&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://jnb.ociweb.com/jnb/jnbJul2003.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://tech.puredanger.com/java7/#reified&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://gafter.blogspot.com/2006/11/reified-generics-for-java.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://relation.to/21406.lace&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://beust.com/weblog/2011/07/29/erasure-vs-reification&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://aszt.inf.elte.hu/~gsd/s/cikkek/java/p40-ghosh.pdf&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=55758</id>
		<title>CSC/ECE 517 Fall 2011/ch6 6c sj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=55758"/>
		<updated>2011-11-18T00:41:24Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Generic Programming==&lt;br /&gt;
&amp;lt;p&amp;gt;Generic programming is a style of computer programming in which algorithms are written in terms of &amp;lt;i&amp;gt;to-be-specified-later&amp;lt;/i&amp;gt; types that are then instantiated when needed for specific types provided as parameters. This enables writing common set of functions which differ only in the types on which they operate. This reduces duplication. Software entities created using generic programming are known as ''generics'' in [http://en.wikipedia.org/wiki/Ada_(programming_language) Ada], [http://en.wikipedia.org/wiki/Eiffel_(programming_language) Eiffel], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/F_Sharp_(programming_language) F#], and [http://en.wikipedia.org/wiki/Visual_Basic_.NET Visual Basic .NET]; parametric polymorphism in [http://en.wikipedia.org/wiki/ML_(programming_language) ML], [http://en.wikipedia.org/wiki/Scala_(programming_language Scala] and [http://en.wikipedia.org/wiki/Haskell_(programming_language) Haskell], [http://en.wikipedia.org/wiki/template_(programming) template]s in [http://en.wikipedia.org/wiki/C++ C++].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;For example, given various data structures and several algorithms, the brute force way would be implement them for each data structure which would mean that various combinations of implementations will be necessary. Generic programming reduces this effort.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Generics in Java==&lt;br /&gt;
===What are Generics?===&lt;br /&gt;
Generics were added to Java programming language as a part of J2SE 5.0 release in 2004. They allow programmers to develop generic and compile safe applications which enables a type or method to operate on objects of various type. This feature is well utilized while implementing [http://en.wikipedia.org/wiki/Java_Collections Java Collections]. The reason why people went into generic programming can be well explained using the below example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  List list = new ArrayList();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = (Integer)list.get(0);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this example, we insert a &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; into an &amp;lt;code&amp;gt;ArrayList&amp;lt;/code&amp;gt; and retrieve element by typecasting with Integer wrapper class. This throws a runtime exception because of Illegal class cast. But if we use generics, runtime exceptions can be avoided and the compiler will be able to catch such issues which in turn help a programmer to build a bug free code. So if we convert the above code to use generic then it would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  List&amp;lt;String&amp;gt; list = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = list.get(0); //line 1 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here at line 1 the compiler throws an error because the compiler on seeing the declaration of ArrayList will be expecting the list to have just &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; and thereby the return type of &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt; to be &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Implementing Generics:===&lt;br /&gt;
Java provides a feature which helps one to implement your own generic types and this will help to build more sophisticated and runtime error free applications. Consider the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
   interface List&amp;lt;N&amp;gt; {&lt;br /&gt;
                         void add(N i);&lt;br /&gt;
                         Iterator&amp;lt;N&amp;gt; iterator();&lt;br /&gt;
                      }&lt;br /&gt;
   interface Iterator&amp;lt;N&amp;gt; {&lt;br /&gt;
                            N next();&lt;br /&gt;
                            boolean hasNext();&lt;br /&gt;
                         }&lt;br /&gt;
   class LinkedList&amp;lt;N&amp;gt; implements List&amp;lt;N&amp;gt; {&lt;br /&gt;
                          //Business Logic   &lt;br /&gt;
                 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
So here, &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; can be replaced with any primitive data types or wrapper classes in the business logic. But we need to make sure that placeholders to be replaced with valid subtypes of Object. Generics implementation is not restricted for classes or interfaces, we can have for static/non static methods and constructors.&lt;br /&gt;
&lt;br /&gt;
Example for generic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;T&amp;gt; void fromArrayToCollection(T[] a, Collection&amp;lt;T&amp;gt; c) {&lt;br /&gt;
    for (T o : a) {&lt;br /&gt;
        c.add(o); // Correct&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Pros and Cons===&lt;br /&gt;
&amp;lt;b&amp;gt;Pros:&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduces the number of casts in the program, which in turn reduces the number of potential bugs in the program.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Improves code clarity and maintenance.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Cons:&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Parameter type information is not available at run time.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;The automatically generated casts may fail when interoperating with ill-behaved legacy code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Templates in C++==&lt;br /&gt;
===What are templates?===&lt;br /&gt;
&amp;lt;p&amp;gt;Templates are functions that can operate with &amp;lt;i&amp;gt;generic types&amp;lt;/i&amp;gt; which means that the functionality can be adapted for more than one type of data without repeating the entire code for each type. &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
===Overview===&lt;br /&gt;
Templates can be either function templates or class templates.&lt;br /&gt;
====Function Templates====&lt;br /&gt;
These are just like regular functions except that they can have arguments of different types. A single function definition works with different kinds of data types. During compile time, the actual functions are generated once the compiler knows the data type being used. This kind of template does not save any memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;typename Type&amp;gt;&lt;br /&gt;
Type max(Type a, Type b) {&lt;br /&gt;
    return a &amp;gt; b ? a : b;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  // This will call max &amp;lt;int&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3, 7) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This will call max&amp;lt;double&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3.0, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This type is ambiguous, so explicitly instantiate max&amp;lt;double&amp;gt;&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max&amp;lt;double&amp;gt;(3, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Class Templates====&lt;br /&gt;
A class template provides a specification for generating classes based on parameters. A class template is instantiated by passing a given set of types to it as template arguments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;class T&amp;gt;&lt;br /&gt;
class mypair {&lt;br /&gt;
    T values [2];&lt;br /&gt;
  public:&lt;br /&gt;
    mypair (T first, T second)&lt;br /&gt;
    {&lt;br /&gt;
      values[0]=first; values[1]=second;&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Features of C++ Templates===&lt;br /&gt;
Some of the features of C++ templates are:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Implemented in the compiler.&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;No runtime overhead&amp;lt;/ul&amp;gt;&amp;lt;ul&amp;gt;Requires template source to be in headers&amp;lt;/ul&amp;gt;&amp;lt;ul&amp;gt;Latent typing means template instantiator does no type checking&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Gloriﬁed macro facility&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;“Macros done right”/“Macros that look like classes”&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Can use template arguments for both classes and straight function&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Template specialization&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;Speciﬁc implementation of a templated type or method&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pattern matching and text replacement&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;Declarative model (like [http://en.wikipedia.org/wiki/Prolog Prolog])&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pros and Cons===&lt;br /&gt;
Usage of templates have both advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Pros&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduction in code size.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They are type-safe, that is, type-checking is done at compile time.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Cons&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Since all compilers are not good at their support for templates, they may not be very portable.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Compilers generate additional code for each template type, this could lead to huge code if usage of templates is not checked.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Information hiding is not achieved as the code is all exposed in the header.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Templates (C++) versus Generics (Java)==&lt;br /&gt;
We can compare templates in C++ versus generics in Java based on the following models of comparison,&lt;br /&gt;
1. Translation model - discussion based on the way generic code is translated.&lt;br /&gt;
2. Type model - discussion based on implementations in type interference, type aliasing and associated types.&lt;br /&gt;
3. Security model - discussion based on security loopholes, if any.&lt;br /&gt;
Let's look at these with some examples.&lt;br /&gt;
&lt;br /&gt;
===Translation Model===&lt;br /&gt;
====Java====&lt;br /&gt;
One of the design reasons behind Java's generics was to provide backward compatibility of legacy Java code. To achieve this, Java implementation has adopted the same representation policy for the raw type and the parametric type. The parametric type Collection&amp;lt;T&amp;gt; can be passed safely where the corresponding raw type Collection is expected. Hence the translation model of Java Generics is based on the “type erasure” model, where the translation erases the generic type parameter, replaces them by the bounding type (Object) and inserts casts to the actual places of usage. In order for method overriding to work correctly, the translation process also adds “bridge methods”, as illustrated in the following example.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class C&amp;lt;A&amp;gt; { abstract A id(A x); } &lt;br /&gt;
class D extends C&amp;lt;String&amp;gt; { String id(String x) { return x; } } &lt;br /&gt;
This will be translated to: &lt;br /&gt;
class C { abstract Object id(Object x); } &lt;br /&gt;
class D extends C { &lt;br /&gt;
    String id(String x) { return x; } &lt;br /&gt;
    // bridge method introduced by the translator to make  &lt;br /&gt;
    // overriding work correctly &lt;br /&gt;
    Object id(Object x) { return id((String)x); }  &lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====C++====&lt;br /&gt;
The translation model of C++ is based on instantiation – no static type checking is done on the generic code. The compiler generates separate copies of the component (class or function) for each instantiation with a distinct type and the type checking is performed after instantiation at each call site. Type checking of the bound types can only succeed when the input types have satisfied the type requirements of the function template body. It is because of this, that misleading error messages are thrown in by the compiler when a generic component is instantiated with an improper type.&lt;br /&gt;
&lt;br /&gt;
====Comparison====&lt;br /&gt;
The C++ model is loss-less in the sense that no type information is lost during runtime, though the implementation of the translation suffers from the drawbacks of the possibility of introducing code bloats and misleading error messages. On the other hand, the Java model emphasizes on retrofitting the raw types with the generic counterparts, but the type-erasure model delegates the generic types to “second class” status compared to the conventional types.&lt;br /&gt;
&lt;br /&gt;
===Type Model===&lt;br /&gt;
====Java====&lt;br /&gt;
Type requirements can be defined on arguments as a set of formal abstractions – this feature is called constrained genericity. The generic types of the classes have to honor these requirements in order to participate in the valid instantiation. Java Generics use interfaces to represent a concept and employ the mechanism of subtyping to model a concept – any type T modeling a concept C will have to implement the corresponding interface.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public interface VertexListGraph&amp;lt;Vertex,  &lt;br /&gt;
                      VertexIterator extends Iterator&amp;lt;Vertex&amp;gt;&amp;gt; { &lt;br /&gt;
    VertexIterator vertices(); &lt;br /&gt;
    int num_vertices(); &lt;br /&gt;
} &lt;br /&gt;
public interface IncidenceGraph&amp;lt;Vertex, Edge, &lt;br /&gt;
                      OutEdgeIterator extends Iterator&amp;lt;Edge&amp;gt;&amp;gt; { &lt;br /&gt;
    OutEdgeIterator out_edges(Vertex v); &lt;br /&gt;
    int out_degree(Vertex v); &lt;br /&gt;
} &lt;br /&gt;
public interface VertexListAndIncidenceGraph&amp;lt;…&amp;gt; &lt;br /&gt;
        extends VertexListGraph&amp;lt;…&amp;gt;, IncidenceGraph&amp;lt;…&amp;gt; {} &lt;br /&gt;
public class adjacency_list &lt;br /&gt;
        implements VertexListAndIncidenceGraph&amp;lt;Integer, &lt;br /&gt;
                      Simple_edge&amp;lt;Integer&amp;gt;, Iterator&amp;lt;Integer&amp;gt;, &lt;br /&gt;
                      Integer, Iterator&amp;lt;simple_edge&amp;lt;Integer&amp;gt;&amp;gt;, &lt;br /&gt;
                      Integer, Iterator&amp;lt;simple_edge&amp;lt;Integer&amp;gt;&amp;gt;&amp;gt; { &lt;br /&gt;
…… &lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The implements clause makes the adjacency_list a model of Vertex List Graph and Incidence Graph concepts.&lt;br /&gt;
&lt;br /&gt;
====C++====&lt;br /&gt;
C++ does not offer any means to constrain the template parameters. However, techniques for checking constraints in C++ have been implemented as a library using the notion of compile time assertions.&lt;br /&gt;
&lt;br /&gt;
====Comparison====Java Generics come without two of the very important features of generic programming – type aliasing and associated types. C++ templates offer both of them, type aliasing through typedefs and the associated types through the traits mechanism. Though typedef s are not part of &lt;br /&gt;
the C++ templates per se, but without them writing generic code often becomes extremely &lt;br /&gt;
verbose and error prone.&lt;br /&gt;
&lt;br /&gt;
Java has no type aliasing as seen below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dijkstra_visitor&amp;lt;VertexListAndIncidenceGraph&amp;lt;Vertex, &lt;br /&gt;
   Edge, &lt;br /&gt;
   VertexIterator, &lt;br /&gt;
   OutEdgeIterator&amp;gt;,  &lt;br /&gt;
                 mutable_queue&amp;lt;Vertex, indirect_cmp&amp;lt;Vertex,  &lt;br /&gt;
                          Distance, DistanceMap, DistanceCompare&amp;gt;&amp;gt;,  &lt;br /&gt;
                 WeightMap,  &lt;br /&gt;
                 PredecessorMap,  &lt;br /&gt;
                 DistanceMap,  &lt;br /&gt;
                 DistanceCombine,  &lt;br /&gt;
                 DistanceCompare,  &lt;br /&gt;
                 Vertex,  &lt;br /&gt;
                 Edge,  &lt;br /&gt;
                 Distance&amp;gt; vis  &lt;br /&gt;
      = new dijkstra_visitor&amp;lt;VertexListAndIncidenceGraph&amp;lt;Vertex, &lt;br /&gt;
                                                     Edge, &lt;br /&gt;
                                                     VertexIterator, &lt;br /&gt;
                                                     OutEdgeIterator&amp;gt;,  &lt;br /&gt;
                             mutable_queue&amp;lt;Vertex,  &lt;br /&gt;
                                 indirect_cmp&amp;lt;Vertex, Distance,  &lt;br /&gt;
                                      DistanceMap, DistanceCompare&amp;gt;&amp;gt;,  &lt;br /&gt;
                             WeightMap,  &lt;br /&gt;
                             PredecessorMap,  &lt;br /&gt;
                             DistanceMap,  &lt;br /&gt;
                             DistanceCombine,  &lt;br /&gt;
                             DistanceCompare,  &lt;br /&gt;
                             Vertex,  &lt;br /&gt;
                             Edge,  &lt;br /&gt;
                             Distance&amp;gt; (Q, weight, predecessor, &lt;br /&gt;
distance, combine, compare, zero); &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Java has no support for associated types:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// breadth_first_search prototype in C++ &lt;br /&gt;
template &amp;lt;class VertexListGraph, class Buffer, class BFSVisitor, &lt;br /&gt;
          class ColorMap&amp;gt; &lt;br /&gt;
  void breadth_first_search &lt;br /&gt;
    (const VertexListGraph&amp;amp; g, &lt;br /&gt;
     typename graph_traits&amp;lt;VertexListGraph&amp;gt;::vertex_descriptor s, &lt;br /&gt;
     Buffer&amp;amp; Q, BFSVisitor vis, ColorMap color) &lt;br /&gt;
// breadth_first_search prototype in Java &lt;br /&gt;
public static &amp;lt;Vertex, &lt;br /&gt;
               Edge extends GraphEdge&amp;lt;Vertex&amp;gt;, &lt;br /&gt;
               VertexIterator extends java.util.Iterator&amp;lt;Vertex&amp;gt;, &lt;br /&gt;
               OutEdgeIterator extends java.util.Iterator&amp;lt;Edge&amp;gt;, &lt;br /&gt;
               Vis extends Visitor, &lt;br /&gt;
               ColorMap extends &lt;br /&gt;
                    ReadWritePropertyMap&amp;lt;Vertex,java.lang.Integer&amp;gt;, &lt;br /&gt;
               QueueType extends Buffer&amp;lt;Vertex&amp;gt;&amp;gt; &lt;br /&gt;
  void breadth_first_search(VertexListAndIncidenceGraph&amp;lt;Vertex, &lt;br /&gt;
                               Edge,VertexIterator,OutEdgeIterator&amp;gt; g, &lt;br /&gt;
                               Vertex s, Visitor vis, ColorMap color) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Security Model===&lt;br /&gt;
====Java====&lt;br /&gt;
Java Generics translation model replaces all generic types by the bound type, Object, thereby removing all type information from the runtime system. This is referred to as the homogeneous model of implementing Generics, since all generic types are mapped to a single supertype.&lt;br /&gt;
&lt;br /&gt;
====C++====&lt;br /&gt;
C++ implements the heterogeneous model, where the compiler generates a separate copy of the type for each specific instantiation of the type parameter. Hence a generic container Stack&amp;lt;T&amp;gt; will generate separate concrete classes Stack&amp;lt;int&amp;gt; for integers, Stack&amp;lt;double&amp;gt; for double precision numbers, Stack&amp;lt;string&amp;gt; for string data type. While in Java, Stack&amp;lt;T&amp;gt; will be instantiated as Stack collection class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class BroadcastList&amp;lt;C extends Channel&amp;gt; { &lt;br /&gt;
    C channels[]; &lt;br /&gt;
    void add(C c) { … } &lt;br /&gt;
    void broadcast(String s) { &lt;br /&gt;
        int I; &lt;br /&gt;
        for(I = 0; I &amp;lt; channels.length; i++) &lt;br /&gt;
            channels[i].send(s); &lt;br /&gt;
    } &lt;br /&gt;
    …… &lt;br /&gt;
} &lt;br /&gt;
Class EncryptedChannel extends Channel; &lt;br /&gt;
Class UnencryptedChannel extends Channel; &lt;br /&gt;
BroadcastList&amp;lt;EncryptedChannel&amp;gt; list = ……; &lt;br /&gt;
list.add(new EncryptedChannel()); &lt;br /&gt;
(*) &lt;br /&gt;
list.broadcast(“Hello”); &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Comparison====&lt;br /&gt;
&lt;br /&gt;
Because of the homogeneous implementation, during instantiation of the generic class BroadCastList, C will not contain the exact type, since the translation of Java Generics will erase C. Hence it becomes vulnerable to a malicious program who can add an unencrypted channel to the list (possibly at position marked by (*)) through hand-written byte codes, which will bypass all compile time checking and the compiler generated run-time checks guaranteeing JDK 1.5 (beta) includes a workaround to prevent this security hole; it has a means of constructing a dynamically typesafe view of a specified collection (Collections.checkedCollection()). This ensures that any attempt to insert an element of incorrect type will result in a ClassCastException. But this approach introduces a counterintuitive programming model specifically to address an existing loophole in the security of the JVM. &lt;br /&gt;
&lt;br /&gt;
In C++, this security loophole does not exist since strict type-checking is employed at the points of instantiation of templates. However, this heterogeneous translation model employed by C++ will not fit with the current security model of the Java virtual machine. The JVM offers two levels of visibility – global level (public) and package level. Hence in some cases it becomes impossible to find out the proper package where the instantiated class will be placed honoring the visibility model of the JVM.&lt;br /&gt;
==Evolution of Generics==&lt;br /&gt;
Here we take Java programming language as an example to explain evolution of generics. Generics were introduced with Java 1.5. However, before that, the codes were bulky and messy but the results were same. Rather than simply using a List&amp;lt;Integer&amp;gt; or Comparable&amp;lt;String&amp;gt;, developers had to deal with a significant amount of inheritance, casting, and instanceof testing. For example, an ArrayList to store only Integers pre-generics might look like the below snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class IntegerList extends ArrayList{&lt;br /&gt;
     public boolean add(Object o){&lt;br /&gt;
            if(o instanceof Integer)&lt;br /&gt;
                return super.add(o);&lt;br /&gt;
             return false;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      public Integer get(int index){&lt;br /&gt;
           return (Integer)super.get(index);&lt;br /&gt;
      }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generics allows to write more modular and reusable code that is adaptable to various datatypes, yet logically restrictive as well. Currently, generics are implemented using erasure, which means that the generic type information is not available at runtime, which makes some kind of code hard to write. Generics were implemented this way to support backwards compatibility with older non-generic code. Reified generics would make the generic type information available at runtime, which would break legacy non-generic code. Generics are implemented using erasure, in which generic type parameters are simply removed at runtime. That doesn't render generics useless, because you get typechecking at compile-time based on the generic type parameters, and also because the compiler inserts casts in the code based on the type parameters.&lt;br /&gt;
===Erasure v/s Reification===&lt;br /&gt;
&lt;br /&gt;
Consider the below example, it won't work because of erasure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Test&amp;lt;Key, Val&amp;gt; {&lt;br /&gt;
  public void test(Key key) {&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
  public void test(Val value) {&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This would give a name clash error for having same erasure and one way to avoid the error is by renaming the method name but this will not the serve the purpose of overloading. Similarly, the below example would give errors because the JVM is not aware of the type T instead views it just as an Object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Test {&lt;br /&gt;
  public &amp;lt;T&amp;gt; void f() {&lt;br /&gt;
    T t = new T();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So reified generics have support in the compiler for preserving type information whereas type erased generics don't have and that &amp;quot;remember&amp;quot; the class they were created with during runtime. Below are some of the reasons why Java should have reified generics:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Type argument erasure cripples frameworks that works with generic types and this results in horrid workarounds&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reified generics allows Typesafe narrowing. Currently in Java, we first test the type of the object using the instanceof operator, and then attempt to downcast it using a C-style typecast&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Interoperability between statically-typed is difficult since few support reified generics.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But at the same time reified generics have issues and one of the main concern is incompatible with the current collections. So a test on &amp;lt;code&amp;gt;instanceof List&amp;lt;String&amp;gt;&amp;lt;/code&amp;gt; would now test that the object is an instance of &amp;lt;code&amp;gt;List&amp;lt;/code&amp;gt; but also that its elements are of type &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;. This requires a lot of work around since we need to distinguish between collections making used of reified types from their older types.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generic_programming&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generics_in_Java&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.oracle.com/technetwork/articles/javase/generics-136597.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://download.oracle.com/javase/tutorial/extra/generics/methods.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.cplusplus.com/doc/tutorial/templates/&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Template_(programming)&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.cs.binghamton.edu/~mike/presentations/java-generics-cs580c-fall-2007.pdf&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://jnb.ociweb.com/jnb/jnbJul2003.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://tech.puredanger.com/java7/#reified&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://gafter.blogspot.com/2006/11/reified-generics-for-java.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://relation.to/21406.lace&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://beust.com/weblog/2011/07/29/erasure-vs-reification&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://aszt.inf.elte.hu/~gsd/s/cikkek/java/p40-ghosh.pdf&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=55755</id>
		<title>CSC/ECE 517 Fall 2011/ch6 6c sj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=55755"/>
		<updated>2011-11-18T00:28:10Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Generic Programming==&lt;br /&gt;
&amp;lt;p&amp;gt;Generic programming is a style of computer programming in which algorithms are written in terms of &amp;lt;i&amp;gt;to-be-specified-later&amp;lt;/i&amp;gt; types that are then instantiated when needed for specific types provided as parameters. This enables writing common set of functions which differ only in the types on which they operate. This reduces duplication. Software entities created using generic programming are known as ''generics'' in [http://en.wikipedia.org/wiki/Ada_(programming_language) Ada], [http://en.wikipedia.org/wiki/Eiffel_(programming_language) Eiffel], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/F_Sharp_(programming_language) F#], and [http://en.wikipedia.org/wiki/Visual_Basic_.NET Visual Basic .NET]; parametric polymorphism in [http://en.wikipedia.org/wiki/ML_(programming_language) ML], [http://en.wikipedia.org/wiki/Scala_(programming_language Scala] and [http://en.wikipedia.org/wiki/Haskell_(programming_language) Haskell], [http://en.wikipedia.org/wiki/template_(programming) template]s in [http://en.wikipedia.org/wiki/C++ C++].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;For example, given various data structures and several algorithms, the brute force way would be implement them for each data structure which would mean that various combinations of implementations will be necessary. Generic programming reduces this effort.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Generics in Java==&lt;br /&gt;
===What are Generics?===&lt;br /&gt;
Generics were added to Java programming language as a part of J2SE 5.0 release in 2004. They allow programmers to develop generic and compile safe applications which enables a type or method to operate on objects of various type. This feature is well utilized while implementing [http://en.wikipedia.org/wiki/Java_Collections Java Collections]. The reason why people went into generic programming can be well explained using the below example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  List list = new ArrayList();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = (Integer)list.get(0);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this example, we insert a &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; into an &amp;lt;code&amp;gt;ArrayList&amp;lt;/code&amp;gt; and retrieve element by typecasting with Integer wrapper class. This throws a runtime exception because of Illegal class cast. But if we use generics, runtime exceptions can be avoided and the compiler will be able to catch such issues which in turn help a programmer to build a bug free code. So if we convert the above code to use generic then it would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  List&amp;lt;String&amp;gt; list = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = list.get(0); //line 1 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here at line 1 the compiler throws an error because the compiler on seeing the declaration of ArrayList will be expecting the list to have just &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; and thereby the return type of &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt; to be &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Implementing Generics:===&lt;br /&gt;
Java provides a feature which helps one to implement your own generic types and this will help to build more sophisticated and runtime error free applications. Consider the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
   interface List&amp;lt;N&amp;gt; {&lt;br /&gt;
                         void add(N i);&lt;br /&gt;
                         Iterator&amp;lt;N&amp;gt; iterator();&lt;br /&gt;
                      }&lt;br /&gt;
   interface Iterator&amp;lt;N&amp;gt; {&lt;br /&gt;
                            N next();&lt;br /&gt;
                            boolean hasNext();&lt;br /&gt;
                         }&lt;br /&gt;
   class LinkedList&amp;lt;N&amp;gt; implements List&amp;lt;N&amp;gt; {&lt;br /&gt;
                          //Business Logic   &lt;br /&gt;
                 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
So here, &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; can be replaced with any primitive data types or wrapper classes in the business logic. But we need to make sure that placeholders to be replaced with valid subtypes of Object. Generics implementation is not restricted for classes or interfaces, we can have for static/non static methods and constructors.&lt;br /&gt;
&lt;br /&gt;
Example for generic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;T&amp;gt; void fromArrayToCollection(T[] a, Collection&amp;lt;T&amp;gt; c) {&lt;br /&gt;
    for (T o : a) {&lt;br /&gt;
        c.add(o); // Correct&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Pros and Cons===&lt;br /&gt;
&amp;lt;b&amp;gt;Pros:&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduces the number of casts in the program, which in turn reduces the number of potential bugs in the program.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Improves code clarity and maintenance.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Cons:&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Parameter type information is not available at run time.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;The automatically generated casts may fail when interoperating with ill-behaved legacy code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Templates in C++==&lt;br /&gt;
===What are templates?===&lt;br /&gt;
&amp;lt;p&amp;gt;Templates are functions that can operate with &amp;lt;i&amp;gt;generic types&amp;lt;/i&amp;gt; which means that the functionality can be adapted for more than one type of data without repeating the entire code for each type. &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
===Overview===&lt;br /&gt;
Templates can be either function templates or class templates.&lt;br /&gt;
====Function Templates====&lt;br /&gt;
These are just like regular functions except that they can have arguments of different types. A single function definition works with different kinds of data types. During compile time, the actual functions are generated once the compiler knows the data type being used. This kind of template does not save any memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;typename Type&amp;gt;&lt;br /&gt;
Type max(Type a, Type b) {&lt;br /&gt;
    return a &amp;gt; b ? a : b;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  // This will call max &amp;lt;int&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3, 7) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This will call max&amp;lt;double&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3.0, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This type is ambiguous, so explicitly instantiate max&amp;lt;double&amp;gt;&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max&amp;lt;double&amp;gt;(3, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Class Templates====&lt;br /&gt;
A class template provides a specification for generating classes based on parameters. A class template is instantiated by passing a given set of types to it as template arguments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;class T&amp;gt;&lt;br /&gt;
class mypair {&lt;br /&gt;
    T values [2];&lt;br /&gt;
  public:&lt;br /&gt;
    mypair (T first, T second)&lt;br /&gt;
    {&lt;br /&gt;
      values[0]=first; values[1]=second;&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Features of C++ Templates===&lt;br /&gt;
Some of the features of C++ templates are:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Implemented in the compiler.&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;No runtime overhead&amp;lt;/ul&amp;gt;&amp;lt;ul&amp;gt;Requires template source to be in headers&amp;lt;/ul&amp;gt;&amp;lt;ul&amp;gt;Latent typing means template instantiator does no type checking&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Gloriﬁed macro facility&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;“Macros done right”/“Macros that look like classes”&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Can use template arguments for both classes and straight function&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Template specialization&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;Speciﬁc implementation of a templated type or method&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pattern matching and text replacement&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;Declarative model (like [http://en.wikipedia.org/wiki/Prolog Prolog])&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pros and Cons===&lt;br /&gt;
Usage of templates have both advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Pros&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduction in code size.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They are type-safe, that is, type-checking is done at compile time.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Cons&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Since all compilers are not good at their support for templates, they may not be very portable.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Compilers generate additional code for each template type, this could lead to huge code if usage of templates is not checked.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Information hiding is not achieved as the code is all exposed in the header.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Templates (C++) versus Generics (Java)==&lt;br /&gt;
We can compare templates in C++ versus generics in Java based on the following models of comparison,&lt;br /&gt;
1. Translation model - discussion based on the way generic code is translated.&lt;br /&gt;
2. Type model - discussion based on implementations in type interference, type aliasing and associated types.&lt;br /&gt;
3. Security model - discussion based on security loopholes, if any.&lt;br /&gt;
Let's look at these with some examples.&lt;br /&gt;
&lt;br /&gt;
===Translation Model===&lt;br /&gt;
====Java====&lt;br /&gt;
One of the design reasons behind Java's generics was to provide backward compatibility of legacy Java code. To achieve this, Java implementation has adopted the same representation policy for the raw type and the parametric type. The parametric type Collection&amp;lt;T&amp;gt; can be passed safely where the corresponding raw type Collection is expected. Hence the translation model of Java Generics is based on the “type erasure” model, where the translation erases the generic type parameter, replaces them by the bounding type (Object) and inserts casts to the actual places of usage. In order for method overriding to work correctly, the translation process also adds “bridge methods”, as illustrated in the following example.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class C&amp;lt;A&amp;gt; { abstract A id(A x); } &lt;br /&gt;
class D extends C&amp;lt;String&amp;gt; { String id(String x) { return x; } } &lt;br /&gt;
This will be translated to: &lt;br /&gt;
class C { abstract Object id(Object x); } &lt;br /&gt;
class D extends C { &lt;br /&gt;
    String id(String x) { return x; } &lt;br /&gt;
    // bridge method introduced by the translator to make  &lt;br /&gt;
    // overriding work correctly &lt;br /&gt;
    Object id(Object x) { return id((String)x); }  &lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====C++====&lt;br /&gt;
The translation model of C++ is based on instantiation – no static type checking is done on the generic code. The compiler generates separate copies of the component (class or function) for each instantiation with a distinct type and the type checking is performed after instantiation at each call site. Type checking of the bound types can only succeed when the input types have satisfied the type requirements of the function template body. It is because of this, that misleading error messages are thrown in by the compiler when a generic component is instantiated with an improper type.&lt;br /&gt;
&lt;br /&gt;
====Comparison====&lt;br /&gt;
The C++ model is loss-less in the sense that no type information is lost during runtime, though the implementation of the translation suffers from the drawbacks of the possibility of introducing code bloats and misleading error messages. On the other hand, the Java model emphasizes on retrofitting the raw types with the generic counterparts, but the type-erasure model delegates the generic types to “second class” status compared to the conventional types.&lt;br /&gt;
&lt;br /&gt;
===Type Model===&lt;br /&gt;
====Java====&lt;br /&gt;
====C++====&lt;br /&gt;
====Comparison====&lt;br /&gt;
&lt;br /&gt;
===Security Model===&lt;br /&gt;
====Java====&lt;br /&gt;
====C++====&lt;br /&gt;
====Comparison====&lt;br /&gt;
&lt;br /&gt;
==Evolution of Generics==&lt;br /&gt;
Here we take Java programming language as an example to explain evolution of generics. Generics were introduced with Java 1.5. However, before that, the codes were bulky and messy but the results were same. Rather than simply using a List&amp;lt;Integer&amp;gt; or Comparable&amp;lt;String&amp;gt;, developers had to deal with a significant amount of inheritance, casting, and instanceof testing. For example, an ArrayList to store only Integers pre-generics might look like the below snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class IntegerList extends ArrayList{&lt;br /&gt;
     public boolean add(Object o){&lt;br /&gt;
            if(o instanceof Integer)&lt;br /&gt;
                return super.add(o);&lt;br /&gt;
             return false;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      public Integer get(int index){&lt;br /&gt;
           return (Integer)super.get(index);&lt;br /&gt;
      }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generics allows to write more modular and reusable code that is adaptable to various datatypes, yet logically restrictive as well. Currently, generics are implemented using erasure, which means that the generic type information is not available at runtime, which makes some kind of code hard to write. Generics were implemented this way to support backwards compatibility with older non-generic code. Reified generics would make the generic type information available at runtime, which would break legacy non-generic code. Generics are implemented using erasure, in which generic type parameters are simply removed at runtime. That doesn't render generics useless, because you get typechecking at compile-time based on the generic type parameters, and also because the compiler inserts casts in the code based on the type parameters.&lt;br /&gt;
===Erasure v/s Reification===&lt;br /&gt;
&lt;br /&gt;
Consider the below example, it won't work because of erasure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Test&amp;lt;Key, Val&amp;gt; {&lt;br /&gt;
  public void test(Key key) {&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
  public void test(Val value) {&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This would give a name clash error for having same erasure and one way to avoid the error is by renaming the method name but this will not the serve the purpose of overloading. Similarly, the below example would give errors because the JVM is not aware of the type T instead views it just as an Object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Test {&lt;br /&gt;
  public &amp;lt;T&amp;gt; void f() {&lt;br /&gt;
    T t = new T();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So reified generics have support in the compiler for preserving type information whereas type erased generics don't have and that &amp;quot;remember&amp;quot; the class they were created with during runtime. Below are some of the reasons why Java should have reified generics:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Type argument erasure cripples frameworks that works with generic types and this results in horrid workarounds&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reified generics allows Typesafe narrowing. Currently in Java, we first test the type of the object using the instanceof operator, and then attempt to downcast it using a C-style typecast&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Interoperability between statically-typed is difficult since few support reified generics.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But at the same time reified generics have issues and one of the main concern is incompatible with the current collections. So a test on &amp;lt;code&amp;gt;instanceof List&amp;lt;String&amp;gt;&amp;lt;/code&amp;gt; would now test that the object is an instance of &amp;lt;code&amp;gt;List&amp;lt;/code&amp;gt; but also that its elements are of type &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;. This requires a lot of work around since we need to distinguish between collections making used of reified types from their older types.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generic_programming&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generics_in_Java&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.oracle.com/technetwork/articles/javase/generics-136597.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://download.oracle.com/javase/tutorial/extra/generics/methods.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.cplusplus.com/doc/tutorial/templates/&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Template_(programming)&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.cs.binghamton.edu/~mike/presentations/java-generics-cs580c-fall-2007.pdf&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://jnb.ociweb.com/jnb/jnbJul2003.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://tech.puredanger.com/java7/#reified&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://gafter.blogspot.com/2006/11/reified-generics-for-java.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://relation.to/21406.lace&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://beust.com/weblog/2011/07/29/erasure-vs-reification&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://aszt.inf.elte.hu/~gsd/s/cikkek/java/p40-ghosh.pdf&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=55753</id>
		<title>CSC/ECE 517 Fall 2011/ch6 6c sj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=55753"/>
		<updated>2011-11-18T00:23:55Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Generic Programming==&lt;br /&gt;
&amp;lt;p&amp;gt;Generic programming is a style of computer programming in which algorithms are written in terms of &amp;lt;i&amp;gt;to-be-specified-later&amp;lt;/i&amp;gt; types that are then instantiated when needed for specific types provided as parameters. This enables writing common set of functions which differ only in the types on which they operate. This reduces duplication. Software entities created using generic programming are known as ''generics'' in [http://en.wikipedia.org/wiki/Ada_(programming_language) Ada], [http://en.wikipedia.org/wiki/Eiffel_(programming_language) Eiffel], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/F_Sharp_(programming_language) F#], and [http://en.wikipedia.org/wiki/Visual_Basic_.NET Visual Basic .NET]; parametric polymorphism in [http://en.wikipedia.org/wiki/ML_(programming_language) ML], [http://en.wikipedia.org/wiki/Scala_(programming_language Scala] and [http://en.wikipedia.org/wiki/Haskell_(programming_language) Haskell], [http://en.wikipedia.org/wiki/template_(programming) template]s in [http://en.wikipedia.org/wiki/C++ C++].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;For example, given various data structures and several algorithms, the brute force way would be implement them for each data structure which would mean that various combinations of implementations will be necessary. Generic programming reduces this effort.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Generics in Java==&lt;br /&gt;
===What are Generics?===&lt;br /&gt;
Generics were added to Java programming language as a part of J2SE 5.0 release in 2004. They allow programmers to develop generic and compile safe applications which enables a type or method to operate on objects of various type. This feature is well utilized while implementing [http://en.wikipedia.org/wiki/Java_Collections Java Collections]. The reason why people went into generic programming can be well explained using the below example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  List list = new ArrayList();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = (Integer)list.get(0);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this example, we insert a &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; into an &amp;lt;code&amp;gt;ArrayList&amp;lt;/code&amp;gt; and retrieve element by typecasting with Integer wrapper class. This throws a runtime exception because of Illegal class cast. But if we use generics, runtime exceptions can be avoided and the compiler will be able to catch such issues which in turn help a programmer to build a bug free code. So if we convert the above code to use generic then it would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  List&amp;lt;String&amp;gt; list = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = list.get(0); //line 1 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here at line 1 the compiler throws an error because the compiler on seeing the declaration of ArrayList will be expecting the list to have just &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; and thereby the return type of &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt; to be &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Implementing Generics:===&lt;br /&gt;
Java provides a feature which helps one to implement your own generic types and this will help to build more sophisticated and runtime error free applications. Consider the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
   interface List&amp;lt;N&amp;gt; {&lt;br /&gt;
                         void add(N i);&lt;br /&gt;
                         Iterator&amp;lt;N&amp;gt; iterator();&lt;br /&gt;
                      }&lt;br /&gt;
   interface Iterator&amp;lt;N&amp;gt; {&lt;br /&gt;
                            N next();&lt;br /&gt;
                            boolean hasNext();&lt;br /&gt;
                         }&lt;br /&gt;
   class LinkedList&amp;lt;N&amp;gt; implements List&amp;lt;N&amp;gt; {&lt;br /&gt;
                          //Business Logic   &lt;br /&gt;
                 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
So here, &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; can be replaced with any primitive data types or wrapper classes in the business logic. But we need to make sure that placeholders to be replaced with valid subtypes of Object. Generics implementation is not restricted for classes or interfaces, we can have for static/non static methods and constructors.&lt;br /&gt;
&lt;br /&gt;
Example for generic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;T&amp;gt; void fromArrayToCollection(T[] a, Collection&amp;lt;T&amp;gt; c) {&lt;br /&gt;
    for (T o : a) {&lt;br /&gt;
        c.add(o); // Correct&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Pros and Cons===&lt;br /&gt;
&amp;lt;b&amp;gt;Pros:&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduces the number of casts in the program, which in turn reduces the number of potential bugs in the program.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Improves code clarity and maintenance.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Cons:&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Parameter type information is not available at run time.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;The automatically generated casts may fail when interoperating with ill-behaved legacy code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Templates in C++==&lt;br /&gt;
===What are templates?===&lt;br /&gt;
&amp;lt;p&amp;gt;Templates are functions that can operate with &amp;lt;i&amp;gt;generic types&amp;lt;/i&amp;gt; which means that the functionality can be adapted for more than one type of data without repeating the entire code for each type. &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
===Overview===&lt;br /&gt;
Templates can be either function templates or class templates.&lt;br /&gt;
====Function Templates====&lt;br /&gt;
These are just like regular functions except that they can have arguments of different types. A single function definition works with different kinds of data types. During compile time, the actual functions are generated once the compiler knows the data type being used. This kind of template does not save any memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;typename Type&amp;gt;&lt;br /&gt;
Type max(Type a, Type b) {&lt;br /&gt;
    return a &amp;gt; b ? a : b;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  // This will call max &amp;lt;int&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3, 7) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This will call max&amp;lt;double&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3.0, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This type is ambiguous, so explicitly instantiate max&amp;lt;double&amp;gt;&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max&amp;lt;double&amp;gt;(3, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Class Templates====&lt;br /&gt;
A class template provides a specification for generating classes based on parameters. A class template is instantiated by passing a given set of types to it as template arguments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;class T&amp;gt;&lt;br /&gt;
class mypair {&lt;br /&gt;
    T values [2];&lt;br /&gt;
  public:&lt;br /&gt;
    mypair (T first, T second)&lt;br /&gt;
    {&lt;br /&gt;
      values[0]=first; values[1]=second;&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Features of C++ Templates===&lt;br /&gt;
Some of the features of C++ templates are:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Implemented in the compiler.&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;No runtime overhead&amp;lt;/ul&amp;gt;&amp;lt;ul&amp;gt;Requires template source to be in headers&amp;lt;/ul&amp;gt;&amp;lt;ul&amp;gt;Latent typing means template instantiator does no type checking&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Gloriﬁed macro facility&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;“Macros done right”/“Macros that look like classes”&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Can use template arguments for both classes and straight function&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Template specialization&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;Speciﬁc implementation of a templated type or method&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pattern matching and text replacement&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;Declarative model (like [http://en.wikipedia.org/wiki/Prolog Prolog])&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pros and Cons===&lt;br /&gt;
Usage of templates have both advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Pros&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduction in code size.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They are type-safe, that is, type-checking is done at compile time.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Cons&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Since all compilers are not good at their support for templates, they may not be very portable.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Compilers generate additional code for each template type, this could lead to huge code if usage of templates is not checked.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Information hiding is not achieved as the code is all exposed in the header.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Templates (C++) versus Generics (Java)==&lt;br /&gt;
We can compare templates in C++ versus generics in Java based on the following models of comparison,&lt;br /&gt;
1. Translation model - discussion based on the way generic code is translated.&lt;br /&gt;
2. Type model - discussion based on implementations in type interference, type aliasing and associated types.&lt;br /&gt;
3. Security model - discussion based on security loopholes, if any.&lt;br /&gt;
Let's look at these with some examples.&lt;br /&gt;
&lt;br /&gt;
===Translation Model===&lt;br /&gt;
====Java====&lt;br /&gt;
One of the design reasons behind Java's generics was to provide backward compatibility of legacy Java code. To achieve this, Java implementation has adopted the same representation policy for the raw type and the parametric type. The parametric type Collection&amp;lt;T&amp;gt; can be passed safely where the corresponding raw type Collection is expected. Hence the translation model of Java Generics is based on the “type erasure” model, where the translation erases the generic type parameter, replaces them by the bounding type (Object) and inserts casts to the actual places of usage. In order for method overriding to work correctly, the translation process also adds “bridge methods”, as illustrated in the following example.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class C&amp;lt;A&amp;gt; { abstract A id(A x); } &lt;br /&gt;
class D extends C&amp;lt;String&amp;gt; { String id(String x) { return x; } } &lt;br /&gt;
This will be translated to: &lt;br /&gt;
class C { abstract Object id(Object x); } &lt;br /&gt;
class D extends C { &lt;br /&gt;
    String id(String x) { return x; } &lt;br /&gt;
    // bridge method introduced by the translator to make  &lt;br /&gt;
    // overriding work correctly &lt;br /&gt;
    Object id(Object x) { return id((String)x); }  &lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====C++====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Type Model===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Security Model===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Evolution of Generics==&lt;br /&gt;
Here we take Java programming language as an example to explain evolution of generics. Generics were introduced with Java 1.5. However, before that, the codes were bulky and messy but the results were same. Rather than simply using a List&amp;lt;Integer&amp;gt; or Comparable&amp;lt;String&amp;gt;, developers had to deal with a significant amount of inheritance, casting, and instanceof testing. For example, an ArrayList to store only Integers pre-generics might look like the below snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class IntegerList extends ArrayList{&lt;br /&gt;
     public boolean add(Object o){&lt;br /&gt;
            if(o instanceof Integer)&lt;br /&gt;
                return super.add(o);&lt;br /&gt;
             return false;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      public Integer get(int index){&lt;br /&gt;
           return (Integer)super.get(index);&lt;br /&gt;
      }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generics allows to write more modular and reusable code that is adaptable to various datatypes, yet logically restrictive as well. Currently, generics are implemented using erasure, which means that the generic type information is not available at runtime, which makes some kind of code hard to write. Generics were implemented this way to support backwards compatibility with older non-generic code. Reified generics would make the generic type information available at runtime, which would break legacy non-generic code. Generics are implemented using erasure, in which generic type parameters are simply removed at runtime. That doesn't render generics useless, because you get typechecking at compile-time based on the generic type parameters, and also because the compiler inserts casts in the code based on the type parameters.&lt;br /&gt;
===Erasure v/s Reification===&lt;br /&gt;
&lt;br /&gt;
Consider the below example, it won't work because of erasure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Test&amp;lt;Key, Val&amp;gt; {&lt;br /&gt;
  public void test(Key key) {&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
  public void test(Val value) {&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This would give a name clash error for having same erasure and one way to avoid the error is by renaming the method name but this will not the serve the purpose of overloading. Similarly, the below example would give errors because the JVM is not aware of the type T instead views it just as an Object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Test {&lt;br /&gt;
  public &amp;lt;T&amp;gt; void f() {&lt;br /&gt;
    T t = new T();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So reified generics have support in the compiler for preserving type information whereas type erased generics don't have and that &amp;quot;remember&amp;quot; the class they were created with during runtime. Below are some of the reasons why Java should have reified generics:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Type argument erasure cripples frameworks that works with generic types and this results in horrid workarounds&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reified generics allows Typesafe narrowing. Currently in Java, we first test the type of the object using the instanceof operator, and then attempt to downcast it using a C-style typecast&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Interoperability between statically-typed is difficult since few support reified generics.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But at the same time reified generics have issues and one of the main concern is incompatible with the current collections. So a test on &amp;lt;code&amp;gt;instanceof List&amp;lt;String&amp;gt;&amp;lt;/code&amp;gt; would now test that the object is an instance of &amp;lt;code&amp;gt;List&amp;lt;/code&amp;gt; but also that its elements are of type &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;. This requires a lot of work around since we need to distinguish between collections making used of reified types from their older types.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generic_programming&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generics_in_Java&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.oracle.com/technetwork/articles/javase/generics-136597.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://download.oracle.com/javase/tutorial/extra/generics/methods.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.cplusplus.com/doc/tutorial/templates/&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Template_(programming)&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.cs.binghamton.edu/~mike/presentations/java-generics-cs580c-fall-2007.pdf&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://jnb.ociweb.com/jnb/jnbJul2003.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://tech.puredanger.com/java7/#reified&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://gafter.blogspot.com/2006/11/reified-generics-for-java.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://relation.to/21406.lace&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://beust.com/weblog/2011/07/29/erasure-vs-reification&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://aszt.inf.elte.hu/~gsd/s/cikkek/java/p40-ghosh.pdf&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=55476</id>
		<title>CSC/ECE 517 Fall 2011/ch6 6c sj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=55476"/>
		<updated>2011-11-17T11:26:36Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Generic Programming==&lt;br /&gt;
&amp;lt;p&amp;gt;Generic programming is a style of computer programming in which algorithms are written in terms of &amp;lt;i&amp;gt;to-be-specified-later&amp;lt;/i&amp;gt; types that are then instantiated when needed for specific types provided as parameters. This enables writing common set of functions which differ only in the types on which they operate. This reduces duplication. Software entities created using generic programming are known as ''generics'' in [http://en.wikipedia.org/wiki/Ada_(programming_language) Ada], [http://en.wikipedia.org/wiki/Eiffel_(programming_language) Eiffel], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/F_Sharp_(programming_language) F#], and [http://en.wikipedia.org/wiki/Visual_Basic_.NET Visual Basic .NET]; parametric polymorphism in [http://en.wikipedia.org/wiki/ML_(programming_language) ML], [http://en.wikipedia.org/wiki/Scala_(programming_language Scala] and [http://en.wikipedia.org/wiki/Haskell_(programming_language) Haskell], [http://en.wikipedia.org/wiki/template_(programming) template]s in [http://en.wikipedia.org/wiki/C++ C++].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;For example, given various data structures and several algorithms, the brute force way would be implement them for each data structure which would mean that various combinations of implementations will be necessary. Generic programming reduces this effort.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Generics in Java?==&lt;br /&gt;
Generics were added to Java programming language as a part of J2SE 5.0 release in 2004. They allow programmers to develop generic and compile safe applications which enables a type or method to operate on objects of various type. This feature is well utilized while implementing [http://en.wikipedia.org/wiki/Java_Collections Java Collections]. The reason why people went into generic programming can be well explained using the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  List list = new ArrayList();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = (Integer)list.get(0);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
In this example, we insert a &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; into an &amp;lt;code&amp;gt;ArrayList&amp;lt;/code&amp;gt; and retrieve element by typecasting with Integer wrapper class. This throws a runtime exception because of Illegal class cast. But if we use generics, runtime exceptions can be avoided and the compiler will be able to catch such issues which in turn help a programmer to build a bug free code. So if we convert the above code to use generic then it would look like this:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  List&amp;lt;String&amp;gt; list = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = list.get(0); //line 1 &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Here at line 1 the compiler throws an error because the compiler on seeing the declaration of ArrayList will be expecting the list to have just &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; and thereby the return type of &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt; to be &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Implementing Generics:'''&lt;br /&gt;
Java provides a feature which helps one to implement your own generic types and this will help to build more sophisticated and runtime error free applications. Consider the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
   interface List&amp;lt;N&amp;gt; {&lt;br /&gt;
                         void add(N i);&lt;br /&gt;
                         Iterator&amp;lt;N&amp;gt; iterator();&lt;br /&gt;
                      }&lt;br /&gt;
   interface Iterator&amp;lt;N&amp;gt; {&lt;br /&gt;
                            N next();&lt;br /&gt;
                            boolean hasNext();&lt;br /&gt;
                         }&lt;br /&gt;
   class LinkedList&amp;lt;N&amp;gt; implements List&amp;lt;N&amp;gt; {&lt;br /&gt;
                          //Business Logic   &lt;br /&gt;
                 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
So here, &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; can be replaced with any primitive data types or wrapper classes in the business logic. But we need to make sure that placeholders to be replaced with valid subtypes of Object. Generics implementation is not restricted for classes or interfaces, we can have for static/non static methods and constructors.&lt;br /&gt;
&lt;br /&gt;
Example for generic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static &amp;lt;T&amp;gt; void fromArrayToCollection(T[] a, Collection&amp;lt;T&amp;gt; c) {&lt;br /&gt;
    for (T o : a) {&lt;br /&gt;
        c.add(o); // Correct&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Templates in C++==&lt;br /&gt;
===What are templates?===&lt;br /&gt;
&amp;lt;p&amp;gt;Templates are functions that can operate with &amp;lt;i&amp;gt;generic types&amp;lt;/i&amp;gt; which means that the functionality can be adapted for more than one type of data without repeating the entire code for each type. &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
===Overview===&lt;br /&gt;
Templates can be either function templates or class templates.&lt;br /&gt;
====Function Templates====&lt;br /&gt;
These are just like regular functions except that they can have arguments of different types. A single function definition works with different kinds of data types. During compile time, the actual functions are generated once the compiler knows the data type being used. This kind of template does not save any memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;typename Type&amp;gt;&lt;br /&gt;
Type max(Type a, Type b) {&lt;br /&gt;
    return a &amp;gt; b ? a : b;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  // This will call max &amp;lt;int&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3, 7) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This will call max&amp;lt;double&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3.0, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This type is ambiguous, so explicitly instantiate max&amp;lt;double&amp;gt;&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max&amp;lt;double&amp;gt;(3, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Class Templates====&lt;br /&gt;
A class template provides a specification for generating classes based on parameters. A class template is instantiated by passing a given set of types to it as template arguments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;class T&amp;gt;&lt;br /&gt;
class mypair {&lt;br /&gt;
    T values [2];&lt;br /&gt;
  public:&lt;br /&gt;
    mypair (T first, T second)&lt;br /&gt;
    {&lt;br /&gt;
      values[0]=first; values[1]=second;&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Features of C++ Templates===&lt;br /&gt;
Some of the features of C++ templates are:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Implemented in the compiler.&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;No runtime overhead&amp;lt;/ul&amp;gt;&amp;lt;ul&amp;gt;Requires template source to be in headers&amp;lt;/ul&amp;gt;&amp;lt;ul&amp;gt;Latent typing means template instantiator does no type checking&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Gloriﬁed macro facility&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;“Macros done right”/“Macros that look like classes”&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Can use template arguments for both classes and straight function&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Template specialization&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;Speciﬁc implementation of a templated type or method&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pattern matching and text replacement&amp;lt;ol&amp;gt;&amp;lt;ul&amp;gt;Declarative model (like [http://en.wikipedia.org/wiki/Prolog Prolog])&amp;lt;/ul&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pros and Cons===&lt;br /&gt;
Usage of templates have both advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Pros&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduction in code size.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They are type-safe, that is, type-checking is done at compile time.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Cons&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Since all compilers are not good at their support for templates, they may not be very portable.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Compilers generate additional code for each template type, this could lead to huge code if usage of templates is not checked.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Information hiding is not achieved as the code is all exposed in the header.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generic_programming&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generics_in_Java&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.oracle.com/technetwork/articles/javase/generics-136597.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://download.oracle.com/javase/tutorial/extra/generics/methods.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.cplusplus.com/doc/tutorial/templates/&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Template_(programming)&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.cs.binghamton.edu/~mike/presentations/java-generics-cs580c-fall-2007.pdf&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=54901</id>
		<title>CSC/ECE 517 Fall 2011/ch6 6c sj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=54901"/>
		<updated>2011-11-14T03:54:53Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Generic Programming==&lt;br /&gt;
&amp;lt;p&amp;gt;Generic programming is a style of computer programming in which algorithms are written in terms of &amp;lt;i&amp;gt;to-be-specified-later&amp;lt;/i&amp;gt; types that are then instantiated when needed for specific types provided as parameters. This enables writing common set of functions which differ only in the types on which they operate. This reduces duplication. Software entities created using generic programming are known as ''generics'' in [http://en.wikipedia.org/wiki/Ada_(programming_language) Ada], [http://en.wikipedia.org/wiki/Eiffel_(programming_language) Eiffel], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/F_Sharp_(programming_language) F#], and [http://en.wikipedia.org/wiki/Visual_Basic_.NET Visual Basic .NET]; parametric polymorphism in [http://en.wikipedia.org/wiki/ML_(programming_language) ML], [http://en.wikipedia.org/wiki/Scala_(programming_language Scala] and [http://en.wikipedia.org/wiki/Haskell_(programming_language) Haskell], [http://en.wikipedia.org/wiki/template_(programming) template]s in [http://en.wikipedia.org/wiki/C++ C++].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;For example, given various data structures and several algorithms, the brute force way would be implement them for each data structure which would mean that various combinations of implementations will be necessary. Generic programming reduces this effort.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Generics in Java?==&lt;br /&gt;
Generics were added to Java programming language as a part of J2SE 5.0 release in 2004. They allow programmers to develop generic and compile safe applications which enables a type or method to operate on objects of various type. This feature is well utilized while implementing [http://en.wikipedia.org/wiki/Java_Collections Java Collections]. The reason why people went into generic programming can be well explained using the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  List list = new ArrayList();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = (Integer)list.get(0);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
In this example, we insert a &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; into an &amp;lt;code&amp;gt;ArrayList&amp;lt;/code&amp;gt; and retrieve element by typecasting with Integer wrapper class. This throws a runtime exception because of Illegal class cast. But if we use generics, runtime exceptions can be avoided and the compiler will be able to catch such issues which in turn help a programmer to build a bug free code. So if we convert the above code to use generic then it would look like this:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  List&amp;lt;String&amp;gt; list = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = list.get(0); //line 1 &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Here at line 1 the compiler throws an error because the compiler on seeing the declaration of ArrayList will be expecting the list to have just &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; and thereby the return type of &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt; to be &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Implementing Generics:'''&lt;br /&gt;
Java provides a feature which helps one to implement your own generic types and this will help to build more sophisticated and runtime error free applications. Consider the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
   interface List&amp;lt;N&amp;gt; {&lt;br /&gt;
                         void add(N i);&lt;br /&gt;
                         Iterator&amp;lt;N&amp;gt; iterator();&lt;br /&gt;
                      }&lt;br /&gt;
   interface Iterator&amp;lt;N&amp;gt; {&lt;br /&gt;
                            N next();&lt;br /&gt;
                            boolean hasNext();&lt;br /&gt;
                         }&lt;br /&gt;
   class LinkedList&amp;lt;N&amp;gt; implements List&amp;lt;N&amp;gt; {&lt;br /&gt;
                          //Business Logic   &lt;br /&gt;
                 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
So here, &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; can be replaced with any primitive data types or wrapper classes in the business logic. But we need to make sure that placeholders to be replaced with valid subtypes of Object. Generics implementation is not restricted for classes or interfaces, we can have for static/non static methods and constructors.&lt;br /&gt;
&lt;br /&gt;
Example for generic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static &amp;lt;T&amp;gt; void fromArrayToCollection(T[] a, Collection&amp;lt;T&amp;gt; c) {&lt;br /&gt;
    for (T o : a) {&lt;br /&gt;
        c.add(o); // Correct&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Templates in C++==&lt;br /&gt;
===What are templates?===&lt;br /&gt;
&amp;lt;p&amp;gt;Templates are functions that can operate with &amp;lt;i&amp;gt;generic types&amp;lt;/i&amp;gt; which means that the functionality can be adapted for more than one type of data without repeating the entire code for each type. &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
===Overview===&lt;br /&gt;
Templates can be either function templates or class templates.&lt;br /&gt;
====Function Templates====&lt;br /&gt;
These are just like regular functions except that they can have arguments of different types. A single function definition works with different kinds of data types. During compile time, the actual functions are generated once the compiler knows the data type being used. This kind of template does not save any memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;typename Type&amp;gt;&lt;br /&gt;
Type max(Type a, Type b) {&lt;br /&gt;
    return a &amp;gt; b ? a : b;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  // This will call max &amp;lt;int&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3, 7) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This will call max&amp;lt;double&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3.0, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This type is ambiguous, so explicitly instantiate max&amp;lt;double&amp;gt;&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max&amp;lt;double&amp;gt;(3, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Class Templates====&lt;br /&gt;
A class template provides a specification for generating classes based on parameters. A class template is instantiated by passing a given set of types to it as template arguments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;class T&amp;gt;&lt;br /&gt;
class mypair {&lt;br /&gt;
    T values [2];&lt;br /&gt;
  public:&lt;br /&gt;
    mypair (T first, T second)&lt;br /&gt;
    {&lt;br /&gt;
      values[0]=first; values[1]=second;&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pros and Cons===&lt;br /&gt;
Usage of templates have both advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Pros&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduction in code size.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They are type-safe, that is, type-checking is done at compile time.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Cons&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Since all compilers are not good at their support for templates, they may not be very portable.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Compilers generate additional code for each template type, this could lead to huge code if usage of templates is not checked.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Information hiding is not achieved as the code is all exposed in the header.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generic_programming&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generics_in_Java&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.oracle.com/technetwork/articles/javase/generics-136597.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://download.oracle.com/javase/tutorial/extra/generics/methods.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.cplusplus.com/doc/tutorial/templates/&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Template_(programming)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=54900</id>
		<title>CSC/ECE 517 Fall 2011/ch6 6c sj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=54900"/>
		<updated>2011-11-14T03:54:25Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Generic Programming==&lt;br /&gt;
&amp;lt;p&amp;gt;Generic programming is a style of computer programming in which algorithms are written in terms of &amp;lt;i&amp;gt;to-be-specified-later&amp;lt;/i&amp;gt; types that are then instantiated when needed for specific types provided as parameters. This enables writing common set of functions which differ only in the types on which they operate. This reduces duplication. Software entities created using generic programming are known as ''generics'' in [http://en.wikipedia.org/wiki/Ada_(programming_language) Ada], [http://en.wikipedia.org/wiki/Eiffel_(programming_language) Eiffel], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/F_Sharp_(programming_language) F#], and [http://en.wikipedia.org/wiki/Visual_Basic_.NET Visual Basic .NET]; parametric polymorphism in [http://en.wikipedia.org/wiki/ML_(programming_language) ML], [http://en.wikipedia.org/wiki/Scala_(programming_language Scala] and [http://en.wikipedia.org/wiki/Haskell_(programming_language) Haskell], [http://en.wikipedia.org/wiki/template_(programming) template]s in [http://en.wikipedia.org/wiki/C++ C++].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;For example, given various data structures and several algorithms, the brute force way would be implement them for each data structure which would mean that various combinations of implementations will be necessary. Generic programming reduces this effort.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Generics in Java?==&lt;br /&gt;
Generics were added to Java programming language as a part of J2SE 5.0 release in 2004. They allow programmers to develop generic and compile safe applications which enables a type or method to operate on objects of various type. This feature is well utilized while implementing [http://en.wikipedia.org/wiki/Java_Collections Java Collections]. The reason why people went into generic programming can be well explained using the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  List list = new ArrayList();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = (Integer)list.get(0);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
In this example, we insert a &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; into an &amp;lt;code&amp;gt;ArrayList&amp;lt;/code&amp;gt; and retrieve element by typecasting with Integer wrapper class. This throws a runtime exception because of Illegal class cast. But if we use generics, runtime exceptions can be avoided and the compiler will be able to catch such issues which in turn help a programmer to build a bug free code. So if we convert the above code to use generic then it would look like this:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  List&amp;lt;String&amp;gt; list = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = list.get(0); //line 1 &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Here at line 1 the compiler throws an error because the compiler on seeing the declaration of ArrayList will be expecting the list to have just &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; and thereby the return type of &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt; to be &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Implementing Generics:'''&lt;br /&gt;
Java provides a feature which helps one to implement your own generic types and this will help to build more sophisticated and runtime error free applications. Consider the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
   interface List&amp;lt;N&amp;gt; {&lt;br /&gt;
                         void add(N i);&lt;br /&gt;
                         Iterator&amp;lt;N&amp;gt; iterator();&lt;br /&gt;
                      }&lt;br /&gt;
   interface Iterator&amp;lt;N&amp;gt; {&lt;br /&gt;
                            N next();&lt;br /&gt;
                            boolean hasNext();&lt;br /&gt;
                         }&lt;br /&gt;
   class LinkedList&amp;lt;N&amp;gt; implements List&amp;lt;N&amp;gt; {&lt;br /&gt;
                          //Business Logic   &lt;br /&gt;
                 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
So here, &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; can be replaced with any primitive data types or wrapper classes in the business logic. But we need to make sure that placeholders to be replaced with valid subtypes of Object. Generics implementation is not restricted for classes or interfaces, we can have for static/non static methods and constructors.&lt;br /&gt;
&lt;br /&gt;
Example for generic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static &amp;lt;T&amp;gt; void fromArrayToCollection(T[] a, Collection&amp;lt;T&amp;gt; c) {&lt;br /&gt;
    for (T o : a) {&lt;br /&gt;
        c.add(o); // Correct&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Templates in C++==&lt;br /&gt;
===What are templates?===&lt;br /&gt;
&amp;lt;p&amp;gt;Templates are functions that can operate with &amp;lt;i&amp;gt;generic types&amp;lt;/i&amp;gt; which means that the functionality can be adapted for more than one type of data without repeating the entire code for each type. &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
===Overview===&lt;br /&gt;
Templates can be either function templates or class templates.&lt;br /&gt;
====Function Templates====&lt;br /&gt;
These are just like regular functions except that they can have arguments of different types. A single function definition works with different kinds of data types. During compile time, the actual functions are generated once the compiler knows the data type being used. This kind of template does not save any memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;typename Type&amp;gt;&lt;br /&gt;
Type max(Type a, Type b) {&lt;br /&gt;
    return a &amp;gt; b ? a : b;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  // This will call max &amp;lt;int&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3, 7) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This will call max&amp;lt;double&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3.0, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This type is ambiguous, so explicitly instantiate max&amp;lt;double&amp;gt;&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max&amp;lt;double&amp;gt;(3, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Class Templates====&lt;br /&gt;
A class template provides a specification for generating classes based on parameters. A class template is instantiated by passing a given set of types to it as template arguments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;class T&amp;gt;&lt;br /&gt;
class mypair {&lt;br /&gt;
    T values [2];&lt;br /&gt;
  public:&lt;br /&gt;
    mypair (T first, T second)&lt;br /&gt;
    {&lt;br /&gt;
      values[0]=first; values[1]=second;&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pros and Cons===&lt;br /&gt;
Usage of templates have both advantages and disadvantages.&lt;br /&gt;
&amp;lt;b&amp;gt;Pros&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduction in code size.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They are type-safe, that is, type-checking is done at compile time.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Cons&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Since all compilers are not good at their support for templates, they may not be very portable.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Compilers generate additional code for each template type, this could lead to huge code if usage of templates is not checked.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Information hiding is not achieved as the code is all exposed in the header.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generic_programming&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generics_in_Java&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.oracle.com/technetwork/articles/javase/generics-136597.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://download.oracle.com/javase/tutorial/extra/generics/methods.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.cplusplus.com/doc/tutorial/templates/&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Template_(programming)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=54899</id>
		<title>CSC/ECE 517 Fall 2011/ch6 6c sj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=54899"/>
		<updated>2011-11-14T03:47:59Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Generic Programming==&lt;br /&gt;
&amp;lt;p&amp;gt;Generic programming is a style of computer programming in which algorithms are written in terms of &amp;lt;i&amp;gt;to-be-specified-later&amp;lt;/i&amp;gt; types that are then instantiated when needed for specific types provided as parameters. This enables writing common set of functions which differ only in the types on which they operate. This reduces duplication. Software entities created using generic programming are known as ''generics'' in [http://en.wikipedia.org/wiki/Ada_(programming_language) Ada], [http://en.wikipedia.org/wiki/Eiffel_(programming_language) Eiffel], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/F_Sharp_(programming_language) F#], and [http://en.wikipedia.org/wiki/Visual_Basic_.NET Visual Basic .NET]; parametric polymorphism in [http://en.wikipedia.org/wiki/ML_(programming_language) ML], [http://en.wikipedia.org/wiki/Scala_(programming_language Scala] and [http://en.wikipedia.org/wiki/Haskell_(programming_language) Haskell], [http://en.wikipedia.org/wiki/template_(programming) template]s in [http://en.wikipedia.org/wiki/C++ C++].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;For example, given various data structures and several algorithms, the brute force way would be implement them for each data structure which would mean that various combinations of implementations will be necessary. Generic programming reduces this effort.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Generics in Java?==&lt;br /&gt;
Generics were added to Java programming language as a part of J2SE 5.0 release in 2004. They allow programmers to develop generic and compile safe applications which enables a type or method to operate on objects of various type. This feature is well utilized while implementing [http://en.wikipedia.org/wiki/Java_Collections Java Collections]. The reason why people went into generic programming can be well explained using the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  List list = new ArrayList();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = (Integer)list.get(0);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
In this example, we insert a &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; into an &amp;lt;code&amp;gt;ArrayList&amp;lt;/code&amp;gt; and retrieve element by typecasting with Integer wrapper class. This throws a runtime exception because of Illegal class cast. But if we use generics, runtime exceptions can be avoided and the compiler will be able to catch such issues which in turn help a programmer to build a bug free code. So if we convert the above code to use generic then it would look like this:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  List&amp;lt;String&amp;gt; list = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = list.get(0); //line 1 &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Here at line 1 the compiler throws an error because the compiler on seeing the declaration of ArrayList will be expecting the list to have just &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; and thereby the return type of &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt; to be &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Implementing Generics:'''&lt;br /&gt;
Java provides a feature which helps one to implement your own generic types and this will help to build more sophisticated and runtime error free applications. Consider the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
   interface List&amp;lt;N&amp;gt; {&lt;br /&gt;
                         void add(N i);&lt;br /&gt;
                         Iterator&amp;lt;N&amp;gt; iterator();&lt;br /&gt;
                      }&lt;br /&gt;
   interface Iterator&amp;lt;N&amp;gt; {&lt;br /&gt;
                            N next();&lt;br /&gt;
                            boolean hasNext();&lt;br /&gt;
                         }&lt;br /&gt;
   class LinkedList&amp;lt;N&amp;gt; implements List&amp;lt;N&amp;gt; {&lt;br /&gt;
                          //Business Logic   &lt;br /&gt;
                 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
So here, &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; can be replaced with any primitive data types or wrapper classes in the business logic. But we need to make sure that placeholders to be replaced with valid subtypes of Object. Generics implementation is not restricted for classes or interfaces, we can have for static/non static methods and constructors.&lt;br /&gt;
&lt;br /&gt;
Example for generic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static &amp;lt;T&amp;gt; void fromArrayToCollection(T[] a, Collection&amp;lt;T&amp;gt; c) {&lt;br /&gt;
    for (T o : a) {&lt;br /&gt;
        c.add(o); // Correct&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Templates in C++==&lt;br /&gt;
===What are templates?===&lt;br /&gt;
&amp;lt;p&amp;gt;Templates are functions that can operate with &amp;lt;i&amp;gt;generic types&amp;lt;/i&amp;gt; which means that the functionality can be adapted for more than one type of data without repeating the entire code for each type. &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
===Overview===&lt;br /&gt;
Templates can be either function templates or class templates.&lt;br /&gt;
====Function Templates====&lt;br /&gt;
These are just like regular functions except that they can have arguments of different types. A single function definition works with different kinds of data types. During compile time, the actual functions are generated once the compiler knows the data type being used. This kind of template does not save any memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;typename Type&amp;gt;&lt;br /&gt;
Type max(Type a, Type b) {&lt;br /&gt;
    return a &amp;gt; b ? a : b;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  // This will call max &amp;lt;int&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3, 7) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This will call max&amp;lt;double&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3.0, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This type is ambiguous, so explicitly instantiate max&amp;lt;double&amp;gt;&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max&amp;lt;double&amp;gt;(3, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Class Templates====&lt;br /&gt;
A class template provides a specification for generating classes based on parameters. A class template is instantiated by passing a given set of types to it as template arguments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;class T&amp;gt;&lt;br /&gt;
class mypair {&lt;br /&gt;
    T values [2];&lt;br /&gt;
  public:&lt;br /&gt;
    mypair (T first, T second)&lt;br /&gt;
    {&lt;br /&gt;
      values[0]=first; values[1]=second;&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generic_programming&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generics_in_Java&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.oracle.com/technetwork/articles/javase/generics-136597.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://download.oracle.com/javase/tutorial/extra/generics/methods.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.cplusplus.com/doc/tutorial/templates/&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Template_(programming)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=54898</id>
		<title>CSC/ECE 517 Fall 2011/ch6 6c sj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=54898"/>
		<updated>2011-11-14T03:46:34Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Generic Programming==&lt;br /&gt;
&amp;lt;p&amp;gt;Generic programming is a style of computer programming in which algorithms are written in terms of &amp;lt;i&amp;gt;to-be-specified-later&amp;lt;/i&amp;gt; types that are then instantiated when needed for specific types provided as parameters. This enables writing common set of functions which differ only in the types on which they operate. This reduces duplication. Software entities created using generic programming are known as ''generics'' in [http://en.wikipedia.org/wiki/Ada_(programming_language) Ada], [http://en.wikipedia.org/wiki/Eiffel_(programming_language) Eiffel], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/F_Sharp_(programming_language) F#], and [http://en.wikipedia.org/wiki/Visual_Basic_.NET Visual Basic .NET]; parametric polymorphism in [http://en.wikipedia.org/wiki/ML_(programming_language) ML], [http://en.wikipedia.org/wiki/Scala_(programming_language Scala] and [http://en.wikipedia.org/wiki/Haskell_(programming_language) Haskell], [http://en.wikipedia.org/wiki/template_(programming) template]s in [http://en.wikipedia.org/wiki/C++ C++].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;For example, given various data structures and several algorithms, the brute force way would be implement them for each data structure which would mean that various combinations of implementations will be necessary. Generic programming reduces this effort.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Generics in Java?==&lt;br /&gt;
Generics were added to Java programming language as a part of J2SE 5.0 release in 2004. They allow programmers to develop generic and compile safe applications which enables a type or method to operate on objects of various type. This feature is well utilized while implementing [http://en.wikipedia.org/wiki/Java_Collections Java Collections]. The reason why people went into generic programming can be well explained using the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  List list = new ArrayList();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = (Integer)list.get(0);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
In this example, we insert a &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; into an &amp;lt;code&amp;gt;ArrayList&amp;lt;/code&amp;gt; and retrieve element by typecasting with Integer wrapper class. This throws a runtime exception because of Illegal class cast. But if we use generics, runtime exceptions can be avoided and the compiler will be able to catch such issues which in turn help a programmer to build a bug free code. So if we convert the above code to use generic then it would look like this:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  List&amp;lt;String&amp;gt; list = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = list.get(0); //line 1 &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Here at line 1 the compiler throws an error because the compiler on seeing the declaration of ArrayList will be expecting the list to have just &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; and thereby the return type of &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt; to be &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Implementing Generics:'''&lt;br /&gt;
Java provides a feature which helps one to implement your own generic types and this will help to build more sophisticated and runtime error free applications. Consider the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
   interface List&amp;lt;N&amp;gt; {&lt;br /&gt;
                         void add(N i);&lt;br /&gt;
                         Iterator&amp;lt;N&amp;gt; iterator();&lt;br /&gt;
                      }&lt;br /&gt;
   interface Iterator&amp;lt;N&amp;gt; {&lt;br /&gt;
                            N next();&lt;br /&gt;
                            boolean hasNext();&lt;br /&gt;
                         }&lt;br /&gt;
   class LinkedList&amp;lt;N&amp;gt; implements List&amp;lt;N&amp;gt; {&lt;br /&gt;
                          //Business Logic   &lt;br /&gt;
                 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
So here, &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; can be replaced with any primitive data types or wrapper classes in the business logic. But we need to make sure that placeholders to be replaced with valid subtypes of Object. Generics implementation is not restricted for classes or interfaces, we can have for static/non static methods and constructors.&lt;br /&gt;
&lt;br /&gt;
Example for generic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static &amp;lt;T&amp;gt; void fromArrayToCollection(T[] a, Collection&amp;lt;T&amp;gt; c) {&lt;br /&gt;
    for (T o : a) {&lt;br /&gt;
        c.add(o); // Correct&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Templates in C++==&lt;br /&gt;
===What are templates?===&lt;br /&gt;
&amp;lt;p&amp;gt;Templates are functions that can operate with &amp;lt;i&amp;gt;generic types&amp;lt;/i&amp;gt; which means that the functionality can be adapted for more than one type of data without repeating the entire code for each type. &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
===Overview===&lt;br /&gt;
Templates can be either function templates or class templates.&lt;br /&gt;
====Function Templates====&lt;br /&gt;
These are just like regular functions except that they can have arguments of different types. A single function definition works with different kinds of data types. During compile time, the actual functions are generated once the compiler knows the data type being used. This kind of template does not save any memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
template &amp;lt;typename Type&amp;gt;&lt;br /&gt;
Type max(Type a, Type b) {&lt;br /&gt;
    return a &amp;gt; b ? a : b;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  // This will call max &amp;lt;int&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3, 7) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This will call max&amp;lt;double&amp;gt; (by argument deduction)&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max(3.0, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  // This type is ambiguous, so explicitly instantiate max&amp;lt;double&amp;gt;&lt;br /&gt;
  std::cout &amp;lt;&amp;lt; max&amp;lt;double&amp;gt;(3, 7.0) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Class Templates====&lt;br /&gt;
A class template provides a specification for generating classes based on parameters. A class template is instantiated by passing a given set of types to it as template arguments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
template &amp;lt;class T&amp;gt;&lt;br /&gt;
class mypair {&lt;br /&gt;
    T values [2];&lt;br /&gt;
  public:&lt;br /&gt;
    mypair (T first, T second)&lt;br /&gt;
    {&lt;br /&gt;
      values[0]=first; values[1]=second;&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generic_programming&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generics_in_Java&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.oracle.com/technetwork/articles/javase/generics-136597.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://download.oracle.com/javase/tutorial/extra/generics/methods.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.cplusplus.com/doc/tutorial/templates/&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Template_(programming)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=54897</id>
		<title>CSC/ECE 517 Fall 2011/ch6 6c sj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=54897"/>
		<updated>2011-11-14T03:33:39Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Generic Programming==&lt;br /&gt;
&amp;lt;p&amp;gt;Generic programming is a style of computer programming in which algorithms are written in terms of &amp;lt;i&amp;gt;to-be-specified-later&amp;lt;/i&amp;gt; types that are then instantiated when needed for specific types provided as parameters. This enables writing common set of functions which differ only in the types on which they operate. This reduces duplication. Software entities created using generic programming are known as ''generics'' in [http://en.wikipedia.org/wiki/Ada_(programming_language) Ada], [http://en.wikipedia.org/wiki/Eiffel_(programming_language) Eiffel], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/F_Sharp_(programming_language) F#], and [http://en.wikipedia.org/wiki/Visual_Basic_.NET Visual Basic .NET]; parametric polymorphism in [http://en.wikipedia.org/wiki/ML_(programming_language) ML], [http://en.wikipedia.org/wiki/Scala_(programming_language Scala] and [http://en.wikipedia.org/wiki/Haskell_(programming_language) Haskell], [http://en.wikipedia.org/wiki/template_(programming) template]s in [http://en.wikipedia.org/wiki/C++ C++].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;For example, given various data structures and several algorithms, the brute force way would be implement them for each data structure which would mean that various combinations of implementations will be necessary. Generic programming reduces this effort.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Generics in Java?==&lt;br /&gt;
Generics were added to Java programming language as a part of J2SE 5.0 release in 2004. They allow programmers to develop generic and compile safe applications which enables a type or method to operate on objects of various type. This feature is well utilized while implementing [http://en.wikipedia.org/wiki/Java_Collections Java Collections]. The reason why people went into generic programming can be well explained using the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  List list = new ArrayList();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = (Integer)list.get(0);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
In this example, we insert a &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; into an &amp;lt;code&amp;gt;ArrayList&amp;lt;/code&amp;gt; and retrieve element by typecasting with Integer wrapper class. This throws a runtime exception because of Illegal class cast. But if we use generics, runtime exceptions can be avoided and the compiler will be able to catch such issues which in turn help a programmer to build a bug free code. So if we convert the above code to use generic then it would look like this:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  List&amp;lt;String&amp;gt; list = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = list.get(0); //line 1 &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Here at line 1 the compiler throws an error because the compiler on seeing the declaration of ArrayList will be expecting the list to have just &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; and thereby the return type of &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt; to be &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Implementing Generics:'''&lt;br /&gt;
Java provides a feature which helps one to implement your own generic types and this will help to build more sophisticated and runtime error free applications. Consider the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
   interface List&amp;lt;N&amp;gt; {&lt;br /&gt;
                         void add(N i);&lt;br /&gt;
                         Iterator&amp;lt;N&amp;gt; iterator();&lt;br /&gt;
                      }&lt;br /&gt;
   interface Iterator&amp;lt;N&amp;gt; {&lt;br /&gt;
                            N next();&lt;br /&gt;
                            boolean hasNext();&lt;br /&gt;
                         }&lt;br /&gt;
   class LinkedList&amp;lt;N&amp;gt; implements List&amp;lt;N&amp;gt; {&lt;br /&gt;
                          //Business Logic   &lt;br /&gt;
                 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
So here, &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; can be replaced with any primitive data types or wrapper classes in the business logic. But we need to make sure that placeholders to be replaced with valid subtypes of Object. Generics implementation is not restricted for classes or interfaces, we can have for static/non static methods and constructors.&lt;br /&gt;
&lt;br /&gt;
Example for generic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static &amp;lt;T&amp;gt; void fromArrayToCollection(T[] a, Collection&amp;lt;T&amp;gt; c) {&lt;br /&gt;
    for (T o : a) {&lt;br /&gt;
        c.add(o); // Correct&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Templates in C++==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generic_programming&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://en.wikipedia.org/wiki/Generics_in_Java&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.oracle.com/technetwork/articles/javase/generics-136597.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://download.oracle.com/javase/tutorial/extra/generics/methods.html&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=54896</id>
		<title>CSC/ECE 517 Fall 2011/ch6 6c sj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch6_6c_sj&amp;diff=54896"/>
		<updated>2011-11-14T03:30:54Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Generic Programming==&lt;br /&gt;
&amp;lt;p&amp;gt;Generic programming is a style of computer programming in which algorithms are written in terms of &amp;lt;i&amp;gt;to-be-specified-later&amp;lt;/i&amp;gt; types that are then instantiated when needed for specific types provided as parameters. This enables writing common set of functions which differ only in the types on which they operate. This reduces duplication. Software entities created using generic programming are known as ''generics'' in [http://en.wikipedia.org/wiki/Ada_(programming_language) Ada], [http://en.wikipedia.org/wiki/Eiffel_(programming_language) Eiffel], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/F_Sharp_(programming_language) F#], and [http://en.wikipedia.org/wiki/Visual_Basic_.NET Visual Basic .NET]; parametric polymorphism in [http://en.wikipedia.org/wiki/ML_(programming_language) ML], [http://en.wikipedia.org/wiki/Scala_(programming_language Scala] and [http://en.wikipedia.org/wiki/Haskell_(programming_language) Haskell], [http://en.wikipedia.org/wiki/template_(programming) template]s in [http://en.wikipedia.org/wiki/C++ C++].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;For example, given various data structures and several algorithms, the brute force way would be implement them for each data structure which would mean that various combinations of implementations will be necessary. Generic programming reduces this effort.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==What are Generics in Java?==&lt;br /&gt;
Generics were added to Java programming language as a part of J2SE 5.0 release in 2004. They allow programmers to develop generic and compile safe applications which enables a type or method to operate on objects of various type. This feature is well utilized while implementing [http://en.wikipedia.org/wiki/Java_Collections Java Collections]. The reason why people went into generic programming can be well explained using the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  List list = new ArrayList();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = (Integer)list.get(0);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
In this example, we insert a &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; into an &amp;lt;code&amp;gt;ArrayList&amp;lt;/code&amp;gt; and retrieve element by typecasting with Integer wrapper class. This throws a runtime exception because of Illegal class cast. But if we use generics, runtime exceptions can be avoided and the compiler will be able to catch such issues which in turn help a programmer to build a bug free code. So if we convert the above code to use generic then it would look like this:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  List&amp;lt;String&amp;gt; list = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
  list.add(&amp;quot;name&amp;quot;);&lt;br /&gt;
  Integer num = list.get(0); //line 1 &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Here at line 1 the compiler throws an error because the compiler on seeing the declaration of ArrayList will be expecting the list to have just &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt; and thereby the return type of &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt; to be &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Implementing Generics:'''&lt;br /&gt;
Java provides a feature which helps one to implement your own generic types and this will help to build more sophisticated and runtime error free applications. Consider the below example:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
   interface List&amp;lt;N&amp;gt; {&lt;br /&gt;
                         void add(N i);&lt;br /&gt;
                         Iterator&amp;lt;N&amp;gt; iterator();&lt;br /&gt;
                      }&lt;br /&gt;
   interface Iterator&amp;lt;N&amp;gt; {&lt;br /&gt;
                            N next();&lt;br /&gt;
                            boolean hasNext();&lt;br /&gt;
                         }&lt;br /&gt;
   class LinkedList&amp;lt;N&amp;gt; implements List&amp;lt;N&amp;gt; {&lt;br /&gt;
                          //Business Logic   &lt;br /&gt;
                 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
So here, &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; can be replaced with any primitive data types or wrapper classes in the business logic. But we need to make sure that placeholders to be replaced with valid subtypes of Object. Generics implementation is not restricted for classes or interfaces, we can have for static/non static methods and constructors.&lt;br /&gt;
&lt;br /&gt;
Example for generic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static &amp;lt;T&amp;gt; void fromArrayToCollection(T[] a, Collection&amp;lt;T&amp;gt; c) {&lt;br /&gt;
    for (T o : a) {&lt;br /&gt;
        c.add(o); // Correct&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Generics_in_Java&lt;br /&gt;
&lt;br /&gt;
2. http://www.oracle.com/technetwork/articles/javase/generics-136597.html&lt;br /&gt;
&lt;br /&gt;
3. http://download.oracle.com/javase/tutorial/extra/generics/methods.html&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=51153</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=51153"/>
		<updated>2011-09-26T02:52:40Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. An object-oriented program may be viewed as a collection of interacting [http://en.wikipedia.org/wiki/Object_(computer_science)/ objects], as opposed to the conventional model, in which a program is seen as a list of tasks (subroutines) to perform. In OOP, each object is capable of receiving messages, processing data, and sending messages to other objects. Each object can be viewed as an independent &amp;quot;machine&amp;quot; with a distinct role or responsibility. The actions (or &amp;quot;methods&amp;quot;) on these objects are closely associated with the object. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Objects form the basis of OOP. Every Object wraps the data within a set of functions which helps to handle different appropriately. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;[http://en.wikipedia.org/wiki/Attribute_(computing)/ attributes]&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;[http://en.wikipedia.org/wiki/Method_(computer_programming)/ methods]&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
&amp;lt;p&amp;gt;A running debate in O-O languages is whether method calls and instance-variable references should have the same syntax. Different programming languages implement this in different ways. Let's look at them by examples.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Ruby use the same syntax for method calls and variable references. There is no distinction between these. We can see this in the example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song&lt;br /&gt;
  def duration=(newDuration)&lt;br /&gt;
    @duration = newDuration&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
aSong = Song.new(&amp;quot;Bicylops&amp;quot;, &amp;quot;Fleck&amp;quot;, 260)&lt;br /&gt;
aSong.duration	»	260&lt;br /&gt;
aSong.duration = 257   # set attribute with updated value&lt;br /&gt;
aSong.duration	»	257&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it simpler for the programmer to code. Also, it presents uniformity in the code.&lt;br /&gt;
&lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Java employ different syntax for method calls and variable references as seen in this example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song{&lt;br /&gt;
	int duration;&lt;br /&gt;
	Song(){}&lt;br /&gt;
	void setDuration(int dur){&lt;br /&gt;
		duration = dur;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Song sng = new Song();&lt;br /&gt;
sng.setDuration(260);&lt;br /&gt;
System.out.println(&amp;quot;Song duration = &amp;quot;+sng.duration);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As seen above, a method is always called using parenthesis, within which arguments may be included if required. However, instance variable is accessed directly.&lt;br /&gt;
&lt;br /&gt;
== Getters and Setters and their Advantages ==&lt;br /&gt;
&amp;lt;p&amp;gt;One of the principles of Objected Oriented Design is that an object's implementation should not be exposed to other classes. This is to avoid difficulty in maintenance. [http://en.wikipedia.org/wiki/Mutator_method/ Getters and Setters] provide a way to read or write private data of a class for any kind of manipulation. They also provide for easy maintenance, in that, if any change needs to be made in the way the variable is set, only the setter method needs to be changed rather than looking for it and changing in every place. These methods also improve the code readability and bring about uniformity across the code.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;br /&gt;
&amp;lt;p&amp;gt;The usage syntax of methods, instance variables, getters and setters is in the table below&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;table border = 1&amp;gt;&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Programming Languages&lt;br /&gt;
!Method call&lt;br /&gt;
!Fields/Attributes&lt;br /&gt;
!Getter / Setter&lt;br /&gt;
!Comparison&lt;br /&gt;
|-&lt;br /&gt;
|ABAP (Advanced Business Application Programming)&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
CALL METHOD &amp;lt;meth&amp;gt; EXPORTING... &amp;lt;ii&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   IMPORTING... &amp;lt;ei&amp;gt; =.&amp;lt;g i&amp;gt;... &lt;br /&gt;
                   CHANGING ... &amp;lt;ci&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   RECEIVING         r = h &lt;br /&gt;
                   EXCEPTIONS... &amp;lt;ei&amp;gt; = rc i...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;data&amp;lt;/b&amp;gt; field &amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt; type&lt;br /&gt;
|Same as other methods with the only difference that they start with SET or GET&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|C++&lt;br /&gt;
|ObjectName.MethodName(parameters) &lt;br /&gt;
|Same as methods. Example below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int getHealth() const { return health; }&lt;br /&gt;
void setHealth(int h) { health = h; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|C#&lt;br /&gt;
|ObjectName.MethodName(parameters) &lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|They are just like methods. Example below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public string GetName()&lt;br /&gt;
    {&lt;br /&gt;
        return m_name;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void SetName(string name)&lt;br /&gt;
    {&lt;br /&gt;
        m_name = name;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|Java&lt;br /&gt;
|ObjectName.MethodName(parameters) [Eg: x.method()]&lt;br /&gt;
|ObjectName.Attribute [Eg: x.field]&lt;br /&gt;
|They are nothing but method calls&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|D&lt;br /&gt;
|ObjectName.MethodName(parameters)&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|No need for getters and setters.  It can be directly accessed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import std.stdio;&lt;br /&gt;
&lt;br /&gt;
class Car&lt;br /&gt;
{&lt;br /&gt;
    float speed = 1.0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void main(){&lt;br /&gt;
    auto my_car = new Car();&lt;br /&gt;
    my_car.speed = 2.5;&lt;br /&gt;
    writefln(my_car.speed);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax used for method calls and variable references is different&lt;br /&gt;
|-&lt;br /&gt;
|Objective C&lt;br /&gt;
|output = [object methodWithOutput]&lt;br /&gt;
|ObjectName-&amp;gt;Attribute&lt;br /&gt;
|An example of getter is below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#import &amp;lt;Cocoa/Cocoa.h&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
@interface Photo : NSObject {&lt;br /&gt;
    NSString* caption;&lt;br /&gt;
    NSString* photographer;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
- (NSString*) caption;&lt;br /&gt;
- (NSString*) photographer;&lt;br /&gt;
&lt;br /&gt;
@end        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
An example of setter is below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#import &amp;lt;Cocoa/Cocoa.h&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
@interface Photo : NSObject {&lt;br /&gt;
    NSString* caption;&lt;br /&gt;
    NSString* photographer;&lt;br /&gt;
}&lt;br /&gt;
- (NSString*) caption;&lt;br /&gt;
- (NSString*) photographer;&lt;br /&gt;
&lt;br /&gt;
- (void) setCaption: (NSString*)input;&lt;br /&gt;
- (void) setPhotographer: (NSString*)input;&lt;br /&gt;
&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax used for method calls and variable references is different&lt;br /&gt;
|-&lt;br /&gt;
|Python&lt;br /&gt;
|ObjectName.MethodName(parameters)&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|Pythonic way of implementing getters and setters is to using public members and turning them into properties when needed&lt;br /&gt;
|Syntax used for method calls and variable references is sometimes the same and different at times (when there are arguments)&lt;br /&gt;
|-&lt;br /&gt;
|Javascript&lt;br /&gt;
|ObjectName.MethodName(Parameters);&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
var lost = {&lt;br /&gt;
	loc : &amp;quot;Island&amp;quot;,&lt;br /&gt;
	get location () {&lt;br /&gt;
		return this.loc;&lt;br /&gt;
	},&lt;br /&gt;
	set location(val) {&lt;br /&gt;
		this.loc = val;&lt;br /&gt;
	}&lt;br /&gt;
};&lt;br /&gt;
lost.location = &amp;quot;Another island&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|PHP&lt;br /&gt;
|$ObjectName-&amp;gt;MethodName(Parameters);&lt;br /&gt;
|$ObjectName-&amp;gt;Attribute&lt;br /&gt;
|N/A. Attributes can be accessed directly.&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|VB.NET&lt;br /&gt;
|ObjectName.MethodName(Parameters);&lt;br /&gt;
ObjectNmae.MethodName&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
Public Property myProperty As String&lt;br /&gt;
    Get&lt;br /&gt;
        Return String.Empty&lt;br /&gt;
    End Get&lt;br /&gt;
    Private Set(ByVal value As String)&lt;br /&gt;
        somethingElse = value&lt;br /&gt;
    End Set&lt;br /&gt;
End Property&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax may be same for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|Ruby&lt;br /&gt;
|$ObjectName-&amp;gt;MethodName(Parameters);&lt;br /&gt;
|$ObjectName-&amp;gt;Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
class Message&lt;br /&gt;
  attr_reader :message&lt;br /&gt;
  def message=(m)&lt;br /&gt;
    @message = m.dup&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Message&lt;br /&gt;
  attr_writer :message&lt;br /&gt;
  def message&lt;br /&gt;
    @message.encode!(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is same for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|Lua&lt;br /&gt;
|ObjectName.MethodName(Parameters);&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  local index = getters and&lt;br /&gt;
    function(self, key)&lt;br /&gt;
      -- read from getter, else from fallback&lt;br /&gt;
      local func = getters[key]&lt;br /&gt;
      if func then return func(self) else return fallback[key] end&lt;br /&gt;
    end&lt;br /&gt;
    or fallback  -- default to fast property reads through table&lt;br /&gt;
  local newindex = setters and&lt;br /&gt;
    function(self, key, value)&lt;br /&gt;
      -- write to setter, else to proxy&lt;br /&gt;
      local func = setters[key]&lt;br /&gt;
      if func then func(self, value)&lt;br /&gt;
      else rawset(self, key, value) end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|Perl&lt;br /&gt;
|$ObjectName-&amp;gt;MethodName(Parameters);&lt;br /&gt;
|$ObjectName-&amp;gt;Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
BEGIN {&lt;br /&gt;
    my @attr = qw(author title number);&lt;br /&gt;
    no strict 'refs';&lt;br /&gt;
    for my $a (@attr){&lt;br /&gt;
        *{__PACKAGE__ . &amp;quot;::get_$a&amp;quot;} = sub { $_[0]-&amp;gt;{$a}         };&lt;br /&gt;
        *{__PACKAGE__ . &amp;quot;::set_$a&amp;quot;} = sub { $_[0]-&amp;gt;{$a} = $_[1] };&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Having getters and setters in the implementation has its own advantages and disadvantages. The advantages are that&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They provide [http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming)/ data encapsulation].&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They improve the code readability.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Changes can be made only to the implementation without making changes to the code that uses the object.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
Using getters and setters also has a disadvantage. They largely provide access to implementation details. But this could hinder &amp;lt;i&amp;gt;[http://en.wikipedia.org/wiki/Abstraction_(computer_science)/ data abstraction&amp;lt;/i&amp;gt;, i.e. hiding the object's implementation of a message handler. Consider a getter function that returns a number. Wherever this method is called, the variable which holds the return value must match the return type of this function. Now if we change they way this method is implemented by changing the return type, then there could be trouble.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Therefore it is important to design such that there is minimal data movement thereby minimizing possible errors.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Using the same syntax for method calls and instance variable references have some advantages and disadvantages. One could argue that having the same syntax makes it simpler for the programmer. It makes the code lighter in terms of lines of code, thus avoiding bulky code. However, including distinct ways for using methods and variables enhances readability by enabling better understanding. This is possible because the manipulation is visible whereas if the syntax were the same(i.e. compact), the one reading has no idea about what is happening &amp;quot;under the hood&amp;quot;.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(object-oriented_programming)/ Comparison of Programming Languages]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://forums.sdn.sap.com/thread.jspa?threadID=529448&amp;amp;tstart=6135/ Setters and Getters in ABAP]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html?page=1/ Why getters and setters are evil?]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.zeuscmd.com/tutorials/cplusplus/50-GettersAndSetters.php/ Getters and Setters]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://cocoadevcentral.com/d/learn_objectivec/ Objective C]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html/ Ruby Classes- Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.vbtutor.in/getting-started-with-visual-basic-net/object-oriented-programming-in-vbnet/ VB.Net Object oriented programming]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[https://developer.mozilla.org/en/Introduction_to_Object-Oriented_JavaScript/ Javascript - Functions/Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.massassi.com/php/articles/classes/ PHP - Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorialspoint.com/perl/perl_oo_perl.htm/ Perl - Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=51110</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=51110"/>
		<updated>2011-09-26T02:08:13Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. An object-oriented program may be viewed as a collection of interacting objects, as opposed to the conventional model, in which a program is seen as a list of tasks (subroutines) to perform. In OOP, each object is capable of receiving messages, processing data, and sending messages to other objects. Each object can be viewed as an independent &amp;quot;machine&amp;quot; with a distinct role or responsibility. The actions (or &amp;quot;methods&amp;quot;) on these objects are closely associated with the object. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Objects form the basis of OOP. Every Object wraps the data within a set of functions which helps to handle different appropriately. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
&amp;lt;p&amp;gt;A running debate in O-O languages is whether method calls and instance-variable references should have the same syntax. Different programming languages implement this in different ways. Let's look at them by examples.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Ruby use the same syntax for method calls and variable references. There is no distinction between these. We can see this in the example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song&lt;br /&gt;
  def duration=(newDuration)&lt;br /&gt;
    @duration = newDuration&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
aSong = Song.new(&amp;quot;Bicylops&amp;quot;, &amp;quot;Fleck&amp;quot;, 260)&lt;br /&gt;
aSong.duration	»	260&lt;br /&gt;
aSong.duration = 257   # set attribute with updated value&lt;br /&gt;
aSong.duration	»	257&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it simpler for the programmer to code. Also, it presents uniformity in the code.&lt;br /&gt;
&lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Java employ different syntax for method calls and variable references as seen in this example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song{&lt;br /&gt;
	int duration;&lt;br /&gt;
	Song(){}&lt;br /&gt;
	void setDuration(int dur){&lt;br /&gt;
		duration = dur;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Song sng = new Song();&lt;br /&gt;
sng.setDuration(260);&lt;br /&gt;
System.out.println(&amp;quot;Song duration = &amp;quot;+sng.duration);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As seen above, a method is always called using parenthesis, within which arguments may be included if required. However, instance variable is accessed directly.&lt;br /&gt;
&lt;br /&gt;
== Getters and Setters and their Advantages ==&lt;br /&gt;
&amp;lt;p&amp;gt;One of the principles of Objected Oriented Design is that an object's implementation should not be exposed to other classes. This is to avoid difficulty in maintenance. Getters and setters provide a way to read or write private data of a class for any kind of manipulation. They also provide for easy maintenance, in that, if any change needs to be made in the way the variable is set, only the setter method needs to be changed rather than looking for it and changing in every place. These methods also improve the code readability and bring about uniformity across the code.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;br /&gt;
&amp;lt;p&amp;gt;The usage syntax of methods, instance variables, getters and setters is in the table below&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;table border = 1&amp;gt;&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Programming Languages&lt;br /&gt;
!Method call&lt;br /&gt;
!Fields/Attributes&lt;br /&gt;
!Getter / Setter&lt;br /&gt;
!Comparison&lt;br /&gt;
|-&lt;br /&gt;
|ABAP (Advanced Business Application Programming)&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
CALL METHOD &amp;lt;meth&amp;gt; EXPORTING... &amp;lt;ii&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   IMPORTING... &amp;lt;ei&amp;gt; =.&amp;lt;g i&amp;gt;... &lt;br /&gt;
                   CHANGING ... &amp;lt;ci&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   RECEIVING         r = h &lt;br /&gt;
                   EXCEPTIONS... &amp;lt;ei&amp;gt; = rc i...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;data&amp;lt;/b&amp;gt; field &amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt; type&lt;br /&gt;
|Same as other methods with the only difference that they start with SET or GET&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|C++&lt;br /&gt;
|ObjectName.MethodName(parameters) &lt;br /&gt;
|Same as methods. Example below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int getHealth() const { return health; }&lt;br /&gt;
void setHealth(int h) { health = h; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|C#&lt;br /&gt;
|ObjectName.MethodName(parameters) &lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|They are just like methods. Example below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public string GetName()&lt;br /&gt;
    {&lt;br /&gt;
        return m_name;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void SetName(string name)&lt;br /&gt;
    {&lt;br /&gt;
        m_name = name;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|Java&lt;br /&gt;
|ObjectName.MethodName(parameters) [Eg: x.method()]&lt;br /&gt;
|ObjectName.Attribute [Eg: x.field]&lt;br /&gt;
|They are nothing but method calls&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|D&lt;br /&gt;
|ObjectName.MethodName(parameters)&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|No need for getters and setters.  It can be directly accessed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import std.stdio;&lt;br /&gt;
&lt;br /&gt;
class Car&lt;br /&gt;
{&lt;br /&gt;
    float speed = 1.0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void main(){&lt;br /&gt;
    auto my_car = new Car();&lt;br /&gt;
    my_car.speed = 2.5;&lt;br /&gt;
    writefln(my_car.speed);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax used for method calls and variable references is different&lt;br /&gt;
|-&lt;br /&gt;
|Objective C&lt;br /&gt;
|output = [object methodWithOutput]&lt;br /&gt;
|ObjectName-&amp;gt;Attribute&lt;br /&gt;
|An example of getter is below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#import &amp;lt;Cocoa/Cocoa.h&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
@interface Photo : NSObject {&lt;br /&gt;
    NSString* caption;&lt;br /&gt;
    NSString* photographer;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
- (NSString*) caption;&lt;br /&gt;
- (NSString*) photographer;&lt;br /&gt;
&lt;br /&gt;
@end        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
An example of setter is below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#import &amp;lt;Cocoa/Cocoa.h&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
@interface Photo : NSObject {&lt;br /&gt;
    NSString* caption;&lt;br /&gt;
    NSString* photographer;&lt;br /&gt;
}&lt;br /&gt;
- (NSString*) caption;&lt;br /&gt;
- (NSString*) photographer;&lt;br /&gt;
&lt;br /&gt;
- (void) setCaption: (NSString*)input;&lt;br /&gt;
- (void) setPhotographer: (NSString*)input;&lt;br /&gt;
&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax used for method calls and variable references is different&lt;br /&gt;
|-&lt;br /&gt;
|Python&lt;br /&gt;
|ObjectName.MethodName(parameters)&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|Pythonic way of implementing getters and setters is to using public members and turning them into properties when needed&lt;br /&gt;
|Syntax used for method calls and variable references is sometimes the same and different at times (when there are arguments)&lt;br /&gt;
|-&lt;br /&gt;
|Javascript&lt;br /&gt;
|ObjectName.MethodName(Parameters);&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
var lost = {&lt;br /&gt;
	loc : &amp;quot;Island&amp;quot;,&lt;br /&gt;
	get location () {&lt;br /&gt;
		return this.loc;&lt;br /&gt;
	},&lt;br /&gt;
	set location(val) {&lt;br /&gt;
		this.loc = val;&lt;br /&gt;
	}&lt;br /&gt;
};&lt;br /&gt;
lost.location = &amp;quot;Another island&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|PHP&lt;br /&gt;
|$ObjectName-&amp;gt;MethodName(Parameters);&lt;br /&gt;
|$ObjectName-&amp;gt;Attribute&lt;br /&gt;
|N/A. Attributes can be accessed directly.&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|VB.NET&lt;br /&gt;
|ObjectName.MethodName(Parameters);&lt;br /&gt;
ObjectNmae.MethodName&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
Public Property myProperty As String&lt;br /&gt;
    Get&lt;br /&gt;
        Return String.Empty&lt;br /&gt;
    End Get&lt;br /&gt;
    Private Set(ByVal value As String)&lt;br /&gt;
        somethingElse = value&lt;br /&gt;
    End Set&lt;br /&gt;
End Property&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax may be same for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|Ruby&lt;br /&gt;
|$ObjectName-&amp;gt;MethodName(Parameters);&lt;br /&gt;
|$ObjectName-&amp;gt;Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
class Message&lt;br /&gt;
  attr_reader :message&lt;br /&gt;
  def message=(m)&lt;br /&gt;
    @message = m.dup&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Message&lt;br /&gt;
  attr_writer :message&lt;br /&gt;
  def message&lt;br /&gt;
    @message.encode!(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is same for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|Lua&lt;br /&gt;
|ObjectName.MethodName(Parameters);&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  local index = getters and&lt;br /&gt;
    function(self, key)&lt;br /&gt;
      -- read from getter, else from fallback&lt;br /&gt;
      local func = getters[key]&lt;br /&gt;
      if func then return func(self) else return fallback[key] end&lt;br /&gt;
    end&lt;br /&gt;
    or fallback  -- default to fast property reads through table&lt;br /&gt;
  local newindex = setters and&lt;br /&gt;
    function(self, key, value)&lt;br /&gt;
      -- write to setter, else to proxy&lt;br /&gt;
      local func = setters[key]&lt;br /&gt;
      if func then func(self, value)&lt;br /&gt;
      else rawset(self, key, value) end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|Perl&lt;br /&gt;
|$ObjectName-&amp;gt;MethodName(Parameters);&lt;br /&gt;
|$ObjectName-&amp;gt;Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
BEGIN {&lt;br /&gt;
    my @attr = qw(author title number);&lt;br /&gt;
    no strict 'refs';&lt;br /&gt;
    for my $a (@attr){&lt;br /&gt;
        *{__PACKAGE__ . &amp;quot;::get_$a&amp;quot;} = sub { $_[0]-&amp;gt;{$a}         };&lt;br /&gt;
        *{__PACKAGE__ . &amp;quot;::set_$a&amp;quot;} = sub { $_[0]-&amp;gt;{$a} = $_[1] };&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Having getters and setters in the implementation has its own advantages and disadvantages. The advantages are that&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They provide data encapsulation.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They improve the code readability.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Changes can be made only to the implementation without making changes to the code that uses the object.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
Using getters and setters also has a disadvantage. They largely provide access to implementation details. But this could hinder &amp;lt;i&amp;gt;data abstraction&amp;lt;/i&amp;gt;, i.e. hiding the object's implementation of a message handler. Consider a getter function that returns a number. Wherever this method is called, the variable which holds the return value must match the return type of this function. Now if we change they way this method is implemented by changing the return type, then there could be trouble.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Therefore it is important to design such that there is minimal data movement thereby minimizing possible errors.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Using the same syntax for method calls and instance variable references have some advantages and disadvantages. One could argue that having the same syntax makes it simpler for the programmer. It makes the code lighter in terms of lines of code, thus avoiding bulky code. However, including distinct ways for using methods and variables enhances readability by enabling better understanding. This is possible because the manipulation is visible whereas if the syntax were the same(i.e. compact), the one reading has no idea about what is happening &amp;quot;under the hood&amp;quot;.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(object-oriented_programming)/ Comparison of Programming Languages]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://forums.sdn.sap.com/thread.jspa?threadID=529448&amp;amp;tstart=6135/ Setters and Getters in ABAP]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html?page=1/ Why getters and setters are evil?]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.zeuscmd.com/tutorials/cplusplus/50-GettersAndSetters.php/ Getters and Setters]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://cocoadevcentral.com/d/learn_objectivec/ Objective C]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html/ Ruby Classes- Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.vbtutor.in/getting-started-with-visual-basic-net/object-oriented-programming-in-vbnet/ VB.Net Object oriented programming]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[https://developer.mozilla.org/en/Introduction_to_Object-Oriented_JavaScript/ Javascript - Functions/Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.massassi.com/php/articles/classes/ PHP - Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorialspoint.com/perl/perl_oo_perl.htm/ Perl - Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=50585</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=50585"/>
		<updated>2011-09-25T17:11:15Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
&amp;lt;p&amp;gt;A running debate in O-O languages is whether method calls and instance-variable references should have the same syntax. Different programming languages implement this in different ways. Let's look at them by examples.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Ruby use the same syntax for method calls and variable references. There is no distinction between these. We can see this in the example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song&lt;br /&gt;
  def duration=(newDuration)&lt;br /&gt;
    @duration = newDuration&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
aSong = Song.new(&amp;quot;Bicylops&amp;quot;, &amp;quot;Fleck&amp;quot;, 260)&lt;br /&gt;
aSong.duration	»	260&lt;br /&gt;
aSong.duration = 257   # set attribute with updated value&lt;br /&gt;
aSong.duration	»	257&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it simpler for the programmer to code. Also, it presents uniformity in the code.&lt;br /&gt;
&lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Java employ different syntax for method calls and variable references as seen in this example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song{&lt;br /&gt;
	int duration;&lt;br /&gt;
	Song(){}&lt;br /&gt;
	void setDuration(int dur){&lt;br /&gt;
		duration = dur;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Song sng = new Song();&lt;br /&gt;
sng.setDuration(260);&lt;br /&gt;
System.out.println(&amp;quot;Song duration = &amp;quot;+sng.duration);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As seen above, a method is always called using parenthesis, within which arguments may be included if required. However, instance variable is accessed directly.&lt;br /&gt;
&lt;br /&gt;
== Getters and Setters and their Advantages ==&lt;br /&gt;
&amp;lt;p&amp;gt;One of the principles of Objected Oriented Design is that an object's implementation should not be exposed to other classes. This is to avoid difficulty in maintenance. Getters and setters provide a way to read or write private data of a class for any kind of manipulation. They also provide for easy maintenance, in that, if any change needs to be made in the way the variable is set, only the setter method needs to be changed rather than looking for it and changing in every place. These methods also improve the code readability and bring about uniformity across the code.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;br /&gt;
&amp;lt;p&amp;gt;The usage syntax of methods, instance variables, getters and setters is in the table below&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Programming Languages&lt;br /&gt;
!Method call&lt;br /&gt;
!Fields/Attributes&lt;br /&gt;
!Getter / Setter&lt;br /&gt;
!Comparison&lt;br /&gt;
|-&lt;br /&gt;
|ABAP (Advanced Business Application Programming)&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
CALL METHOD &amp;lt;meth&amp;gt; EXPORTING... &amp;lt;ii&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   IMPORTING... &amp;lt;ei&amp;gt; =.&amp;lt;g i&amp;gt;... &lt;br /&gt;
                   CHANGING ... &amp;lt;ci&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   RECEIVING         r = h &lt;br /&gt;
                   EXCEPTIONS... &amp;lt;ei&amp;gt; = rc i...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;data&amp;lt;/b&amp;gt; field &amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt; type&lt;br /&gt;
|Same as other methods with the only difference that they start with SET or GET&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|C++&lt;br /&gt;
|ObjectName.MethodName(parameters) &lt;br /&gt;
|Same as methods. Example below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int getHealth() const { return health; }&lt;br /&gt;
void setHealth(int h) { health = h; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|C#&lt;br /&gt;
|ObjectName.MethodName(parameters) &lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|They are just like methods. Example below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public string GetName()&lt;br /&gt;
    {&lt;br /&gt;
        return m_name;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void SetName(string name)&lt;br /&gt;
    {&lt;br /&gt;
        m_name = name;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|Java&lt;br /&gt;
|ObjectName.MethodName(parameters) [Eg: x.method()]&lt;br /&gt;
|ObjectName.Attribute [Eg: x.field]&lt;br /&gt;
|They are nothing but method calls&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|D&lt;br /&gt;
|ObjectName.MethodName(parameters)&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|No need for getters and setters.  It can be directly accessed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import std.stdio;&lt;br /&gt;
&lt;br /&gt;
class Car&lt;br /&gt;
{&lt;br /&gt;
    float speed = 1.0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void main(){&lt;br /&gt;
    auto my_car = new Car();&lt;br /&gt;
    my_car.speed = 2.5;&lt;br /&gt;
    writefln(my_car.speed);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax used for method calls and variable references is different&lt;br /&gt;
|-&lt;br /&gt;
|Objective C&lt;br /&gt;
|output = [object methodWithOutput]&lt;br /&gt;
|ObjectName-&amp;gt;Attribute&lt;br /&gt;
|An example of getter is below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#import &amp;lt;Cocoa/Cocoa.h&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
@interface Photo : NSObject {&lt;br /&gt;
    NSString* caption;&lt;br /&gt;
    NSString* photographer;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
- (NSString*) caption;&lt;br /&gt;
- (NSString*) photographer;&lt;br /&gt;
&lt;br /&gt;
@end        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
An example of setter is below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#import &amp;lt;Cocoa/Cocoa.h&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
@interface Photo : NSObject {&lt;br /&gt;
    NSString* caption;&lt;br /&gt;
    NSString* photographer;&lt;br /&gt;
}&lt;br /&gt;
- (NSString*) caption;&lt;br /&gt;
- (NSString*) photographer;&lt;br /&gt;
&lt;br /&gt;
- (void) setCaption: (NSString*)input;&lt;br /&gt;
- (void) setPhotographer: (NSString*)input;&lt;br /&gt;
&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax used for method calls and variable references is different&lt;br /&gt;
|-&lt;br /&gt;
|Python&lt;br /&gt;
|ObjectName.MethodName(parameters)&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|Pythonic way of implementing getters and setters is to using public members and turning them into properties when needed&lt;br /&gt;
|Syntax used for method calls and variable references is sometimes the same and different at times (when there are arguments)&lt;br /&gt;
|-&lt;br /&gt;
|Javascript&lt;br /&gt;
|ObjectName.MethodName(Parameters);&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
var lost = {&lt;br /&gt;
	loc : &amp;quot;Island&amp;quot;,&lt;br /&gt;
	get location () {&lt;br /&gt;
		return this.loc;&lt;br /&gt;
	},&lt;br /&gt;
	set location(val) {&lt;br /&gt;
		this.loc = val;&lt;br /&gt;
	}&lt;br /&gt;
};&lt;br /&gt;
lost.location = &amp;quot;Another island&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|PHP&lt;br /&gt;
|$ObjectName-&amp;gt;MethodName(Parameters);&lt;br /&gt;
|$ObjectName-&amp;gt;Attribute&lt;br /&gt;
|N/A. Attributes can be accessed directly.&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|VB.NET&lt;br /&gt;
|ObjectName.MethodName(Parameters);&lt;br /&gt;
ObjectNmae.MethodName&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
Public Property myProperty As String&lt;br /&gt;
    Get&lt;br /&gt;
        Return String.Empty&lt;br /&gt;
    End Get&lt;br /&gt;
    Private Set(ByVal value As String)&lt;br /&gt;
        somethingElse = value&lt;br /&gt;
    End Set&lt;br /&gt;
End Property&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax may be same for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|Ruby&lt;br /&gt;
|$ObjectName-&amp;gt;MethodName(Parameters);&lt;br /&gt;
|$ObjectName-&amp;gt;Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
class Message&lt;br /&gt;
  attr_reader :message&lt;br /&gt;
  def message=(m)&lt;br /&gt;
    @message = m.dup&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Message&lt;br /&gt;
  attr_writer :message&lt;br /&gt;
  def message&lt;br /&gt;
    @message.encode!(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is same for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|Lua&lt;br /&gt;
|ObjectName.MethodName(Parameters);&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  local index = getters and&lt;br /&gt;
    function(self, key)&lt;br /&gt;
      -- read from getter, else from fallback&lt;br /&gt;
      local func = getters[key]&lt;br /&gt;
      if func then return func(self) else return fallback[key] end&lt;br /&gt;
    end&lt;br /&gt;
    or fallback  -- default to fast property reads through table&lt;br /&gt;
  local newindex = setters and&lt;br /&gt;
    function(self, key, value)&lt;br /&gt;
      -- write to setter, else to proxy&lt;br /&gt;
      local func = setters[key]&lt;br /&gt;
      if func then func(self, value)&lt;br /&gt;
      else rawset(self, key, value) end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|Perl&lt;br /&gt;
|$ObjectName-&amp;gt;MethodName(Parameters);&lt;br /&gt;
|$ObjectName-&amp;gt;Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
BEGIN {&lt;br /&gt;
    my @attr = qw(author title number);&lt;br /&gt;
    no strict 'refs';&lt;br /&gt;
    for my $a (@attr){&lt;br /&gt;
        *{__PACKAGE__ . &amp;quot;::get_$a&amp;quot;} = sub { $_[0]-&amp;gt;{$a}         };&lt;br /&gt;
        *{__PACKAGE__ . &amp;quot;::set_$a&amp;quot;} = sub { $_[0]-&amp;gt;{$a} = $_[1] };&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Having getters and setters in the implementation has its own advantages and disadvantages. The advantages are that&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They provide data encapsulation.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They improve the code readability.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Changes can be made only to the implementation without making changes to the code that uses the object.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
Using getters and setters also has a disadvantage. They largely provide access to implementation details. But this could hinder &amp;lt;i&amp;gt;data abstraction&amp;lt;/i&amp;gt;, i.e. hiding the object's implementation of a message handler. Consider a getter function that returns a number. Wherever this method is called, the variable which holds the return value must match the return type of this function. Now if we change they way this method is implemented by changing the return type, then there could be trouble.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Therefore it is important to design such that there is minimal data movement thereby minimizing possible errors.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Using the same syntax for method calls and instance variable references have some advantages and disadvantages. One could argue that having the same syntax makes it simpler for the programmer. It makes the code lighter in terms of lines of code, thus avoiding bulky code. However, including distinct ways for using methods and variables enhances readability by enabling better understanding. This is possible because the manipulation is visible whereas if the syntax were the same(i.e. compact), the one reading has no idea about what is happening &amp;quot;under the hood&amp;quot;.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://help.sap.com/saphelp_nw04/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm/ Declaring and Calling Methods]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(object-oriented_programming)/ Comparison of Programming Languages]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://forums.sdn.sap.com/thread.jspa?threadID=529448&amp;amp;tstart=6135/ Setters and Getters in ABAP]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html?page=1/ Why getters and setters are evil?]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.zeuscmd.com/tutorials/cplusplus/50-GettersAndSetters.php/ Getters and Setters]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://cocoadevcentral.com/d/learn_objectivec/ Objective C]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html/ Ruby Classes- Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.vbtutor.in/getting-started-with-visual-basic-net/object-oriented-programming-in-vbnet/ VB.Net Object oriented programming]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[https://developer.mozilla.org/en/Introduction_to_Object-Oriented_JavaScript/ Javascript - Functions/Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.massassi.com/php/articles/classes/ PHP - Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorialspoint.com/perl/perl_oo_perl.htm/ Perl - Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://lua-users.org/wiki/SimpleLuaClasses/ Lua - Object oriented scripting]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=50584</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=50584"/>
		<updated>2011-09-25T17:05:05Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
&amp;lt;p&amp;gt;A running debate in O-O languages is whether method calls and instance-variable references should have the same syntax. Different programming languages implement this in different ways. Let's look at them by examples.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Ruby use the same syntax for method calls and variable references. There is no distinction between these. We can see this in the example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song&lt;br /&gt;
  def duration=(newDuration)&lt;br /&gt;
    @duration = newDuration&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
aSong = Song.new(&amp;quot;Bicylops&amp;quot;, &amp;quot;Fleck&amp;quot;, 260)&lt;br /&gt;
aSong.duration	»	260&lt;br /&gt;
aSong.duration = 257   # set attribute with updated value&lt;br /&gt;
aSong.duration	»	257&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it simpler for the programmer to code. Also, it presents uniformity in the code.&lt;br /&gt;
&lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Java employ different syntax for method calls and variable references as seen in this example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song{&lt;br /&gt;
	int duration;&lt;br /&gt;
	Song(){}&lt;br /&gt;
	void setDuration(int dur){&lt;br /&gt;
		duration = dur;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Song sng = new Song();&lt;br /&gt;
sng.setDuration(260);&lt;br /&gt;
System.out.println(&amp;quot;Song duration = &amp;quot;+sng.duration);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As seen above, a method is always called using parenthesis, within which arguments may be included if required. However, instance variable is accessed directly.&lt;br /&gt;
&lt;br /&gt;
== Getters and Setters and their Advantages ==&lt;br /&gt;
&amp;lt;p&amp;gt;One of the principles of Objected Oriented Design is that an object's implementation should not be exposed to other classes. This is to avoid difficulty in maintenance. Getters and setters provide a way to read or write private data of a class for any kind of manipulation. They also provide for easy maintenance, in that, if any change needs to be made in the way the variable is set, only the setter method needs to be changed rather than looking for it and changing in every place. These methods also improve the code readability and bring about uniformity across the code.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;br /&gt;
&amp;lt;p&amp;gt;The usage syntax of methods, instance variables, getters and setters is in the table below&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Programming Languages&lt;br /&gt;
!Method call&lt;br /&gt;
!Fields/Attributes&lt;br /&gt;
!Getter / Setter&lt;br /&gt;
!Comparison&lt;br /&gt;
|-&lt;br /&gt;
|ABAP (Advanced Business Application Programming)&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
CALL METHOD &amp;lt;meth&amp;gt; EXPORTING... &amp;lt;ii&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   IMPORTING... &amp;lt;ei&amp;gt; =.&amp;lt;g i&amp;gt;... &lt;br /&gt;
                   CHANGING ... &amp;lt;ci&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   RECEIVING         r = h &lt;br /&gt;
                   EXCEPTIONS... &amp;lt;ei&amp;gt; = rc i...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;data&amp;lt;/b&amp;gt; field &amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt; type&lt;br /&gt;
|Same as other methods with the only difference that they start with SET or GET&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|C++&lt;br /&gt;
|ObjectName.MethodName(parameters) &lt;br /&gt;
|Same as methods. Example below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int getHealth() const { return health; }&lt;br /&gt;
void setHealth(int h) { health = h; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|C#&lt;br /&gt;
|ObjectName.MethodName(parameters) &lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|They are just like methods. Example below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public string GetName()&lt;br /&gt;
    {&lt;br /&gt;
        return m_name;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void SetName(string name)&lt;br /&gt;
    {&lt;br /&gt;
        m_name = name;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|Java&lt;br /&gt;
|ObjectName.MethodName(parameters) [Eg: x.method()]&lt;br /&gt;
|ObjectName.Attribute [Eg: x.field]&lt;br /&gt;
|They are nothing but method calls&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|D&lt;br /&gt;
|ObjectName.MethodName(parameters)&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|No need for getters and setters.  It can be directly accessed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import std.stdio;&lt;br /&gt;
&lt;br /&gt;
class Car&lt;br /&gt;
{&lt;br /&gt;
    float speed = 1.0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void main(){&lt;br /&gt;
    auto my_car = new Car();&lt;br /&gt;
    my_car.speed = 2.5;&lt;br /&gt;
    writefln(my_car.speed);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax used for method calls and variable references is different&lt;br /&gt;
|-&lt;br /&gt;
|Objective C&lt;br /&gt;
|output = [object methodWithOutput]&lt;br /&gt;
|ObjectName-&amp;gt;Attribute&lt;br /&gt;
|An example of getter is below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#import &amp;lt;Cocoa/Cocoa.h&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
@interface Photo : NSObject {&lt;br /&gt;
    NSString* caption;&lt;br /&gt;
    NSString* photographer;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
- (NSString*) caption;&lt;br /&gt;
- (NSString*) photographer;&lt;br /&gt;
&lt;br /&gt;
@end        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
An example of setter is below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#import &amp;lt;Cocoa/Cocoa.h&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
@interface Photo : NSObject {&lt;br /&gt;
    NSString* caption;&lt;br /&gt;
    NSString* photographer;&lt;br /&gt;
}&lt;br /&gt;
- (NSString*) caption;&lt;br /&gt;
- (NSString*) photographer;&lt;br /&gt;
&lt;br /&gt;
- (void) setCaption: (NSString*)input;&lt;br /&gt;
- (void) setPhotographer: (NSString*)input;&lt;br /&gt;
&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax used for method calls and variable references is different&lt;br /&gt;
|-&lt;br /&gt;
|Python&lt;br /&gt;
|ObjectName.MethodName(parameters)&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|Pythonic way of implementing getters and setters is to using public members and turning them into properties when needed&lt;br /&gt;
|Syntax used for method calls and variable references is sometimes the same and different at times (when there are arguments)&lt;br /&gt;
|-&lt;br /&gt;
|Javascript&lt;br /&gt;
|ObjectName.MethodName(Parameters);&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
var lost = {&lt;br /&gt;
	loc : &amp;quot;Island&amp;quot;,&lt;br /&gt;
	get location () {&lt;br /&gt;
		return this.loc;&lt;br /&gt;
	},&lt;br /&gt;
	set location(val) {&lt;br /&gt;
		this.loc = val;&lt;br /&gt;
	}&lt;br /&gt;
};&lt;br /&gt;
lost.location = &amp;quot;Another island&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|PHP&lt;br /&gt;
|$ObjectName-&amp;gt;MethodName(Parameters);&lt;br /&gt;
|$ObjectName-&amp;gt;Attribute&lt;br /&gt;
|N/A. Attributes can be accessed directly.&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|VB.NET&lt;br /&gt;
|ObjectName.MethodName(Parameters);&lt;br /&gt;
ObjectNmae.MethodName&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
Public Property myProperty As String&lt;br /&gt;
    Get&lt;br /&gt;
        Return String.Empty&lt;br /&gt;
    End Get&lt;br /&gt;
    Private Set(ByVal value As String)&lt;br /&gt;
        somethingElse = value&lt;br /&gt;
    End Set&lt;br /&gt;
End Property&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax may be same for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|Ruby&lt;br /&gt;
|$ObjectName-&amp;gt;MethodName(Parameters);&lt;br /&gt;
|$ObjectName-&amp;gt;Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
class Message&lt;br /&gt;
  attr_reader :message&lt;br /&gt;
  def message=(m)&lt;br /&gt;
    @message = m.dup&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Message&lt;br /&gt;
  attr_writer :message&lt;br /&gt;
  def message&lt;br /&gt;
    @message.encode!(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is same for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|Lua&lt;br /&gt;
|ObjectName.MethodName(Parameters);&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  local index = getters and&lt;br /&gt;
    function(self, key)&lt;br /&gt;
      -- read from getter, else from fallback&lt;br /&gt;
      local func = getters[key]&lt;br /&gt;
      if func then return func(self) else return fallback[key] end&lt;br /&gt;
    end&lt;br /&gt;
    or fallback  -- default to fast property reads through table&lt;br /&gt;
  local newindex = setters and&lt;br /&gt;
    function(self, key, value)&lt;br /&gt;
      -- write to setter, else to proxy&lt;br /&gt;
      local func = setters[key]&lt;br /&gt;
      if func then func(self, value)&lt;br /&gt;
      else rawset(self, key, value) end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|Perl&lt;br /&gt;
|$ObjectName-&amp;gt;MethodName(Parameters);&lt;br /&gt;
|$ObjectName-&amp;gt;Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
BEGIN {&lt;br /&gt;
    my @attr = qw(author title number);&lt;br /&gt;
    no strict 'refs';&lt;br /&gt;
    for my $a (@attr){&lt;br /&gt;
        *{__PACKAGE__ . &amp;quot;::get_$a&amp;quot;} = sub { $_[0]-&amp;gt;{$a}         };&lt;br /&gt;
        *{__PACKAGE__ . &amp;quot;::set_$a&amp;quot;} = sub { $_[0]-&amp;gt;{$a} = $_[1] };&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Having getters and setters in the implementation has its own advantages and disadvantages. The advantages are that&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They provide data encapsulation.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They improve the code readability.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Changes can be made only to the implementation without making changes to the code that uses the object.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
Using getters and setters also has a disadvantage. They largely provide access to implementation details. But this could hinder &amp;lt;i&amp;gt;data abstraction&amp;lt;/i&amp;gt;, i.e. hiding the object's implementation of a message handler. Consider a getter function that returns a number. Wherever this method is called, the variable which holds the return value must match the return type of this function. Now if we change they way this method is implemented by changing the return type, then there could be trouble.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Therefore it is important to design such that there is minimal data movement thereby minimizing possible errors.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Using the same syntax for method calls and instance variable references have some advantages and disadvantages. One could argue that having the same syntax makes it simpler for the programmer. It makes the code lighter in terms of lines of code, thus avoiding bulky code. However, including distinct ways for using methods and variables enhances readability by enabling better understanding. This is possible because the manipulation is visible whereas if the syntax were the same(i.e. compact), the one reading has no idea about what is happening &amp;quot;under the hood&amp;quot;.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://help.sap.com/saphelp_nw04/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm/ Declaring and Calling Methods]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(object-oriented_programming)/ Comparison of Programming Languages]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://forums.sdn.sap.com/thread.jspa?threadID=529448&amp;amp;tstart=6135/ Setters and Getters in ABAP]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.zeuscmd.com/tutorials/cplusplus/50-GettersAndSetters.php/ Getters and Setters]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://cocoadevcentral.com/d/learn_objectivec/ Objective C]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html/ Ruby Classes- Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.vbtutor.in/getting-started-with-visual-basic-net/object-oriented-programming-in-vbnet/ VB.Net Object oriented programming]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[https://developer.mozilla.org/en/Introduction_to_Object-Oriented_JavaScript/ Javascript - Functions/Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.massassi.com/php/articles/classes/ PHP - Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorialspoint.com/perl/perl_oo_perl.htm/ Perl - Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://lua-users.org/wiki/SimpleLuaClasses/ Lua - Object oriented scripting]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=50583</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=50583"/>
		<updated>2011-09-25T17:04:24Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
&amp;lt;p&amp;gt;A running debate in O-O languages is whether method calls and instance-variable references should have the same syntax. Different programming languages implement this in different ways. Let's look at them by examples.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Ruby use the same syntax for method calls and variable references. There is no distinction between these. We can see this in the example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song&lt;br /&gt;
  def duration=(newDuration)&lt;br /&gt;
    @duration = newDuration&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
aSong = Song.new(&amp;quot;Bicylops&amp;quot;, &amp;quot;Fleck&amp;quot;, 260)&lt;br /&gt;
aSong.duration	»	260&lt;br /&gt;
aSong.duration = 257   # set attribute with updated value&lt;br /&gt;
aSong.duration	»	257&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it simpler for the programmer to code. Also, it presents uniformity in the code.&lt;br /&gt;
&lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Java employ different syntax for method calls and variable references as seen in this example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song{&lt;br /&gt;
	int duration;&lt;br /&gt;
	Song(){}&lt;br /&gt;
	void setDuration(int dur){&lt;br /&gt;
		duration = dur;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Song sng = new Song();&lt;br /&gt;
sng.setDuration(260);&lt;br /&gt;
System.out.println(&amp;quot;Song duration = &amp;quot;+sng.duration);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As seen above, a method is always called using parenthesis, within which arguments may be included if required. However, instance variable is accessed directly.&lt;br /&gt;
&lt;br /&gt;
== Getters and Setters and their Advantages&lt;br /&gt;
&amp;lt;p&amp;gt;One of the principles of Objected Oriented Design is that an object's implementation should not be exposed to other classes. This is to avoid difficulty in maintenance. Getters and setters provide a way to read or write private data of a class for any kind of manipulation. They also provide for easy maintenance, in that, if any change needs to be made in the way the variable is set, only the setter method needs to be changed rather than looking for it and changing in every place. These methods also improve the code readability and bring about uniformity across the code.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;br /&gt;
&amp;lt;p&amp;gt;The usage syntax of methods, instance variables, getters and setters is in the table below&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Programming Languages&lt;br /&gt;
!Method call&lt;br /&gt;
!Fields/Attributes&lt;br /&gt;
!Getter / Setter&lt;br /&gt;
!Comparison&lt;br /&gt;
|-&lt;br /&gt;
|ABAP (Advanced Business Application Programming)&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
CALL METHOD &amp;lt;meth&amp;gt; EXPORTING... &amp;lt;ii&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   IMPORTING... &amp;lt;ei&amp;gt; =.&amp;lt;g i&amp;gt;... &lt;br /&gt;
                   CHANGING ... &amp;lt;ci&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   RECEIVING         r = h &lt;br /&gt;
                   EXCEPTIONS... &amp;lt;ei&amp;gt; = rc i...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;data&amp;lt;/b&amp;gt; field &amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt; type&lt;br /&gt;
|Same as other methods with the only difference that they start with SET or GET&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|C++&lt;br /&gt;
|ObjectName.MethodName(parameters) &lt;br /&gt;
|Same as methods. Example below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int getHealth() const { return health; }&lt;br /&gt;
void setHealth(int h) { health = h; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|C#&lt;br /&gt;
|ObjectName.MethodName(parameters) &lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|They are just like methods. Example below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public string GetName()&lt;br /&gt;
    {&lt;br /&gt;
        return m_name;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void SetName(string name)&lt;br /&gt;
    {&lt;br /&gt;
        m_name = name;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|Java&lt;br /&gt;
|ObjectName.MethodName(parameters) [Eg: x.method()]&lt;br /&gt;
|ObjectName.Attribute [Eg: x.field]&lt;br /&gt;
|They are nothing but method calls&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|D&lt;br /&gt;
|ObjectName.MethodName(parameters)&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|No need for getters and setters.  It can be directly accessed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import std.stdio;&lt;br /&gt;
&lt;br /&gt;
class Car&lt;br /&gt;
{&lt;br /&gt;
    float speed = 1.0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void main(){&lt;br /&gt;
    auto my_car = new Car();&lt;br /&gt;
    my_car.speed = 2.5;&lt;br /&gt;
    writefln(my_car.speed);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax used for method calls and variable references is different&lt;br /&gt;
|-&lt;br /&gt;
|Objective C&lt;br /&gt;
|output = [object methodWithOutput]&lt;br /&gt;
|ObjectName-&amp;gt;Attribute&lt;br /&gt;
|An example of getter is below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#import &amp;lt;Cocoa/Cocoa.h&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
@interface Photo : NSObject {&lt;br /&gt;
    NSString* caption;&lt;br /&gt;
    NSString* photographer;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
- (NSString*) caption;&lt;br /&gt;
- (NSString*) photographer;&lt;br /&gt;
&lt;br /&gt;
@end        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
An example of setter is below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#import &amp;lt;Cocoa/Cocoa.h&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
@interface Photo : NSObject {&lt;br /&gt;
    NSString* caption;&lt;br /&gt;
    NSString* photographer;&lt;br /&gt;
}&lt;br /&gt;
- (NSString*) caption;&lt;br /&gt;
- (NSString*) photographer;&lt;br /&gt;
&lt;br /&gt;
- (void) setCaption: (NSString*)input;&lt;br /&gt;
- (void) setPhotographer: (NSString*)input;&lt;br /&gt;
&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax used for method calls and variable references is different&lt;br /&gt;
|-&lt;br /&gt;
|Python&lt;br /&gt;
|ObjectName.MethodName(parameters)&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|Pythonic way of implementing getters and setters is to using public members and turning them into properties when needed&lt;br /&gt;
|Syntax used for method calls and variable references is sometimes the same and different at times (when there are arguments)&lt;br /&gt;
|-&lt;br /&gt;
|Javascript&lt;br /&gt;
|ObjectName.MethodName(Parameters);&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
var lost = {&lt;br /&gt;
	loc : &amp;quot;Island&amp;quot;,&lt;br /&gt;
	get location () {&lt;br /&gt;
		return this.loc;&lt;br /&gt;
	},&lt;br /&gt;
	set location(val) {&lt;br /&gt;
		this.loc = val;&lt;br /&gt;
	}&lt;br /&gt;
};&lt;br /&gt;
lost.location = &amp;quot;Another island&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|PHP&lt;br /&gt;
|$ObjectName-&amp;gt;MethodName(Parameters);&lt;br /&gt;
|$ObjectName-&amp;gt;Attribute&lt;br /&gt;
|N/A. Attributes can be accessed directly.&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|VB.NET&lt;br /&gt;
|ObjectName.MethodName(Parameters);&lt;br /&gt;
ObjectNmae.MethodName&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
Public Property myProperty As String&lt;br /&gt;
    Get&lt;br /&gt;
        Return String.Empty&lt;br /&gt;
    End Get&lt;br /&gt;
    Private Set(ByVal value As String)&lt;br /&gt;
        somethingElse = value&lt;br /&gt;
    End Set&lt;br /&gt;
End Property&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax may be same for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|Ruby&lt;br /&gt;
|$ObjectName-&amp;gt;MethodName(Parameters);&lt;br /&gt;
|$ObjectName-&amp;gt;Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
class Message&lt;br /&gt;
  attr_reader :message&lt;br /&gt;
  def message=(m)&lt;br /&gt;
    @message = m.dup&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Message&lt;br /&gt;
  attr_writer :message&lt;br /&gt;
  def message&lt;br /&gt;
    @message.encode!(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is same for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|Lua&lt;br /&gt;
|ObjectName.MethodName(Parameters);&lt;br /&gt;
|ObjectName.Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  local index = getters and&lt;br /&gt;
    function(self, key)&lt;br /&gt;
      -- read from getter, else from fallback&lt;br /&gt;
      local func = getters[key]&lt;br /&gt;
      if func then return func(self) else return fallback[key] end&lt;br /&gt;
    end&lt;br /&gt;
    or fallback  -- default to fast property reads through table&lt;br /&gt;
  local newindex = setters and&lt;br /&gt;
    function(self, key, value)&lt;br /&gt;
      -- write to setter, else to proxy&lt;br /&gt;
      local func = setters[key]&lt;br /&gt;
      if func then func(self, value)&lt;br /&gt;
      else rawset(self, key, value) end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|Perl&lt;br /&gt;
|$ObjectName-&amp;gt;MethodName(Parameters);&lt;br /&gt;
|$ObjectName-&amp;gt;Attribute&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
BEGIN {&lt;br /&gt;
    my @attr = qw(author title number);&lt;br /&gt;
    no strict 'refs';&lt;br /&gt;
    for my $a (@attr){&lt;br /&gt;
        *{__PACKAGE__ . &amp;quot;::get_$a&amp;quot;} = sub { $_[0]-&amp;gt;{$a}         };&lt;br /&gt;
        *{__PACKAGE__ . &amp;quot;::set_$a&amp;quot;} = sub { $_[0]-&amp;gt;{$a} = $_[1] };&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Having getters and setters in the implementation has its own advantages and disadvantages. The advantages are that&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They provide data encapsulation.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;They improve the code readability.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Changes can be made only to the implementation without making changes to the code that uses the object.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
Using getters and setters also has a disadvantage. They largely provide access to implementation details. But this could hinder &amp;lt;i&amp;gt;data abstraction&amp;lt;/i&amp;gt;, i.e. hiding the object's implementation of a message handler. Consider a getter function that returns a number. Wherever this method is called, the variable which holds the return value must match the return type of this function. Now if we change they way this method is implemented by changing the return type, then there could be trouble.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Therefore it is important to design such that there is minimal data movement thereby minimizing possible errors.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Using the same syntax for method calls and instance variable references have some advantages and disadvantages. One could argue that having the same syntax makes it simpler for the programmer. It makes the code lighter in terms of lines of code, thus avoiding bulky code. However, including distinct ways for using methods and variables enhances readability by enabling better understanding. This is possible because the manipulation is visible whereas if the syntax were the same(i.e. compact), the one reading has no idea about what is happening &amp;quot;under the hood&amp;quot;.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://help.sap.com/saphelp_nw04/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm/ Declaring and Calling Methods]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(object-oriented_programming)/ Comparison of Programming Languages]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://forums.sdn.sap.com/thread.jspa?threadID=529448&amp;amp;tstart=6135/ Setters and Getters in ABAP]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.zeuscmd.com/tutorials/cplusplus/50-GettersAndSetters.php/ Getters and Setters]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://cocoadevcentral.com/d/learn_objectivec/ Objective C]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html/ Ruby Classes- Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.vbtutor.in/getting-started-with-visual-basic-net/object-oriented-programming-in-vbnet/ VB.Net Object oriented programming]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[https://developer.mozilla.org/en/Introduction_to_Object-Oriented_JavaScript/ Javascript - Functions/Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.massassi.com/php/articles/classes/ PHP - Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorialspoint.com/perl/perl_oo_perl.htm/ Perl - Objects]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://lua-users.org/wiki/SimpleLuaClasses/ Lua - Object oriented scripting]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Trial&amp;diff=48575</id>
		<title>Trial</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Trial&amp;diff=48575"/>
		<updated>2011-09-09T02:58:16Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:concepts.gif]]&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Trial&amp;diff=48573</id>
		<title>Trial</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Trial&amp;diff=48573"/>
		<updated>2011-09-09T02:58:05Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: Created page with &amp;quot;File:concepts-object.gif&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:concepts-object.gif]]&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011&amp;diff=48572</id>
		<title>CSC/ECE 517 Fall 2011</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011&amp;diff=48572"/>
		<updated>2011-09-09T02:57:45Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Link title]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1a ms]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1a cs]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1a ri]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1a lj]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1b sa]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1b ds]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1b tj]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1c cm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1c sj]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1c ka]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1d sr]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1e vs]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e aa]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1a sc]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e dm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e an]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e sa]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e lm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1g vn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1f rs]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1f sv]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1g jn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1h ps]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e sm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1i zf]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1g rn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1i cl]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1d ss]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1i lj]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1h hs]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1d gs]]&lt;br /&gt;
&lt;br /&gt;
*[[trial]]&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=47351</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=47351"/>
		<updated>2011-09-08T03:36:34Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
&amp;lt;p&amp;gt;A running debate in O-O languages is whether method calls and instance-variable references should have the same syntax. Different programming languages implement this in different ways. Let's look at them by examples.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Ruby use the same syntax for method calls and variable references. There is no distinction between these. We can see this in the example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song&lt;br /&gt;
  def duration=(newDuration)&lt;br /&gt;
    @duration = newDuration&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
aSong = Song.new(&amp;quot;Bicylops&amp;quot;, &amp;quot;Fleck&amp;quot;, 260)&lt;br /&gt;
aSong.duration	»	260&lt;br /&gt;
aSong.duration = 257   # set attribute with updated value&lt;br /&gt;
aSong.duration	»	257&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it simpler for the programmer to code. Also, it presents uniformity in the code.&lt;br /&gt;
&lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Java employ different syntax for method calls and variable references as seen in this example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song{&lt;br /&gt;
	int duration;&lt;br /&gt;
	Song(){}&lt;br /&gt;
	void setDuration(int dur){&lt;br /&gt;
		duration = dur;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Song sng = new Song();&lt;br /&gt;
sng.setDuration(260);&lt;br /&gt;
System.out.println(&amp;quot;Song duration = &amp;quot;+sng.duration);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As seen above, a method is always called using parenthesis, within which arguments may be included if required. However, instance variable is accessed directly.&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;br /&gt;
&amp;lt;p&amp;gt;The usage syntax of methods, instance variables, getters and setters is in the table below&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Programming Languages&lt;br /&gt;
!Method call&lt;br /&gt;
!Fields/Attributes&lt;br /&gt;
!Getter / Setter&lt;br /&gt;
!Comparison&lt;br /&gt;
|-&lt;br /&gt;
|ABAP (Advanced Business Application Programming)&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
CALL METHOD &amp;lt;meth&amp;gt; EXPORTING... &amp;lt;ii&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   IMPORTING... &amp;lt;ei&amp;gt; =.&amp;lt;g i&amp;gt;... &lt;br /&gt;
                   CHANGING ... &amp;lt;ci&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   RECEIVING         r = h &lt;br /&gt;
                   EXCEPTIONS... &amp;lt;ei&amp;gt; = rc i...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;data&amp;lt;/b&amp;gt; field &amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt; type&lt;br /&gt;
|Same as other methods with the only difference that they start with SET or GET&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|C++&lt;br /&gt;
|&amp;lt;instance-variable&amp;gt;.method(parameters) [Eg: x.method()]&lt;br /&gt;
|&amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt; field&lt;br /&gt;
|Same as methods. Example below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int getHealth() const { return health; }&lt;br /&gt;
void setHealth(int h) { health = h; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|C#&lt;br /&gt;
|&amp;lt;instance-variable&amp;gt;.method(parameters) [Eg: x.method()]&lt;br /&gt;
|&amp;lt;instance-variable&amp;gt;.field [Eg: x.field]&lt;br /&gt;
|They are just like methods. Example below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public string GetName()&lt;br /&gt;
    {&lt;br /&gt;
        return m_name;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void SetName(string name)&lt;br /&gt;
    {&lt;br /&gt;
        m_name = name;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|Java&lt;br /&gt;
|&amp;lt;instance-variable&amp;gt;.method(parameters) [Eg: x.method()]&lt;br /&gt;
|&amp;lt;instance-variable&amp;gt;.field [Eg: x.field]&lt;br /&gt;
|They are nothing but method calls&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|D&lt;br /&gt;
|&amp;lt;instance-variable&amp;gt;.method(parameters) [Eg: x.method()]&lt;br /&gt;
|&amp;lt;instance-variable&amp;gt;.field [Eg: x.field]&lt;br /&gt;
|No need for getters and setters.  It can be directly accessed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import std.stdio;&lt;br /&gt;
&lt;br /&gt;
class Car&lt;br /&gt;
{&lt;br /&gt;
    float speed = 1.0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void main(){&lt;br /&gt;
    auto my_car = new Car();&lt;br /&gt;
    my_car.speed = 2.5;&lt;br /&gt;
    writefln(my_car.speed);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax used for method calls and variable references is different&lt;br /&gt;
|-&lt;br /&gt;
|Objective C&lt;br /&gt;
|output = [object methodWithOutput]&lt;br /&gt;
|x-&amp;gt;field&lt;br /&gt;
|An example of getter is below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#import &amp;lt;Cocoa/Cocoa.h&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
@interface Photo : NSObject {&lt;br /&gt;
    NSString* caption;&lt;br /&gt;
    NSString* photographer;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
- (NSString*) caption;&lt;br /&gt;
- (NSString*) photographer;&lt;br /&gt;
&lt;br /&gt;
@end        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
An example of setter is below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#import &amp;lt;Cocoa/Cocoa.h&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
@interface Photo : NSObject {&lt;br /&gt;
    NSString* caption;&lt;br /&gt;
    NSString* photographer;&lt;br /&gt;
}&lt;br /&gt;
- (NSString*) caption;&lt;br /&gt;
- (NSString*) photographer;&lt;br /&gt;
&lt;br /&gt;
- (void) setCaption: (NSString*)input;&lt;br /&gt;
- (void) setPhotographer: (NSString*)input;&lt;br /&gt;
&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Syntax used for method calls and variable references is different&lt;br /&gt;
|-&lt;br /&gt;
|Python&lt;br /&gt;
|x.method(parameters)&lt;br /&gt;
|x.field&lt;br /&gt;
|Pythonic way of implementing getters and setters is to using public members and turning them into properties when needed&lt;br /&gt;
|Syntax used for method calls and variable references is sometimes the same and different at times (when there are arguments)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&amp;lt;p&amp;gt;Using the same syntax for method calls and instance variable references have some advantages and disadvantages. One could argue that having the same syntax makes it simpler for the programmer. It makes the code lighter in terms of lines of code, thus avoiding bulky code. However, including distinct ways for using methods and variables enhances readability by enabling better understanding. This is possible because the manipulation is visible whereas if the syntax were the same(i.e. compact), the one reading has no idea about what is happening &amp;quot;under the hood&amp;quot;.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://help.sap.com/saphelp_nw04/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm/ Declaring and Calling Methods]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(object-oriented_programming)/ Comparison of Programming Languages]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://forums.sdn.sap.com/thread.jspa?threadID=529448&amp;amp;tstart=6135/ Setters and Getters in ABAP]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.zeuscmd.com/tutorials/cplusplus/50-GettersAndSetters.php/ Getters and Setters]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://cocoadevcentral.com/d/learn_objectivec/ Objective C]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=47324</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=47324"/>
		<updated>2011-09-08T03:24:03Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
&amp;lt;p&amp;gt;A running debate in O-O languages is whether method calls and instance-variable references should have the same syntax. Different programming languages implement this in different ways. Let's look at them by examples.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Ruby use the same syntax for method calls and variable references. There is no distinction between these. We can see this in the example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song&lt;br /&gt;
  def duration=(newDuration)&lt;br /&gt;
    @duration = newDuration&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
aSong = Song.new(&amp;quot;Bicylops&amp;quot;, &amp;quot;Fleck&amp;quot;, 260)&lt;br /&gt;
aSong.duration	»	260&lt;br /&gt;
aSong.duration = 257   # set attribute with updated value&lt;br /&gt;
aSong.duration	»	257&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it simpler for the programmer to code. Also, it presents uniformity in the code.&lt;br /&gt;
&lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Java employ different syntax for method calls and variable references as seen in this example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song{&lt;br /&gt;
	int duration;&lt;br /&gt;
	Song(){}&lt;br /&gt;
	void setDuration(int dur){&lt;br /&gt;
		duration = dur;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Song sng = new Song();&lt;br /&gt;
sng.setDuration(260);&lt;br /&gt;
System.out.println(&amp;quot;Song duration = &amp;quot;+sng.duration);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As seen above, a method is always called using parenthesis, within which arguments may be included if required. However, instance variable is accessed directly.&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;br /&gt;
&amp;lt;p&amp;gt;The usage syntax of methods, instance variables, getters and setters is in the table below&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Programming Languages&lt;br /&gt;
!Method call&lt;br /&gt;
!Fields/Attributes&lt;br /&gt;
!Getter / Setter&lt;br /&gt;
!Comparison&lt;br /&gt;
|-&lt;br /&gt;
|ABAP (Advanced Business Application Programming)&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
CALL METHOD &amp;lt;meth&amp;gt; EXPORTING... &amp;lt;ii&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   IMPORTING... &amp;lt;ei&amp;gt; =.&amp;lt;g i&amp;gt;... &lt;br /&gt;
                   CHANGING ... &amp;lt;ci&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   RECEIVING         r = h &lt;br /&gt;
                   EXCEPTIONS... &amp;lt;ei&amp;gt; = rc i...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;data&amp;lt;/b&amp;gt; field &amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt; type&lt;br /&gt;
|Same as other methods with the only difference that they start with SET or GET&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|C++&lt;br /&gt;
|&amp;lt;instance-variable&amp;gt;.method(parameters) [Eg: x.method()]&lt;br /&gt;
|&amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt; field&lt;br /&gt;
|Same as methods. Example below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int getHealth() const { return health; }&lt;br /&gt;
void setHealth(int h) { health = h; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|-&lt;br /&gt;
|C#&lt;br /&gt;
|&amp;lt;instance-variable&amp;gt;.method(parameters) [Eg: x.method()]&lt;br /&gt;
|&amp;lt;instance-variable&amp;gt;.field [Eg: x.field]&lt;br /&gt;
|They are just like methods. Example below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public string GetName()&lt;br /&gt;
    {&lt;br /&gt;
        return m_name;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void SetName(string name)&lt;br /&gt;
    {&lt;br /&gt;
        m_name = name;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&amp;lt;p&amp;gt;Using the same syntax for method calls and instance variable references have some advantages and disadvantages. One could argue that having the same syntax makes it simpler for the programmer. It makes the code lighter in terms of lines of code, thus avoiding bulky code. However, including distinct ways for using methods and variables enhances readability by enabling better understanding. This is possible because the manipulation is visible whereas if the syntax were the same(i.e. compact), the one reading has no idea about what is happening &amp;quot;under the hood&amp;quot;.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://help.sap.com/saphelp_nw04/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm/ Declaring and Calling Methods]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(object-oriented_programming)/ Comparison of Programming Languages]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://forums.sdn.sap.com/thread.jspa?threadID=529448&amp;amp;tstart=6135/ Setters and Getters in ABAP]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.zeuscmd.com/tutorials/cplusplus/50-GettersAndSetters.php/ Getters and Setters]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://cocoadevcentral.com/d/learn_objectivec/ Objective C]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=47317</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=47317"/>
		<updated>2011-09-08T03:22:07Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
&amp;lt;p&amp;gt;A running debate in O-O languages is whether method calls and instance-variable references should have the same syntax. Different programming languages implement this in different ways. Let's look at them by examples.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Ruby use the same syntax for method calls and variable references. There is no distinction between these. We can see this in the example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song&lt;br /&gt;
  def duration=(newDuration)&lt;br /&gt;
    @duration = newDuration&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
aSong = Song.new(&amp;quot;Bicylops&amp;quot;, &amp;quot;Fleck&amp;quot;, 260)&lt;br /&gt;
aSong.duration	»	260&lt;br /&gt;
aSong.duration = 257   # set attribute with updated value&lt;br /&gt;
aSong.duration	»	257&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it simpler for the programmer to code. Also, it presents uniformity in the code.&lt;br /&gt;
&lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Java employ different syntax for method calls and variable references as seen in this example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song{&lt;br /&gt;
	int duration;&lt;br /&gt;
	Song(){}&lt;br /&gt;
	void setDuration(int dur){&lt;br /&gt;
		duration = dur;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Song sng = new Song();&lt;br /&gt;
sng.setDuration(260);&lt;br /&gt;
System.out.println(&amp;quot;Song duration = &amp;quot;+sng.duration);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As seen above, a method is always called using parenthesis, within which arguments may be included if required. However, instance variable is accessed directly.&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;br /&gt;
&amp;lt;p&amp;gt;The usage syntax of methods, instance variables, getters and setters is in the table below&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Programming Languages&lt;br /&gt;
!Method call&lt;br /&gt;
!Fields/Attributes&lt;br /&gt;
!Getter / Setter&lt;br /&gt;
!Comparison&lt;br /&gt;
|-&lt;br /&gt;
|ABAP (Advanced Business Application Programming)&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
CALL METHOD &amp;lt;meth&amp;gt; EXPORTING... &amp;lt;ii&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   IMPORTING... &amp;lt;ei&amp;gt; =.&amp;lt;g i&amp;gt;... &lt;br /&gt;
                   CHANGING ... &amp;lt;ci&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   RECEIVING         r = h &lt;br /&gt;
                   EXCEPTIONS... &amp;lt;ei&amp;gt; = rc i...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;data&amp;lt;/b&amp;gt; field &amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt; type&lt;br /&gt;
|Same as other methods with the only difference that they start with SET or GET&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
|-&lt;br /&gt;
|C++&lt;br /&gt;
|&amp;lt;instance-variable&amp;gt;.method(parameters) [Eg: x.method()]&lt;br /&gt;
|&amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt; field&lt;br /&gt;
|Same as methods. Example below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int getHealth() const { return health; }&lt;br /&gt;
void setHealth(int h) { health = h; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Different syntax is used to call methods and instance-variable references&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&amp;lt;p&amp;gt;Using the same syntax for method calls and instance variable references have some advantages and disadvantages. One could argue that having the same syntax makes it simpler for the programmer. It makes the code lighter in terms of lines of code, thus avoiding bulky code. However, including distinct ways for using methods and variables enhances readability by enabling better understanding. This is possible because the manipulation is visible whereas if the syntax were the same(i.e. compact), the one reading has no idea about what is happening &amp;quot;under the hood&amp;quot;.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://help.sap.com/saphelp_nw04/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm/ Declaring and Calling Methods]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(object-oriented_programming)/ Comparison of Programming Languages]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://forums.sdn.sap.com/thread.jspa?threadID=529448&amp;amp;tstart=6135/ Setters and Getters in ABAP]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.zeuscmd.com/tutorials/cplusplus/50-GettersAndSetters.php/ Getters and Setters]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://cocoadevcentral.com/d/learn_objectivec/ Objective C]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=47277</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=47277"/>
		<updated>2011-09-08T03:13:20Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
&amp;lt;p&amp;gt;A running debate in O-O languages is whether method calls and instance-variable references should have the same syntax. Different programming languages implement this in different ways. Let's look at them by examples.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Ruby use the same syntax for method calls and variable references. There is no distinction between these. We can see this in the example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song&lt;br /&gt;
  def duration=(newDuration)&lt;br /&gt;
    @duration = newDuration&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
aSong = Song.new(&amp;quot;Bicylops&amp;quot;, &amp;quot;Fleck&amp;quot;, 260)&lt;br /&gt;
aSong.duration	»	260&lt;br /&gt;
aSong.duration = 257   # set attribute with updated value&lt;br /&gt;
aSong.duration	»	257&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it simpler for the programmer to code. Also, it presents uniformity in the code.&lt;br /&gt;
&lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Java employ different syntax for method calls and variable references as seen in this example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song{&lt;br /&gt;
	int duration;&lt;br /&gt;
	Song(){}&lt;br /&gt;
	void setDuration(int dur){&lt;br /&gt;
		duration = dur;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Song sng = new Song();&lt;br /&gt;
sng.setDuration(260);&lt;br /&gt;
System.out.println(&amp;quot;Song duration = &amp;quot;+sng.duration);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As seen above, a method is always called using parenthesis, within which arguments may be included if required. However, instance variable is accessed directly.&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;br /&gt;
&amp;lt;p&amp;gt;The usage syntax of methods, instance variables, getters and setters is in the table below&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Programming Languages&lt;br /&gt;
!Method call&lt;br /&gt;
!Fields/Attributes&lt;br /&gt;
!Getter / Setter&lt;br /&gt;
!Comparison&lt;br /&gt;
|-&lt;br /&gt;
|ABAP (Advanced Business Application Programming)&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
CALL METHOD &amp;lt;meth&amp;gt; EXPORTING... &amp;lt;ii&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   IMPORTING... &amp;lt;ei&amp;gt; =.&amp;lt;g i&amp;gt;... &lt;br /&gt;
                   CHANGING ... &amp;lt;ci&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   RECEIVING         r = h &lt;br /&gt;
                   EXCEPTIONS... &amp;lt;ei&amp;gt; = rc i...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;data&amp;lt;/b&amp;gt; field &amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt; type&lt;br /&gt;
|Same as other methods with the only difference that they start with SET or GET&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&amp;lt;p&amp;gt;Using the same syntax for method calls and instance variable references have some advantages and disadvantages. One could argue that having the same syntax makes it simpler for the programmer. It makes the code lighter in terms of lines of code, thus avoiding bulky code. However, including distinct ways for using methods and variables enhances readability by enabling better understanding. This is possible because the manipulation is visible whereas if the syntax were the same(i.e. compact), the one reading has no idea about what is happening &amp;quot;under the hood&amp;quot;.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://help.sap.com/saphelp_nw04/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm/ Declaring and Calling Methods]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(object-oriented_programming)/ Comparison of Programming Languages]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://forums.sdn.sap.com/thread.jspa?threadID=529448&amp;amp;tstart=6135/ Setters and Getters in ABAP]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.zeuscmd.com/tutorials/cplusplus/50-GettersAndSetters.php/ Getters and Setters]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://cocoadevcentral.com/d/learn_objectivec/ Objective C]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=47011</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=47011"/>
		<updated>2011-09-08T00:40:09Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
&amp;lt;p&amp;gt;A running debate in O-O languages is whether method calls and instance-variable references should have the same syntax. Different programming languages implement this in different ways. Let's look at them by examples.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Ruby use the same syntax for method calls and variable references. There is no distinction between these. We can see this in the example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song&lt;br /&gt;
  def duration=(newDuration)&lt;br /&gt;
    @duration = newDuration&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
aSong = Song.new(&amp;quot;Bicylops&amp;quot;, &amp;quot;Fleck&amp;quot;, 260)&lt;br /&gt;
aSong.duration	»	260&lt;br /&gt;
aSong.duration = 257   # set attribute with updated value&lt;br /&gt;
aSong.duration	»	257&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it simpler for the programmer to code. Also, it presents uniformity in the code.&lt;br /&gt;
&lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Java employ different syntax for method calls and variable references as seen in this example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song{&lt;br /&gt;
	int duration;&lt;br /&gt;
	Song(){}&lt;br /&gt;
	void setDuration(int dur){&lt;br /&gt;
		duration = dur;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Song sng = new Song();&lt;br /&gt;
sng.setDuration(260);&lt;br /&gt;
System.out.println(&amp;quot;Song duration = &amp;quot;+sng.duration);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As seen above, a method is always called using parenthesis, within which arguments may be included if required. However, instance variable is accessed directly.&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;br /&gt;
&amp;lt;p&amp;gt;The usage syntax of methods, instance variables, getters and setters is in the table below&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Programming Languages&lt;br /&gt;
!Method call&lt;br /&gt;
!Fields/Attributes&lt;br /&gt;
!Getter / Setter&lt;br /&gt;
!Comparison&lt;br /&gt;
|-&lt;br /&gt;
|ABAP (Advanced Business Application Programming)&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
CALL METHOD &amp;lt;meth&amp;gt; EXPORTING... &amp;lt;ii&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   IMPORTING... &amp;lt;ei&amp;gt; =.&amp;lt;g i&amp;gt;... &lt;br /&gt;
                   CHANGING ... &amp;lt;ci&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   RECEIVING         r = h &lt;br /&gt;
                   EXCEPTIONS... &amp;lt;ei&amp;gt; = rc i...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;data&amp;lt;/b&amp;gt; field &amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt; type&lt;br /&gt;
|Same as other methods with the only difference that they start with SET or GET&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&amp;lt;p&amp;gt;Using the same syntax for method calls and instance variable references have some advantages and disadvantages. One could argue that having the same syntax makes it simpler for the programmer. It makes the code lighter in terms of lines of code, thus avoiding bulky code. However, including distinct ways for using methods and variables enhances readability by enabling better understanding. This is possible because the manipulation is visible whereas if the syntax were the same(i.e. compact), the one reading has no idea about what is happening &amp;quot;under the hood&amp;quot;.&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=47000</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=47000"/>
		<updated>2011-09-08T00:32:08Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
&amp;lt;p&amp;gt;A running debate in O-O languages is whether method calls and instance-variable references should have the same syntax. Different programming languages implement this in different ways. Let's look at them by examples.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Ruby use the same syntax for method calls and variable references. There is no distinction between these. We can see this in the example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song&lt;br /&gt;
  def duration=(newDuration)&lt;br /&gt;
    @duration = newDuration&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
aSong = Song.new(&amp;quot;Bicylops&amp;quot;, &amp;quot;Fleck&amp;quot;, 260)&lt;br /&gt;
aSong.duration	»	260&lt;br /&gt;
aSong.duration = 257   # set attribute with updated value&lt;br /&gt;
aSong.duration	»	257&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it simpler for the programmer to code. Also, it presents uniformity in the code.&lt;br /&gt;
&lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Java employ different syntax for method calls and variable references as seen in this example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song{&lt;br /&gt;
	int duration;&lt;br /&gt;
	Song(){}&lt;br /&gt;
	void setDuration(int dur){&lt;br /&gt;
		duration = dur;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Song sng = new Song();&lt;br /&gt;
sng.setDuration(260);&lt;br /&gt;
System.out.println(&amp;quot;Song duration = &amp;quot;+sng.duration);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As seen above, a method is always called using parenthesis, within which arguments may be included if required. However, instance variable is accessed directly.&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;br /&gt;
&amp;lt;p&amp;gt;The usage syntax of methods, instance variables, getters and setters is in the table below&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Programming Languages&lt;br /&gt;
!Method call&lt;br /&gt;
!Fields/Attributes&lt;br /&gt;
!Getter / Setter&lt;br /&gt;
!Comparison&lt;br /&gt;
|-&lt;br /&gt;
|ABAP (Advanced Business Application Programming)&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
CALL METHOD &amp;lt;meth&amp;gt; EXPORTING... &amp;lt;ii&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   IMPORTING... &amp;lt;ei&amp;gt; =.&amp;lt;g i&amp;gt;... &lt;br /&gt;
                   CHANGING ... &amp;lt;ci&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   RECEIVING         r = h &lt;br /&gt;
                   EXCEPTIONS... &amp;lt;ei&amp;gt; = rc i...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;data&amp;lt;/b&amp;gt; field &amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt; type&lt;br /&gt;
|Same as other methods with the only difference that they start with SET or GET&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46998</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46998"/>
		<updated>2011-09-08T00:31:18Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
&amp;lt;p&amp;gt;A running debate in O-O languages is whether method calls and instance-variable references should have the same syntax. Different programming languages implement this in different ways. Let's look at them by examples.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Ruby use the same syntax for method calls and variable references. There is no distinction between these. We can see this in the example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song&lt;br /&gt;
  def duration=(newDuration)&lt;br /&gt;
    @duration = newDuration&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
aSong = Song.new(&amp;quot;Bicylops&amp;quot;, &amp;quot;Fleck&amp;quot;, 260)&lt;br /&gt;
aSong.duration	»	260&lt;br /&gt;
aSong.duration = 257   # set attribute with updated value&lt;br /&gt;
aSong.duration	»	257&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it simpler for the programmer to code. Also, it presents uniformity in the code.&lt;br /&gt;
&lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Java employ different syntax for method calls and variable references as seen in this example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song{&lt;br /&gt;
	int duration;&lt;br /&gt;
	Song(){}&lt;br /&gt;
	void setDuration(int dur){&lt;br /&gt;
		duration = dur;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Song sng = new Song();&lt;br /&gt;
sng.setDuration(260);&lt;br /&gt;
System.out.println(&amp;quot;Song duration = &amp;quot;+sng.duration);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As seen above, a method is always called using parenthesis, within which arguments may be included if required. However, instance variable is accessed directly.&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;br /&gt;
&amp;lt;p&amp;gt;The usage syntax of methods, instance variables, getters and setters is in the table below&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Programming Languages&lt;br /&gt;
!Method call&lt;br /&gt;
!Fields/Attributes&lt;br /&gt;
!Getter / Setter&lt;br /&gt;
!Comparison&lt;br /&gt;
|-&lt;br /&gt;
|ABAP (Advanced Business Application Programming)&lt;br /&gt;
|CALL METHOD &amp;lt;meth&amp;gt; EXPORTING... &amp;lt;ii&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
&amp;lt;br&amp;gt;&amp;amp;#09;IMPORTING... &amp;lt;ei&amp;gt; =.&amp;lt;g i&amp;gt;... &lt;br /&gt;
&amp;lt;br&amp;gt;&amp;amp;#09;CHANGING ... &amp;lt;ci&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
&amp;lt;br&amp;gt;&amp;amp;#09;RECEIVING         r = h &lt;br /&gt;
&amp;lt;br&amp;gt;&amp;amp;#09;EXCEPTIONS... &amp;lt;ei&amp;gt; = rc i...&lt;br /&gt;
|&amp;lt;b&amp;gt;data&amp;lt;/b&amp;gt; field &amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt; type&lt;br /&gt;
|Same as other methods with the only difference that they start with SET or GET&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46996</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46996"/>
		<updated>2011-09-08T00:29:02Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
&amp;lt;p&amp;gt;A running debate in O-O languages is whether method calls and instance-variable references should have the same syntax. Different programming languages implement this in different ways. Let's look at them by examples.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Ruby use the same syntax for method calls and variable references. There is no distinction between these. We can see this in the example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song&lt;br /&gt;
  def duration=(newDuration)&lt;br /&gt;
    @duration = newDuration&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
aSong = Song.new(&amp;quot;Bicylops&amp;quot;, &amp;quot;Fleck&amp;quot;, 260)&lt;br /&gt;
aSong.duration	»	260&lt;br /&gt;
aSong.duration = 257   # set attribute with updated value&lt;br /&gt;
aSong.duration	»	257&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it simpler for the programmer to code. Also, it presents uniformity in the code.&lt;br /&gt;
&lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Java employ different syntax for method calls and variable references as seen in this example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song{&lt;br /&gt;
	int duration;&lt;br /&gt;
	Song(){}&lt;br /&gt;
	void setDuration(int dur){&lt;br /&gt;
		duration = dur;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Song sng = new Song();&lt;br /&gt;
sng.setDuration(260);&lt;br /&gt;
System.out.println(&amp;quot;Song duration = &amp;quot;+sng.duration);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As seen above, a method is always called using parenthesis, within which arguments may be included if required. However, instance variable is accessed directly.&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;br /&gt;
&amp;lt;p&amp;gt;The usage syntax of methods, instance variables, getters and setters is in the table below&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Programming Languages&lt;br /&gt;
!Method call&lt;br /&gt;
!Fields/Attributes&lt;br /&gt;
!Getter / Setter&lt;br /&gt;
!Comparison&lt;br /&gt;
|-&lt;br /&gt;
|ABAP (Advanced Business Application Programming)&lt;br /&gt;
|CALL METHOD &amp;lt;meth&amp;gt; EXPORTING... &amp;lt;ii&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
IMPORTING... &amp;lt;ei&amp;gt; =.&amp;lt;g i&amp;gt;... &lt;br /&gt;
CHANGING ... &amp;lt;ci&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
RECEIVING         r = h &lt;br /&gt;
EXCEPTIONS... &amp;lt;ei&amp;gt; = rc i...&lt;br /&gt;
|&amp;lt;b&amp;gt;data&amp;lt;/b&amp;gt; field &amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt; type&lt;br /&gt;
|Same as other methods with the only difference that they start with SET or GET&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46994</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46994"/>
		<updated>2011-09-08T00:27:18Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
&amp;lt;p&amp;gt;A running debate in O-O languages is whether method calls and instance-variable references should have the same syntax. Different programming languages implement this in different ways. Let's look at them by examples.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Ruby use the same syntax for method calls and variable references. There is no distinction between these. We can see this in the example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song&lt;br /&gt;
  def duration=(newDuration)&lt;br /&gt;
    @duration = newDuration&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
aSong = Song.new(&amp;quot;Bicylops&amp;quot;, &amp;quot;Fleck&amp;quot;, 260)&lt;br /&gt;
aSong.duration	»	260&lt;br /&gt;
aSong.duration = 257   # set attribute with updated value&lt;br /&gt;
aSong.duration	»	257&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it simpler for the programmer to code. Also, it presents uniformity in the code.&lt;br /&gt;
&lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Java employ different syntax for method calls and variable references as seen in this example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song{&lt;br /&gt;
	int duration;&lt;br /&gt;
	Song(){}&lt;br /&gt;
	void setDuration(int dur){&lt;br /&gt;
		duration = dur;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Song sng = new Song();&lt;br /&gt;
sng.setDuration(260);&lt;br /&gt;
System.out.println(&amp;quot;Song duration = &amp;quot;+sng.duration);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As seen above, a method is always called using parenthesis, within which arguments may be included if required. However, instance variable is accessed directly.&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;br /&gt;
&amp;lt;p&amp;gt;The usage syntax of methods, instance variables, getters and setters is in the table below&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Programming Languages&lt;br /&gt;
!Method call&lt;br /&gt;
!Fields/Attributes&lt;br /&gt;
!Getter / Setter&lt;br /&gt;
!Comparison&lt;br /&gt;
|-&lt;br /&gt;
|ABAP (Advanced Business Application Programming)&lt;br /&gt;
|CALL METHOD &amp;lt;meth&amp;gt; EXPORTING... &amp;lt;ii&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   IMPORTING... &amp;lt;ei&amp;gt; =.&amp;lt;g i&amp;gt;... &lt;br /&gt;
                   CHANGING ... &amp;lt;ci&amp;gt; =.&amp;lt;f i&amp;gt;... &lt;br /&gt;
                   RECEIVING         r = h &lt;br /&gt;
                   EXCEPTIONS... &amp;lt;ei&amp;gt; = rc i...&lt;br /&gt;
|&amp;lt;b&amp;gt;data&amp;lt;/b&amp;gt; field &amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt; type&lt;br /&gt;
|Same as other methods with the only difference that they start with SET or GET&lt;br /&gt;
|Syntax is different for method calls and instance-variable reference&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46990</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46990"/>
		<updated>2011-09-08T00:21:52Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
&amp;lt;p&amp;gt;A running debate in O-O languages is whether method calls and instance-variable references should have the same syntax. Different programming languages implement this in different ways. Let's look at them by examples.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Ruby use the same syntax for method calls and variable references. There is no distinction between these. We can see this in the example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song&lt;br /&gt;
  def duration=(newDuration)&lt;br /&gt;
    @duration = newDuration&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
aSong = Song.new(&amp;quot;Bicylops&amp;quot;, &amp;quot;Fleck&amp;quot;, 260)&lt;br /&gt;
aSong.duration	»	260&lt;br /&gt;
aSong.duration = 257   # set attribute with updated value&lt;br /&gt;
aSong.duration	»	257&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it simpler for the programmer to code. Also, it presents uniformity in the code.&lt;br /&gt;
&lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Java employ different syntax for method calls and variable references as seen in this example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song{&lt;br /&gt;
	int duration;&lt;br /&gt;
	Song(){}&lt;br /&gt;
	void setDuration(int dur){&lt;br /&gt;
		duration = dur;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Song sng = new Song();&lt;br /&gt;
sng.setDuration(260);&lt;br /&gt;
System.out.println(&amp;quot;Song duration = &amp;quot;+sng.duration);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As seen above, a method is always called using parenthesis, within which arguments may be included if required. However, instance variable is accessed directly.&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;br /&gt;
&amp;lt;p&amp;gt;The usage syntax of methods, instance variables, getters and setters is in the table below&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Programming Languages&lt;br /&gt;
!Method call&lt;br /&gt;
!Fields/Attributes&lt;br /&gt;
!Getter / Setter&lt;br /&gt;
!Comparison&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46987</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46987"/>
		<updated>2011-09-08T00:14:45Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
&amp;lt;p&amp;gt;A running debate in O-O languages is whether method calls and instance-variable references should have the same syntax. Different programming languages implement this in different ways. Let's look at them by examples.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Ruby use the same syntax for method calls and variable references. There is no distinction between these. We can see this in the example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song&lt;br /&gt;
  def duration=(newDuration)&lt;br /&gt;
    @duration = newDuration&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
aSong = Song.new(&amp;quot;Bicylops&amp;quot;, &amp;quot;Fleck&amp;quot;, 260)&lt;br /&gt;
aSong.duration	»	260&lt;br /&gt;
aSong.duration = 257   # set attribute with updated value&lt;br /&gt;
aSong.duration	»	257&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it simpler for the programmer to code. Also, it presents uniformity in the code.&lt;br /&gt;
&lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Java employ different syntax for method calls and variable references as seen in this example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song{&lt;br /&gt;
	int duration;&lt;br /&gt;
	Song(){}&lt;br /&gt;
	void setDuration(int dur){&lt;br /&gt;
		duration = dur;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Song sng = new Song();&lt;br /&gt;
sng.setDuration(260);&lt;br /&gt;
System.out.println(&amp;quot;Song duration = &amp;quot;+sng.duration);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As seen above, a method is always called using parenthesis, within which arguments may be included if required. However, instance variable is accessed directly.&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46960</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46960"/>
		<updated>2011-09-07T23:52:26Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
&amp;lt;p&amp;gt;A running debate in O-O languages is whether method calls and instance-variable references should have the same syntax. Different programming languages implement this in different ways. Let's look at them by examples.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Languages like Ruby use the same syntax for method calls and variable references. There is no distinction between these. We can see this in the example below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Song&lt;br /&gt;
  def duration=(newDuration)&lt;br /&gt;
    @duration = newDuration&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
aSong = Song.new(&amp;quot;Bicylops&amp;quot;, &amp;quot;Fleck&amp;quot;, 260)&lt;br /&gt;
aSong.duration	»	260&lt;br /&gt;
aSong.duration = 257   # set attribute with updated value&lt;br /&gt;
aSong.duration	»	257&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The advantage of this is that it increases &lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
&amp;lt;p&amp;gt;Java&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46946</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46946"/>
		<updated>2011-09-07T23:34:10Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Method call / Instance Variable reference Syntax ==&lt;br /&gt;
=== Same Syntax ===&lt;br /&gt;
Ruby&lt;br /&gt;
&lt;br /&gt;
=== Differing Syntax ===&lt;br /&gt;
Java&lt;br /&gt;
&lt;br /&gt;
== Comparison of syntax between various Programming Languages ==&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46940</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46940"/>
		<updated>2011-09-07T23:26:12Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 3rd header ==&lt;br /&gt;
&lt;br /&gt;
== 4th header ==&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46937</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46937"/>
		<updated>2011-09-07T23:24:58Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects - Attributes and Methods ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In the above pseudo code, the attributes define the object and the methods provide a way of achieving the desired functionality from that object. The methods use the attributes to manipulate the object and achieve the functionality. From this we can observe that this manipulation is the very essence of programming using objects. Therefore the access of attributes and way of defining method calls very important in OOP.&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46934</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46934"/>
		<updated>2011-09-07T23:18:39Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46932</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46932"/>
		<updated>2011-09-07T23:18:03Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world i.e it's modeled around data rather than logic. Objects form the basis of OOP. Let us now look at objects, their manipulation and the ways to do so.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Similar to real world objects, software objects also consist of state and related behavior. An object stores it's state in &amp;lt;i&amp;gt;attributes&amp;lt;/i&amp;gt; and exposes its behavior through &amp;lt;i&amp;gt;methods&amp;lt;/i&amp;gt;. Let's look at the pseudo code for a bicycle object.&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[File:concepts-object.gif]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr colspan=&amp;quot;2&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CLASS Bicycle&lt;br /&gt;
ATTRIBUTES:&lt;br /&gt;
	speed: NUMBER&lt;br /&gt;
	gear: NUMBER&lt;br /&gt;
	pedal_cadence: NUMBER&lt;br /&gt;
METHODS:&lt;br /&gt;
	ride(speed)&lt;br /&gt;
	changeGear(gear)&lt;br /&gt;
	changeCadence(pedal_cadence)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Concepts-object.gif&amp;diff=46923</id>
		<title>File:Concepts-object.gif</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Concepts-object.gif&amp;diff=46923"/>
		<updated>2011-09-07T22:50:21Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46921</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46921"/>
		<updated>2011-09-07T22:49:38Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:concepts-object.gif]]&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rambo&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Attributes ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Methods ===&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46917</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46917"/>
		<updated>2011-09-07T22:47:05Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:http://download.oracle.com/javase/tutorial/figures/java/concepts-object.gif]]&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objects ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rambo&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Attributes ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Methods ===&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46893</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46893"/>
		<updated>2011-09-07T20:38:58Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming/ Object Oriented Programming] is to make programs model things the way people think or deal with the world.&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46891</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46891"/>
		<updated>2011-09-07T20:37:51Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=5&amp;gt;Common Attribute/Member Syntax&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Different object oriented programming languages include different ways of accessing the member variables and methods. This page discusses the various usages and their advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&amp;lt;p&amp;gt;The purpose of [http://en.wikipedia.org/wiki/Object-oriented_programming]Object Oriented Programming&amp;lt;/p&amp;gt; is to make programs model things the way people think or deal with the world.&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46337</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_ps&amp;diff=46337"/>
		<updated>2011-09-07T00:37:51Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: Created page with &amp;quot;'''Common Attribute/Member Syntax''' ==Team== 1. Smitha Kalkere Sudarshan 2. Pradeep Kumar Ramaswamy&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Common Attribute/Member Syntax'''&lt;br /&gt;
==Team==&lt;br /&gt;
1. Smitha Kalkere Sudarshan&lt;br /&gt;
2. Pradeep Kumar Ramaswamy&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011&amp;diff=46089</id>
		<title>CSC/ECE 517 Fall 2011</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011&amp;diff=46089"/>
		<updated>2011-09-05T22:34:50Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE 517 Fall 2011/ch1 1a ms]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1a ri]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1b sa]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1b ds]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1c cm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1c sj]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1c ka]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1d sr]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1e vs]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e aa]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e dm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1g vn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e lm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1f sv]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1g jn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1h ps]]&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011&amp;diff=45963</id>
		<title>CSC/ECE 517 Fall 2011</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011&amp;diff=45963"/>
		<updated>2011-09-05T19:30:51Z</updated>

		<summary type="html">&lt;p&gt;Kkalker: a new page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE 517 Fall 2011/ch1 1a ms]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1a ri]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1b sa]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1b ds]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1c cm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1c sj]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1d sr]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1e vs]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e aa]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e dm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1g vn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e lm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1f sv]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1g jn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1g ps]]&lt;/div&gt;</summary>
		<author><name>Kkalker</name></author>
	</entry>
</feed>