<?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=Pnphadni</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=Pnphadni"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Pnphadni"/>
	<updated>2026-08-14T10:01:33Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9888</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9888"/>
		<updated>2007-11-27T04:48:43Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract [http://en.wikipedia.org/wiki/Design_by_contract] is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Preconditions -''' [http://en.wikipedia.org/wiki/Precondition] Certain obligations need to be fulfilled by any module which calls the software component are called as pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Postconditions -''' [http://en.wikipedia.org/wiki/Postcondition] The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Class invariant -''' [http://en.wikipedia.org/wiki/Invariant_%28computer_science%29] The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on exit, called the class invariant.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive. This will always be satisfied, since, the getage() method returns the value of the same variable that is set using the setage() method, and the setage() method will never allow that value to be negative.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stack of integers===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Stack {&lt;br /&gt;
&lt;br /&gt;
/* @ public invariant&lt;br /&gt;
   @ \forall (isValidstack() == true)&lt;br /&gt;
     \forall (s.isEmpty == true &amp;lt;==&amp;gt; s.pop() == -1)&lt;br /&gt;
   @ */&lt;br /&gt;
&lt;br /&gt;
public Stack() { ... }&lt;br /&gt;
&lt;br /&gt;
/*@ normal behavior //non-exceptional specification&lt;br /&gt;
  @  // precondition&lt;br /&gt;
  @  requires i &amp;gt; 0&lt;br /&gt;
  @  requires i % 1 == 0&lt;br /&gt;
  @  //postcondition&lt;br /&gt;
  @  ensures \this.toString != \old.toString&lt;br /&gt;
  @  ensures \this.size() == \old.size + 1&lt;br /&gt;
  @  ensures \this.top() == i&lt;br /&gt;
  @  ensures \this.contains(i) == true&lt;br /&gt;
  @  ensures \this.pop() == \old&lt;br /&gt;
  @ */&lt;br /&gt;
&lt;br /&gt;
//push adds a given element to the top of the stack leaving previous elements below&lt;br /&gt;
public void push(int i){ ... }&lt;br /&gt;
&lt;br /&gt;
// pop removes the current top element of the stack&lt;br /&gt;
public int top() { ... }&lt;br /&gt;
&lt;br /&gt;
// isEmpty checks whether the stack is empty or not&lt;br /&gt;
public boolean isEmpty() { ... }&lt;br /&gt;
&lt;br /&gt;
//contains checks whether the stack contains the given element or not&lt;br /&gt;
public boolean contains(int i) { ... }&lt;br /&gt;
&lt;br /&gt;
//size queries the number of elements stored in the stack&lt;br /&gt;
public int size() { ... }&lt;br /&gt;
&lt;br /&gt;
/* toString returns a string to represent the stack content. For example, it returns &lt;br /&gt;
&amp;quot; &amp;quot; for an empty stack; &amp;quot;8;&amp;quot; for a stack containing only one element 8, &amp;quot;8;9;&amp;quot; for a &lt;br /&gt;
stack containing 2 elements 8 and 9 */&lt;br /&gt;
public String toString() { ... }&lt;br /&gt;
&lt;br /&gt;
//isValidStack checks whether the stack has valid state; &lt;br /&gt;
public boolean isValidStack();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above implementation shows a stack of positive integers. The stack has no limit on the number of elements in it.&lt;br /&gt;
The fact that the stack is a valid one is always true. Also, whenever a pop operation is done on an empty stack, a value of -1 is returned. Since these two things never change, they are the class invariants.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever any element is to be added to the stack, the client needs to make sure that the element is positive and that it is an integer. These two requirements are the preconditions.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also, the stack needs to ensure that whenever a push operation is performed on it, the old stack and the new resulting stack are never the same and the size of the new stack is one more than that of the old one. It also needs to ensure, that the top method always returns the latest inserted element i and if that element i is popped out, the resulting stack is the same as the old one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References &amp;amp; External Links==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;http://www.artima.com/intv/contracts.html&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://archive.eiffel.com/doc/manuals/technology/contract/&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://www.developer.com/lang/article.php/10924_3642656_1&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://wwwse.inf.tu-dresden.de/data/courses/ws07/lab/session2.pdf&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Design_by_contract&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Precondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Postcondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Invariant_%28computer_science%29&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9886</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9886"/>
		<updated>2007-11-27T04:48:01Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract [http://en.wikipedia.org/wiki/Design_by_contract] is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Preconditions -''' [http://en.wikipedia.org/wiki/Precondition] Certain obligations need to be fulfilled by any module which calls the software component are called as pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Postconditions -''' [http://en.wikipedia.org/wiki/Postcondition] The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Class invariant -''' [http://en.wikipedia.org/wiki/Invariant_%28computer_science%29] The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on exit, called the class invariant.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive. This will always be satisfied, since, the getage() method returns the value of the same variable that is set using the setage() method, and the setage() method will never allow that value to be negative.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stack of integers===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Stack {&lt;br /&gt;
&lt;br /&gt;
/* @ public invariant&lt;br /&gt;
   @ \forall (isValidstack() == true)&lt;br /&gt;
     \forall (s.isEmpty == true &amp;lt;==&amp;gt; s.pop() == -1)&lt;br /&gt;
   @ */&lt;br /&gt;
&lt;br /&gt;
public Stack() { ... }&lt;br /&gt;
&lt;br /&gt;
/*@ normal behavior //non-exceptional specification&lt;br /&gt;
  @  // precondition&lt;br /&gt;
  @  requires i &amp;gt; 0&lt;br /&gt;
  @  requires i % 1 == 0&lt;br /&gt;
  @  //postcondition&lt;br /&gt;
  @  ensures \this.toString != \old.toString&lt;br /&gt;
  @  ensures \this.size() == \old.size + 1&lt;br /&gt;
  @  ensures \this.top() == i&lt;br /&gt;
  @  ensures \this.contains(i) == true&lt;br /&gt;
  @  ensures \this.pop() == \old&lt;br /&gt;
  @ */&lt;br /&gt;
&lt;br /&gt;
//push adds a given element to the top of the stack leaving previous elements below&lt;br /&gt;
public void push(int i){ ... }&lt;br /&gt;
&lt;br /&gt;
// pop removes the current top element of the stack&lt;br /&gt;
public int top() { ... }&lt;br /&gt;
&lt;br /&gt;
// isEmpty checks whether the stack is empty or not&lt;br /&gt;
public boolean isEmpty() { ... }&lt;br /&gt;
&lt;br /&gt;
//contains checks whether the stack contains the given element or not&lt;br /&gt;
public boolean contains(int i) { ... }&lt;br /&gt;
&lt;br /&gt;
//size queries the number of elements stored in the stack&lt;br /&gt;
public int size() { ... }&lt;br /&gt;
&lt;br /&gt;
/* toString returns a string to represent the stack content. For example, it returns &lt;br /&gt;
&amp;quot; &amp;quot; for an empty stack; &amp;quot;8;&amp;quot; for a stack containing only one element 8, &amp;quot;8;9;&amp;quot; for a &lt;br /&gt;
stack containing 2 elements 8 and 9 */&lt;br /&gt;
public String toString() { ... }&lt;br /&gt;
&lt;br /&gt;
//isValidStack checks whether the stack has valid state; &lt;br /&gt;
public boolean isValidStack();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above implementation shows a stack of positive integers. The stack has no limit on the number of elements in it.&lt;br /&gt;
The fact that the stack is a valid one is always true. Also, whenever a pop operation is done on an empty stack, a value of -1 is returned. Since these two things never change, they are the class invariants.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever any element is to be added to the stack, the client needs to make sure that the element is positive and that it is an integer. These two requirements are the preconditions.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also, the stack needs to ensure that whenever a push operation is performed on it, the old stack and the new resulting stack are never the same and the size of the new stack is one more than that of the old one. It also needs to ensure, that the top method always returns the latest inserted element i and if that element i is popped out, the resulting stack is the same as the old one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References &amp;amp; External Links==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;http://www.artima.com/intv/contracts.html&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://archive.eiffel.com/doc/manuals/technology/contract/&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://www.developer.com/lang/article.php/10924_3642656_1&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://wwwse.inf.tu-dresden.de/data/courses/ws07/lab/session2.pdf&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Design_by_contract&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Precondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Postcondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Invariant_%28computer_science%29&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9880</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9880"/>
		<updated>2007-11-27T04:39:18Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract [http://en.wikipedia.org/wiki/Design_by_contract] is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Preconditions -''' [http://en.wikipedia.org/wiki/Precondition] Certain obligations need to be fulfilled by any module which calls the software component are called as pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Postconditions -''' [http://en.wikipedia.org/wiki/Postcondition] The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Class invariant -''' [http://en.wikipedia.org/wiki/Invariant_%28computer_science%29] The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on exit, called the class invariant.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive. This will always be satisfied, since, the getage() method returns the value of the same variable that is set using the setage() method, and the setage() method will never allow that value to be negative.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stack of integers===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Stack {&lt;br /&gt;
&lt;br /&gt;
/* @ public invariant&lt;br /&gt;
   @ \forall (isValidstack() == true)&lt;br /&gt;
     \forall (s.isEmpty == true &amp;lt;==&amp;gt; s.pop() == -1)&lt;br /&gt;
   @ */&lt;br /&gt;
&lt;br /&gt;
public Stack() { ... }&lt;br /&gt;
&lt;br /&gt;
/*@ normal behavior //non-exceptional specification&lt;br /&gt;
  @  // precondition&lt;br /&gt;
  @  requires i &amp;gt; 0&lt;br /&gt;
  @  requires i % 1 == 0&lt;br /&gt;
  @  //postcondition&lt;br /&gt;
  @  ensures \this.toString != \old.toString&lt;br /&gt;
  @  ensures \this.size() == \old.size + 1&lt;br /&gt;
  @  ensures \this.top() == i&lt;br /&gt;
  @  ensures \this.contains(i) == true&lt;br /&gt;
  @  ensures \this.pop() == \old&lt;br /&gt;
  @ */&lt;br /&gt;
&lt;br /&gt;
//push adds a given element to the top of the stack leaving previous elements below&lt;br /&gt;
public void push(int i){ ... }&lt;br /&gt;
&lt;br /&gt;
// pop removes the current top element of the stack&lt;br /&gt;
public int top() { ... }&lt;br /&gt;
&lt;br /&gt;
// isEmpty checks whether the stack is empty or not&lt;br /&gt;
public boolean isEmpty() { ... }&lt;br /&gt;
&lt;br /&gt;
//contains checks whether the stack contains the given element or not&lt;br /&gt;
public boolean contains(int i) { ... }&lt;br /&gt;
&lt;br /&gt;
//size queries the number of elements stored in the stack&lt;br /&gt;
public int size() { ... }&lt;br /&gt;
&lt;br /&gt;
/* toString returns a string to represent the stack content. For example, it returns &lt;br /&gt;
&amp;quot; &amp;quot; for an empty stack; &amp;quot;8;&amp;quot; for a stack containing only one element 8, &amp;quot;8;9;&amp;quot; for a &lt;br /&gt;
stack containing 2 elements 8 and 9 */&lt;br /&gt;
public String toString() { ... }&lt;br /&gt;
&lt;br /&gt;
//isValidStack checks whether the stack has valid state; &lt;br /&gt;
public boolean isValidStack();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above implementation shows a stack of positive integers. The stack has no limit on the number of elements in it.&lt;br /&gt;
The fact that the stack is a valid one is always true. Also, whenever a pop operation is done on an empty stack, a value of -1 is returned. Since these two things never change, they are the class invariants.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever any element is to be added to the stack, the client needs to make sure that the element is positive and that it is an integer. These two requirements are the preconditions.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also, the stack needs to ensure that whenever a push operation is performed on it, the old stack and the new resulting stack are never the same and the size of the new stack is one more than that of the old one. It also needs to ensure, that the top method always returns the latest inserted element i and if that element i is popped out, the resulting stack is the same as the old one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References &amp;amp; External Links==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Design_by_contract&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Precondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Postcondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Invariant_%28computer_science%29&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://www.artima.com/intv/contracts.html&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://archive.eiffel.com/doc/manuals/technology/contract/&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9879</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9879"/>
		<updated>2007-11-27T04:37:33Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract [http://en.wikipedia.org/wiki/Design_by_contract] is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Preconditions -''' [http://en.wikipedia.org/wiki/Precondition] Certain obligations need to be fulfilled by any module which calls the software component are called as pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Postconditions -''' [http://en.wikipedia.org/wiki/Postcondition] The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Class invariant -''' [http://en.wikipedia.org/wiki/Invariant_%28computer_science%29] The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on exit, called the class invariant.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive. This will always be satisfied, since, the getage() method returns the value of the same variable that is set using the setage() method.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stack of integers===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Stack {&lt;br /&gt;
&lt;br /&gt;
/* @ public invariant&lt;br /&gt;
   @ \forall (isValidstack() == true)&lt;br /&gt;
     \forall (s.isEmpty == true &amp;lt;==&amp;gt; s.pop() == -1)&lt;br /&gt;
   @ */&lt;br /&gt;
&lt;br /&gt;
public Stack() { ... }&lt;br /&gt;
&lt;br /&gt;
/*@ normal behavior //non-exceptional specification&lt;br /&gt;
  @  // precondition&lt;br /&gt;
  @  requires i &amp;gt; 0&lt;br /&gt;
  @  requires i % 1 == 0&lt;br /&gt;
  @  //postcondition&lt;br /&gt;
  @  ensures \this.toString != \old.toString&lt;br /&gt;
  @  ensures \this.size() == \old.size + 1&lt;br /&gt;
  @  ensures \this.top() == i&lt;br /&gt;
  @  ensures \this.contains(i) == true&lt;br /&gt;
  @  ensures \this.pop() == \old&lt;br /&gt;
  @ */&lt;br /&gt;
&lt;br /&gt;
//push adds a given element to the top of the stack leaving previous elements below&lt;br /&gt;
public void push(int i){ ... }&lt;br /&gt;
&lt;br /&gt;
// pop removes the current top element of the stack&lt;br /&gt;
public int top() { ... }&lt;br /&gt;
&lt;br /&gt;
// isEmpty checks whether the stack is empty or not&lt;br /&gt;
public boolean isEmpty() { ... }&lt;br /&gt;
&lt;br /&gt;
//contains checks whether the stack contains the given element or not&lt;br /&gt;
public boolean contains(int i) { ... }&lt;br /&gt;
&lt;br /&gt;
//size queries the number of elements stored in the stack&lt;br /&gt;
public int size() { ... }&lt;br /&gt;
&lt;br /&gt;
/* toString returns a string to represent the stack content. For example, it returns &lt;br /&gt;
&amp;quot; &amp;quot; for an empty stack; &amp;quot;8;&amp;quot; for a stack containing only one element 8, &amp;quot;8;9;&amp;quot; for a &lt;br /&gt;
stack containing 2 elements 8 and 9 */&lt;br /&gt;
public String toString() { ... }&lt;br /&gt;
&lt;br /&gt;
//isValidStack checks whether the stack has valid state; &lt;br /&gt;
public boolean isValidStack();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above implementation shows a stack of positive integers. The stack has no limit on the number of elements in it.&lt;br /&gt;
The fact that the stack is a valid one is always true. Also, whenever a pop operation is done on an empty stack, a value of -1 is returned. Since these two things never change, they are the class invariants.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever any element is to be added to the stack, the client needs to make sure that the element is positive and that it is an integer. These two requirements are the preconditions.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also, the stack needs to ensure that whenever a push operation is performed on it, the old stack and the new resulting stack are never the same and the size of the new stack is one more than that of the old one. It also needs to ensure, that the top method always returns the latest inserted element i and if that element i is popped out, the resulting stack is the same as the old one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References &amp;amp; External Links==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Design_by_contract&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Precondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Postcondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Invariant_%28computer_science%29&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://www.artima.com/intv/contracts.html&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://archive.eiffel.com/doc/manuals/technology/contract/&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9878</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9878"/>
		<updated>2007-11-27T04:34:53Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract [http://en.wikipedia.org/wiki/Design_by_contract] is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Preconditions -''' [http://en.wikipedia.org/wiki/Precondition] Certain obligations need to be fulfilled by any module which calls the software component are called as pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Postconditions -''' [http://en.wikipedia.org/wiki/Postcondition] The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Class invariant -''' [http://en.wikipedia.org/wiki/Invariant_%28computer_science%29] The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on exit, called the class invariant.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stack of integers===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Stack {&lt;br /&gt;
&lt;br /&gt;
/* @ public invariant&lt;br /&gt;
   @ \forall (isValidstack() == true)&lt;br /&gt;
     \forall (s.isEmpty == true &amp;lt;==&amp;gt; s.pop() == -1)&lt;br /&gt;
   @ */&lt;br /&gt;
&lt;br /&gt;
public Stack() { ... }&lt;br /&gt;
&lt;br /&gt;
/*@ normal behavior //non-exceptional specification&lt;br /&gt;
  @  // precondition&lt;br /&gt;
  @  requires i &amp;gt; 0&lt;br /&gt;
  @  requires i % 1 == 0&lt;br /&gt;
  @  //postcondition&lt;br /&gt;
  @  ensures \this.toString != \old.toString&lt;br /&gt;
  @  ensures \this.size() == \old.size + 1&lt;br /&gt;
  @  ensures \this.top() == i&lt;br /&gt;
  @  ensures \this.contains(i) == true&lt;br /&gt;
  @  ensures \this.pop() == \old&lt;br /&gt;
  @ */&lt;br /&gt;
&lt;br /&gt;
//push adds a given element to the top of the stack leaving previous elements below&lt;br /&gt;
public void push(int i){ ... }&lt;br /&gt;
&lt;br /&gt;
// pop removes the current top element of the stack&lt;br /&gt;
public int top() { ... }&lt;br /&gt;
&lt;br /&gt;
// isEmpty checks whether the stack is empty or not&lt;br /&gt;
public boolean isEmpty() { ... }&lt;br /&gt;
&lt;br /&gt;
//contains checks whether the stack contains the given element or not&lt;br /&gt;
public boolean contains(int i) { ... }&lt;br /&gt;
&lt;br /&gt;
//size queries the number of elements stored in the stack&lt;br /&gt;
public int size() { ... }&lt;br /&gt;
&lt;br /&gt;
/* toString returns a string to represent the stack content. For example, it returns &lt;br /&gt;
&amp;quot; &amp;quot; for an empty stack; &amp;quot;8;&amp;quot; for a stack containing only one element 8, &amp;quot;8;9;&amp;quot; for a &lt;br /&gt;
stack containing 2 elements 8 and 9 */&lt;br /&gt;
public String toString() { ... }&lt;br /&gt;
&lt;br /&gt;
//isValidStack checks whether the stack has valid state; &lt;br /&gt;
public boolean isValidStack();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above implementation shows a stack of positive integers. The stack has no limit on the number of elements in it.&lt;br /&gt;
The fact that the stack is a valid one is always true. Also, whenever a pop operation is done on an empty stack, a value of -1 is returned. Since these two things never change, they are the class invariants.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever any element is to be added to the stack, the client needs to make sure that the element is positive and that it is an integer. These two requirements are the preconditions.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also, the stack needs to ensure that whenever a push operation is performed on it, the old stack and the new resulting stack are never the same and the size of the new stack is one more than that of the old one. It also needs to ensure, that the top method always returns the latest inserted element i and if that element i is popped out, the resulting stack is the same as the old one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References &amp;amp; External Links==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Design_by_contract&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Precondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Postcondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Invariant_%28computer_science%29&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://www.artima.com/intv/contracts.html&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://archive.eiffel.com/doc/manuals/technology/contract/&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9877</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9877"/>
		<updated>2007-11-27T04:32:45Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract [http://en.wikipedia.org/wiki/Design_by_contract] is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Preconditions -''' Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Postconditions -''' The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•  '''Class invariant -''' The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stack of integers===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Stack {&lt;br /&gt;
&lt;br /&gt;
/* @ public invariant&lt;br /&gt;
   @ \forall (isValidstack() == true)&lt;br /&gt;
     \forall (s.isEmpty == true &amp;lt;==&amp;gt; s.pop() == -1)&lt;br /&gt;
   @ */&lt;br /&gt;
&lt;br /&gt;
public Stack() { ... }&lt;br /&gt;
&lt;br /&gt;
/*@ normal behavior //non-exceptional specification&lt;br /&gt;
  @  // precondition&lt;br /&gt;
  @  requires i &amp;gt; 0&lt;br /&gt;
  @  requires i % 1 == 0&lt;br /&gt;
  @  //postcondition&lt;br /&gt;
  @  ensures \this.toString != \old.toString&lt;br /&gt;
  @  ensures \this.size() == \old.size + 1&lt;br /&gt;
  @  ensures \this.top() == i&lt;br /&gt;
  @  ensures \this.contains(i) == true&lt;br /&gt;
  @  ensures \this.pop() == \old&lt;br /&gt;
  @ */&lt;br /&gt;
&lt;br /&gt;
//push adds a given element to the top of the stack leaving previous elements below&lt;br /&gt;
public void push(int i){ ... }&lt;br /&gt;
&lt;br /&gt;
// pop removes the current top element of the stack&lt;br /&gt;
public int top() { ... }&lt;br /&gt;
&lt;br /&gt;
// isEmpty checks whether the stack is empty or not&lt;br /&gt;
public boolean isEmpty() { ... }&lt;br /&gt;
&lt;br /&gt;
//contains checks whether the stack contains the given element or not&lt;br /&gt;
public boolean contains(int i) { ... }&lt;br /&gt;
&lt;br /&gt;
//size queries the number of elements stored in the stack&lt;br /&gt;
public int size() { ... }&lt;br /&gt;
&lt;br /&gt;
/* toString returns a string to represent the stack content. For example, it returns &lt;br /&gt;
&amp;quot; &amp;quot; for an empty stack; &amp;quot;8;&amp;quot; for a stack containing only one element 8, &amp;quot;8;9;&amp;quot; for a &lt;br /&gt;
stack containing 2 elements 8 and 9 */&lt;br /&gt;
public String toString() { ... }&lt;br /&gt;
&lt;br /&gt;
//isValidStack checks whether the stack has valid state; &lt;br /&gt;
public boolean isValidStack();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above implementation shows a stack of positive integers. The stack has no limit on the number of elements in it.&lt;br /&gt;
The fact that the stack is a valid one is always true. Also, whenever a pop operation is done on an empty stack, a value of -1 is returned. Since these two things never change, they are the class invariants.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever any element is to be added to the stack, the client needs to make sure that the element is positive and that it is an integer. These two requirements are the preconditions.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also, the stack needs to ensure that whenever a push operation is performed on it, the old stack and the new resulting stack are never the same and the size of the new stack is one more than that of the old one. It also needs to ensure, that the top method always returns the latest inserted element i and if that element i is popped out, the resulting stack is the same as the old one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References &amp;amp; External Links==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Design_by_contract&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Precondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Postcondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Invariant_%28computer_science%29&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://www.artima.com/intv/contracts.html&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://archive.eiffel.com/doc/manuals/technology/contract/&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9876</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9876"/>
		<updated>2007-11-27T04:29:51Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract [http://en.wikipedia.org/wiki/Design_by_contract] is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stack of integers===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Stack {&lt;br /&gt;
&lt;br /&gt;
/* @ public invariant&lt;br /&gt;
   @ \forall (isValidstack() == true)&lt;br /&gt;
     \forall (s.isEmpty == true &amp;lt;==&amp;gt; s.pop() == -1)&lt;br /&gt;
   @ */&lt;br /&gt;
&lt;br /&gt;
public Stack() { ... }&lt;br /&gt;
&lt;br /&gt;
/*@ normal behavior //non-exceptional specification&lt;br /&gt;
  @  // precondition&lt;br /&gt;
  @  requires i &amp;gt; 0&lt;br /&gt;
  @  requires i % 1 == 0&lt;br /&gt;
  @  //postcondition&lt;br /&gt;
  @  ensures \this.toString != \old.toString&lt;br /&gt;
  @  ensures \this.size() == \old.size + 1&lt;br /&gt;
  @  ensures \this.top() == i&lt;br /&gt;
  @  ensures \this.contains(i) == true&lt;br /&gt;
  @  ensures \this.pop() == \old&lt;br /&gt;
  @ */&lt;br /&gt;
&lt;br /&gt;
//push adds a given element to the top of the stack leaving previous elements below&lt;br /&gt;
public void push(int i){ ... }&lt;br /&gt;
&lt;br /&gt;
// pop removes the current top element of the stack&lt;br /&gt;
public int top() { ... }&lt;br /&gt;
&lt;br /&gt;
// isEmpty checks whether the stack is empty or not&lt;br /&gt;
public boolean isEmpty() { ... }&lt;br /&gt;
&lt;br /&gt;
//contains checks whether the stack contains the given element or not&lt;br /&gt;
public boolean contains(int i) { ... }&lt;br /&gt;
&lt;br /&gt;
//size queries the number of elements stored in the stack&lt;br /&gt;
public int size() { ... }&lt;br /&gt;
&lt;br /&gt;
/* toString returns a string to represent the stack content. For example, it returns &lt;br /&gt;
&amp;quot; &amp;quot; for an empty stack; &amp;quot;8;&amp;quot; for a stack containing only one element 8, &amp;quot;8;9;&amp;quot; for a &lt;br /&gt;
stack containing 2 elements 8 and 9 */&lt;br /&gt;
public String toString() { ... }&lt;br /&gt;
&lt;br /&gt;
//isValidStack checks whether the stack has valid state; &lt;br /&gt;
public boolean isValidStack();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above implementation shows a stack of positive integers. The stack has no limit on the number of elements in it.&lt;br /&gt;
The fact that the stack is a valid one is always true. Also, whenever a pop operation is done on an empty stack, a value of -1 is returned. Since these two things never change, they are the class invariants.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever any element is to be added to the stack, the client needs to make sure that the element is positive and that it is an integer. These two requirements are the preconditions.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also, the stack needs to ensure that whenever a push operation is performed on it, the old stack and the new resulting stack are never the same and the size of the new stack is one more than that of the old one. It also needs to ensure, that the top method always returns the latest inserted element i and if that element i is popped out, the resulting stack is the same as the old one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References &amp;amp; External Links==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Design_by_contract&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Precondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Postcondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Invariant_%28computer_science%29&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://www.artima.com/intv/contracts.html&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://archive.eiffel.com/doc/manuals/technology/contract/&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9875</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9875"/>
		<updated>2007-11-27T04:27:28Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
[[http://en.wikipedia.org/wiki/Design_by_contract]] Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stack of integers===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Stack {&lt;br /&gt;
&lt;br /&gt;
/* @ public invariant&lt;br /&gt;
   @ \forall (isValidstack() == true)&lt;br /&gt;
     \forall (s.isEmpty == true &amp;lt;==&amp;gt; s.pop() == -1)&lt;br /&gt;
   @ */&lt;br /&gt;
&lt;br /&gt;
public Stack() { ... }&lt;br /&gt;
&lt;br /&gt;
/*@ normal behavior //non-exceptional specification&lt;br /&gt;
  @  // precondition&lt;br /&gt;
  @  requires i &amp;gt; 0&lt;br /&gt;
  @  requires i % 1 == 0&lt;br /&gt;
  @  //postcondition&lt;br /&gt;
  @  ensures \this.toString != \old.toString&lt;br /&gt;
  @  ensures \this.size() == \old.size + 1&lt;br /&gt;
  @  ensures \this.top() == i&lt;br /&gt;
  @  ensures \this.contains(i) == true&lt;br /&gt;
  @  ensures \this.pop() == \old&lt;br /&gt;
  @ */&lt;br /&gt;
&lt;br /&gt;
//push adds a given element to the top of the stack leaving previous elements below&lt;br /&gt;
public void push(int i){ ... }&lt;br /&gt;
&lt;br /&gt;
// pop removes the current top element of the stack&lt;br /&gt;
public int top() { ... }&lt;br /&gt;
&lt;br /&gt;
// isEmpty checks whether the stack is empty or not&lt;br /&gt;
public boolean isEmpty() { ... }&lt;br /&gt;
&lt;br /&gt;
//contains checks whether the stack contains the given element or not&lt;br /&gt;
public boolean contains(int i) { ... }&lt;br /&gt;
&lt;br /&gt;
//size queries the number of elements stored in the stack&lt;br /&gt;
public int size() { ... }&lt;br /&gt;
&lt;br /&gt;
/* toString returns a string to represent the stack content. For example, it returns &lt;br /&gt;
&amp;quot; &amp;quot; for an empty stack; &amp;quot;8;&amp;quot; for a stack containing only one element 8, &amp;quot;8;9;&amp;quot; for a &lt;br /&gt;
stack containing 2 elements 8 and 9 */&lt;br /&gt;
public String toString() { ... }&lt;br /&gt;
&lt;br /&gt;
//isValidStack checks whether the stack has valid state; &lt;br /&gt;
public boolean isValidStack();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above implementation shows a stack of positive integers. The stack has no limit on the number of elements in it.&lt;br /&gt;
The fact that the stack is a valid one is always true. Also, whenever a pop operation is done on an empty stack, a value of -1 is returned. Since these two things never change, they are the class invariants.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever any element is to be added to the stack, the client needs to make sure that the element is positive and that it is an integer. These two requirements are the preconditions.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also, the stack needs to ensure that whenever a push operation is performed on it, the old stack and the new resulting stack are never the same and the size of the new stack is one more than that of the old one. It also needs to ensure, that the top method always returns the latest inserted element i and if that element i is popped out, the resulting stack is the same as the old one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References &amp;amp; External Links==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Design_by_contract&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Precondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Postcondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Invariant_%28computer_science%29&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://www.artima.com/intv/contracts.html&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://archive.eiffel.com/doc/manuals/technology/contract/&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9874</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=9874"/>
		<updated>2007-11-27T04:24:48Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Design_by_contract] Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stack of integers===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Stack {&lt;br /&gt;
&lt;br /&gt;
/* @ public invariant&lt;br /&gt;
   @ \forall (isValidstack() == true)&lt;br /&gt;
     \forall (s.isEmpty == true &amp;lt;==&amp;gt; s.pop() == -1)&lt;br /&gt;
   @ */&lt;br /&gt;
&lt;br /&gt;
public Stack() { ... }&lt;br /&gt;
&lt;br /&gt;
/*@ normal behavior //non-exceptional specification&lt;br /&gt;
  @  // precondition&lt;br /&gt;
  @  requires i &amp;gt; 0&lt;br /&gt;
  @  requires i % 1 == 0&lt;br /&gt;
  @  //postcondition&lt;br /&gt;
  @  ensures \this.toString != \old.toString&lt;br /&gt;
  @  ensures \this.size() == \old.size + 1&lt;br /&gt;
  @  ensures \this.top() == i&lt;br /&gt;
  @  ensures \this.contains(i) == true&lt;br /&gt;
  @  ensures \this.pop() == \old&lt;br /&gt;
  @ */&lt;br /&gt;
&lt;br /&gt;
//push adds a given element to the top of the stack leaving previous elements below&lt;br /&gt;
public void push(int i){ ... }&lt;br /&gt;
&lt;br /&gt;
// pop removes the current top element of the stack&lt;br /&gt;
public int top() { ... }&lt;br /&gt;
&lt;br /&gt;
// isEmpty checks whether the stack is empty or not&lt;br /&gt;
public boolean isEmpty() { ... }&lt;br /&gt;
&lt;br /&gt;
//contains checks whether the stack contains the given element or not&lt;br /&gt;
public boolean contains(int i) { ... }&lt;br /&gt;
&lt;br /&gt;
//size queries the number of elements stored in the stack&lt;br /&gt;
public int size() { ... }&lt;br /&gt;
&lt;br /&gt;
/* toString returns a string to represent the stack content. For example, it returns &lt;br /&gt;
&amp;quot; &amp;quot; for an empty stack; &amp;quot;8;&amp;quot; for a stack containing only one element 8, &amp;quot;8;9;&amp;quot; for a &lt;br /&gt;
stack containing 2 elements 8 and 9 */&lt;br /&gt;
public String toString() { ... }&lt;br /&gt;
&lt;br /&gt;
//isValidStack checks whether the stack has valid state; &lt;br /&gt;
public boolean isValidStack();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above implementation shows a stack of positive integers. The stack has no limit on the number of elements in it.&lt;br /&gt;
The fact that the stack is a valid one is always true. Also, whenever a pop operation is done on an empty stack, a value of -1 is returned. Since these two things never change, they are the class invariants.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever any element is to be added to the stack, the client needs to make sure that the element is positive and that it is an integer. These two requirements are the preconditions.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also, the stack needs to ensure that whenever a push operation is performed on it, the old stack and the new resulting stack are never the same and the size of the new stack is one more than that of the old one. It also needs to ensure, that the top method always returns the latest inserted element i and if that element i is popped out, the resulting stack is the same as the old one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References &amp;amp; External Links==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Design_by_contract&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Precondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Postcondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Invariant_%28computer_science%29&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://www.artima.com/intv/contracts.html&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://archive.eiffel.com/doc/manuals/technology/contract/&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8855</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8855"/>
		<updated>2007-11-18T01:52:17Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stack of integers===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Stack {&lt;br /&gt;
&lt;br /&gt;
/* @ public invariant&lt;br /&gt;
   @ \forall (isValidstack() == true)&lt;br /&gt;
     \forall (s.isEmpty == true &amp;lt;==&amp;gt; s.pop() == -1)&lt;br /&gt;
   @ */&lt;br /&gt;
&lt;br /&gt;
public Stack() { ... }&lt;br /&gt;
&lt;br /&gt;
/*@ normal behavior //non-exceptional specification&lt;br /&gt;
  @  // precondition&lt;br /&gt;
  @  requires i &amp;gt; 0&lt;br /&gt;
  @  requires i % 1 == 0&lt;br /&gt;
  @  //postcondition&lt;br /&gt;
  @  ensures \this.toString != \old.toString&lt;br /&gt;
  @  ensures \this.size() == \old.size + 1&lt;br /&gt;
  @  ensures \this.top() == i&lt;br /&gt;
  @  ensures \this.contains(i) == true&lt;br /&gt;
  @  ensures \this.pop() == \old&lt;br /&gt;
  @ */&lt;br /&gt;
&lt;br /&gt;
//push adds a given element to the top of the stack leaving previous elements below&lt;br /&gt;
public void push(int i){ ... }&lt;br /&gt;
&lt;br /&gt;
// pop removes the current top element of the stack&lt;br /&gt;
public int top() { ... }&lt;br /&gt;
&lt;br /&gt;
// isEmpty checks whether the stack is empty or not&lt;br /&gt;
public boolean isEmpty() { ... }&lt;br /&gt;
&lt;br /&gt;
//contains checks whether the stack contains the given element or not&lt;br /&gt;
public boolean contains(int i) { ... }&lt;br /&gt;
&lt;br /&gt;
//size queries the number of elements stored in the stack&lt;br /&gt;
public int size() { ... }&lt;br /&gt;
&lt;br /&gt;
/* toString returns a string to represent the stack content. For example, it returns &lt;br /&gt;
&amp;quot; &amp;quot; for an empty stack; &amp;quot;8;&amp;quot; for a stack containing only one element 8, &amp;quot;8;9;&amp;quot; for a &lt;br /&gt;
stack containing 2 elements 8 and 9 */&lt;br /&gt;
public String toString() { ... }&lt;br /&gt;
&lt;br /&gt;
//isValidStack checks whether the stack has valid state; &lt;br /&gt;
public boolean isValidStack();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above implementation shows a stack of positive integers. The stack has no limit on the number of elements in it.&lt;br /&gt;
The fact that the stack is a valid one is always true. Also, whenever a pop operation is done on an empty stack, a value of -1 is returned. Since these two things never change, they are the class invariants.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever any element is to be added to the stack, the client needs to make sure that the element is positive and that it is an integer. These two requirements are the preconditions.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also, the stack needs to ensure that whenever a push operation is performed on it, the old stack and the new resulting stack are never the same and the size of the new stack is one more than that of the old one. It also needs to ensure, that the top method always returns the latest inserted element i and if that element i is popped out, the resulting stack is the same as the old one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References &amp;amp; External Links==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Design_by_contract&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Precondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Postcondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Invariant_%28computer_science%29&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://www.artima.com/intv/contracts.html&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://archive.eiffel.com/doc/manuals/technology/contract/&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8854</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8854"/>
		<updated>2007-11-18T01:49:21Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stack of integers===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Stack {&lt;br /&gt;
&lt;br /&gt;
/* @ public invariant&lt;br /&gt;
   @ \forall (isValidstack() == true)&lt;br /&gt;
     \forall (s.isEmpty == true &amp;lt;==&amp;gt; s.pop() == -1)&lt;br /&gt;
   @ */&lt;br /&gt;
&lt;br /&gt;
public Stack() { ... }&lt;br /&gt;
&lt;br /&gt;
/*@ normal behavior //non-exceptional specification&lt;br /&gt;
  @  // precondition&lt;br /&gt;
  @  requires i &amp;gt; 0&lt;br /&gt;
  @  requires i % 1 == 0&lt;br /&gt;
  @  //postcondition&lt;br /&gt;
  @  ensures \this.toString != \old.toString&lt;br /&gt;
  @  ensures \this.size() == \old.size + 1&lt;br /&gt;
  @  ensures \this.top() == i&lt;br /&gt;
  @  ensures \this.contains(i) == true&lt;br /&gt;
  @  ensures \this.pop() == \old&lt;br /&gt;
  @ */&lt;br /&gt;
&lt;br /&gt;
//push adds a given element to the top of the stack leaving previous elements below&lt;br /&gt;
public void push(int i){ ... }&lt;br /&gt;
&lt;br /&gt;
// pop removes the current top element of the stack&lt;br /&gt;
public int top() { ... }&lt;br /&gt;
&lt;br /&gt;
// isEmpty checks whether the stack is empty or not&lt;br /&gt;
public boolean isEmpty() { ... }&lt;br /&gt;
&lt;br /&gt;
//contains checks whether the stack contains the given element or not&lt;br /&gt;
public boolean contains(int i) { ... }&lt;br /&gt;
&lt;br /&gt;
//size queries the number of elements stored in the stack&lt;br /&gt;
public int size() { ... }&lt;br /&gt;
&lt;br /&gt;
/* toString returns a string to represent the stack content. For example, it returns &lt;br /&gt;
&amp;quot; &amp;quot; for an empty stack; &amp;quot;8;&amp;quot; for a stack containing only one element 8, &amp;quot;8;9;&amp;quot; for a &lt;br /&gt;
stack containing 2 elements 8 and 9 */&lt;br /&gt;
public String toString() { ... }&lt;br /&gt;
&lt;br /&gt;
//isValidStack checks whether the stack has valid state; &lt;br /&gt;
public boolean isValidStack();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above implementation shows a stack of positive integers. The stack has no limit on the number of elements in it.&lt;br /&gt;
The fact that the stack is a valid one is always true. Also, whenever a pop operation is done on an empty stack, a value of -1 is returned. Since these two things never change, they are the class invariants.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever any element is to be added to the stack, the client needs to make sure that the element is positive and that it is an integer. These two requirements are the preconditions.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also, the stack needs to ensure that whenever a push operation is performed on it, the old stack and the new resulting stack are never the same and the size of the new stack is one more than that of the old one. It also needs to ensure, that the top method always returns the latest inserted element i and if that element i is popped out, the resulting stack is the same as the old one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References &amp;amp; External Links==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Design_by_contract&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Precondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Postcondition&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;http://en.wikipedia.org/wiki/Invariant_%28computer_science%29&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8853</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8853"/>
		<updated>2007-11-18T01:48:27Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stack of integers===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Stack {&lt;br /&gt;
&lt;br /&gt;
/* @ public invariant&lt;br /&gt;
   @ \forall (isValidstack() == true)&lt;br /&gt;
     \forall (s.isEmpty == true &amp;lt;==&amp;gt; s.pop() == -1)&lt;br /&gt;
   @ */&lt;br /&gt;
&lt;br /&gt;
public Stack() { ... }&lt;br /&gt;
&lt;br /&gt;
/*@ normal behavior //non-exceptional specification&lt;br /&gt;
  @  // precondition&lt;br /&gt;
  @  requires i &amp;gt; 0&lt;br /&gt;
  @  requires i % 1 == 0&lt;br /&gt;
  @  //postcondition&lt;br /&gt;
  @  ensures \this.toString != \old.toString&lt;br /&gt;
  @  ensures \this.size() == \old.size + 1&lt;br /&gt;
  @  ensures \this.top() == i&lt;br /&gt;
  @  ensures \this.contains(i) == true&lt;br /&gt;
  @  ensures \this.pop() == \old&lt;br /&gt;
  @ */&lt;br /&gt;
&lt;br /&gt;
//push adds a given element to the top of the stack leaving previous elements below&lt;br /&gt;
public void push(int i){ ... }&lt;br /&gt;
&lt;br /&gt;
// pop removes the current top element of the stack&lt;br /&gt;
public int top() { ... }&lt;br /&gt;
&lt;br /&gt;
// isEmpty checks whether the stack is empty or not&lt;br /&gt;
public boolean isEmpty() { ... }&lt;br /&gt;
&lt;br /&gt;
//contains checks whether the stack contains the given element or not&lt;br /&gt;
public boolean contains(int i) { ... }&lt;br /&gt;
&lt;br /&gt;
//size queries the number of elements stored in the stack&lt;br /&gt;
public int size() { ... }&lt;br /&gt;
&lt;br /&gt;
/* toString returns a string to represent the stack content. For example, it returns &lt;br /&gt;
&amp;quot; &amp;quot; for an empty stack; &amp;quot;8;&amp;quot; for a stack containing only one element 8, &amp;quot;8;9;&amp;quot; for a &lt;br /&gt;
stack containing 2 elements 8 and 9 */&lt;br /&gt;
public String toString() { ... }&lt;br /&gt;
&lt;br /&gt;
//isValidStack checks whether the stack has valid state; &lt;br /&gt;
public boolean isValidStack();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above implementation shows a stack of positive integers. The stack has no limit on the number of elements in it.&lt;br /&gt;
The fact that the stack is a valid one is always true. Also, whenever a pop operation is done on an empty stack, a value of -1 is returned. Since these two things never change, they are the class invariants.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever any element is to be added to the stack, the client needs to make sure that the element is positive and that it is an integer. These two requirements are the preconditions.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also, the stack needs to ensure that whenever a push operation is performed on it, the old stack and the new resulting stack are never the same and the size of the new stack is one more than that of the old one. It also needs to ensure, that the top method always returns the latest inserted element i and if that element i is popped out, the resulting stack is the same as the old one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References &amp;amp; External Links==&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/Design_by_contract&lt;br /&gt;
http://en.wikipedia.org/wiki/Precondition&lt;br /&gt;
http://en.wikipedia.org/wiki/Postcondition&lt;br /&gt;
http://en.wikipedia.org/wiki/Invariant_%28computer_science%29&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8852</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8852"/>
		<updated>2007-11-18T01:46:30Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stack of integers===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Stack {&lt;br /&gt;
&lt;br /&gt;
/* @ public invariant&lt;br /&gt;
   @ \forall (isValidstack() == true)&lt;br /&gt;
     \forall (s.isEmpty == true &amp;lt;==&amp;gt; s.pop() == -1)&lt;br /&gt;
   @ */&lt;br /&gt;
&lt;br /&gt;
public Stack() { ... }&lt;br /&gt;
&lt;br /&gt;
/*@ normal behavior //non-exceptional specification&lt;br /&gt;
  @  // precondition&lt;br /&gt;
  @  requires i &amp;gt; 0&lt;br /&gt;
  @  requires i % 1 == 0&lt;br /&gt;
  @  //postcondition&lt;br /&gt;
  @  ensures \this.toString != \old.toString&lt;br /&gt;
  @  ensures \this.size() == \old.size + 1&lt;br /&gt;
  @  ensures \this.top() == i&lt;br /&gt;
  @  ensures \this.contains(i) == true&lt;br /&gt;
  @  ensures \this.pop() == \old&lt;br /&gt;
  @ */&lt;br /&gt;
&lt;br /&gt;
//push adds a given element to the top of the stack leaving previous elements below&lt;br /&gt;
public void push(int i){ ... }&lt;br /&gt;
&lt;br /&gt;
// pop removes the current top element of the stack&lt;br /&gt;
public int top() { ... }&lt;br /&gt;
&lt;br /&gt;
// isEmpty checks whether the stack is empty or not&lt;br /&gt;
public boolean isEmpty() { ... }&lt;br /&gt;
&lt;br /&gt;
//contains checks whether the stack contains the given element or not&lt;br /&gt;
public boolean contains(int i) { ... }&lt;br /&gt;
&lt;br /&gt;
//size queries the number of elements stored in the stack&lt;br /&gt;
public int size() { ... }&lt;br /&gt;
&lt;br /&gt;
/* toString returns a string to represent the stack content. For example, it returns &lt;br /&gt;
&amp;quot; &amp;quot; for an empty stack; &amp;quot;8;&amp;quot; for a stack containing only one element 8, &amp;quot;8;9;&amp;quot; for a &lt;br /&gt;
stack containing 2 elements 8 and 9 */&lt;br /&gt;
public String toString() { ... }&lt;br /&gt;
&lt;br /&gt;
//isValidStack checks whether the stack has valid state; &lt;br /&gt;
public boolean isValidStack();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above implementation shows a stack of positive integers. The stack has no limit on the number of elements in it.&lt;br /&gt;
The fact that the stack is a valid one is always true. Also, whenever a pop operation is done on an empty stack, a value of -1 is returned. Since these two things never change, they are the class invariants.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever any element is to be added to the stack, the client needs to make sure that the element is positive and that it is an integer. These two requirements are the preconditions.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also, the stack needs to ensure that whenever a push operation is performed on it, the old stack and the new resulting stack are never the same and the size of the new stack is one more than that of the old one. It also needs to ensure, that the top method always returns the latest inserted element i and if that element i is popped out, the resulting stack is the same as the old one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
(1) http://en.wikipedia.org/wiki/Design_by_contract&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8851</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8851"/>
		<updated>2007-11-18T01:20:50Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stack of integers===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Stack {&lt;br /&gt;
&lt;br /&gt;
/* @ public invariant&lt;br /&gt;
   @ \forall (isValidstack() == true)&lt;br /&gt;
     \forall (s.isEmpty == true &amp;lt;==&amp;gt; s.pop() == -1)&lt;br /&gt;
   @ */&lt;br /&gt;
&lt;br /&gt;
public Stack() { ... }&lt;br /&gt;
&lt;br /&gt;
/*@ normal behavior //non-exceptional specification&lt;br /&gt;
  @  // precondition&lt;br /&gt;
  @  requires i &amp;gt; 0&lt;br /&gt;
  @  requires i % 1 == 0&lt;br /&gt;
  @  //postcondition&lt;br /&gt;
  @  ensures \this.toString != \old.toString&lt;br /&gt;
  @  ensures \this.size() == \old.size + 1&lt;br /&gt;
  @  ensures \this.top() == i&lt;br /&gt;
  @  ensures \this.contains(i) == true&lt;br /&gt;
  @  ensures \this.pop() == \old&lt;br /&gt;
  @ */&lt;br /&gt;
&lt;br /&gt;
//push adds a given element to the top of the stack leaving previous elements below&lt;br /&gt;
public void push(int i){ ... }&lt;br /&gt;
&lt;br /&gt;
// pop removes the current top element of the stack&lt;br /&gt;
public int top() { ... }&lt;br /&gt;
&lt;br /&gt;
// isEmpty checks whether the stack is empty or not&lt;br /&gt;
public boolean isEmpty() { ... }&lt;br /&gt;
&lt;br /&gt;
//contains checks whether the stack contains the given element or not&lt;br /&gt;
public boolean contains(int i) { ... }&lt;br /&gt;
&lt;br /&gt;
//size queries the number of elements stored in the stack&lt;br /&gt;
public int size() { ... }&lt;br /&gt;
&lt;br /&gt;
/* toString returns a string to represent the stack content. For example, it returns &lt;br /&gt;
&amp;quot; &amp;quot; for an empty stack; &amp;quot;8;&amp;quot; for a stack containing only one element 8, &amp;quot;8;9;&amp;quot; for a &lt;br /&gt;
stack containing 2 elements 8 and 9 */&lt;br /&gt;
public String toString() { ... }&lt;br /&gt;
&lt;br /&gt;
//isValidStack checks whether the stack has valid state; &lt;br /&gt;
public boolean isValidStack();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above implementation shows a stack of positive integers. The stack has no limit on the number of elements in it.&lt;br /&gt;
The fact that the stack is a valid one is always true. Also, whenever a pop operation is done on an empty stack, a value of -1 is returned. Since these two things never change, they are the class invariants.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever any element is to be added to the stack, the client needs to make sure that the element is positive and that it is an integer. These two requirements are the preconditions.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also, the stack needs to ensure that whenever a push operation is performed on it, the old stack and the new resulting stack are never the same and the size of the new stack is one more than that of the old one. It also needs to ensure, that the top method always returns the latest inserted element i and if that element i is popped out, the resulting stack is the same as the old one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8848</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8848"/>
		<updated>2007-11-18T01:12:16Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stack of integers===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Stack {&lt;br /&gt;
&lt;br /&gt;
/* @ public invariant&lt;br /&gt;
   @ \forall (isValidstack() == true)&lt;br /&gt;
     \forall (s.isEmpty == true &amp;lt;==&amp;gt; s.pop() == -1)&lt;br /&gt;
   @ */&lt;br /&gt;
&lt;br /&gt;
public Stack() { ... }&lt;br /&gt;
&lt;br /&gt;
/*@ normal behavior //non-exceptional specification&lt;br /&gt;
  @  // precondition&lt;br /&gt;
  @  requires i &amp;gt; 0&lt;br /&gt;
  @  requires i % 1 == 0&lt;br /&gt;
  @  //postcondition&lt;br /&gt;
  @  ensures \this.toString != \old.toString&lt;br /&gt;
  @  ensures \this.size() == \old.size + 1&lt;br /&gt;
  @  ensures \this.top() == i&lt;br /&gt;
  @  ensures \this.contains(i) == true&lt;br /&gt;
  @  ensures \this.pop() == \old&lt;br /&gt;
  @ */&lt;br /&gt;
&lt;br /&gt;
//push adds a given element to the top of the stack leaving previous elements below&lt;br /&gt;
public void push(int i){ ... }&lt;br /&gt;
&lt;br /&gt;
// pop removes the current top element of the stack&lt;br /&gt;
public int top() { ... }&lt;br /&gt;
&lt;br /&gt;
// isEmpty checks whether the stack is empty or not&lt;br /&gt;
public boolean isEmpty() { ... }&lt;br /&gt;
&lt;br /&gt;
//contains checks whether the stack contains the given element or not&lt;br /&gt;
public boolean contains(int i) { ... }&lt;br /&gt;
&lt;br /&gt;
//size queries the number of elements stored in the stack&lt;br /&gt;
public int size() { ... }&lt;br /&gt;
&lt;br /&gt;
/* toString returns a string to represent the stack content. For example, it returns &lt;br /&gt;
&amp;quot; &amp;quot; for an empty stack; &amp;quot;8;&amp;quot; for a stack containing only one element 8, &amp;quot;8;9;&amp;quot; for a &lt;br /&gt;
stack containing 2 elements 8 and 9 */&lt;br /&gt;
public String toString() { ... }&lt;br /&gt;
&lt;br /&gt;
//isValidStack checks whether the stack has valid state; &lt;br /&gt;
public boolean isValidStack();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above implementation shows a stack of positive integers. The stack has no limit on the number of elements in it.&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8846</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8846"/>
		<updated>2007-11-18T01:09:10Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stack of integers===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Stack {&lt;br /&gt;
&lt;br /&gt;
/* @ public invariant&lt;br /&gt;
   @ \forall (isValidstack() == true)&lt;br /&gt;
     \forall (s.isEmpty == true &amp;lt;==&amp;gt; s.pop() == -1)&lt;br /&gt;
   @ */&lt;br /&gt;
&lt;br /&gt;
public Stack() { ... }&lt;br /&gt;
&lt;br /&gt;
/*@ normal behavior //non-exceptional specification&lt;br /&gt;
  @  // precondition&lt;br /&gt;
  @  requires i &amp;gt; 0&lt;br /&gt;
  @  requires i % 1 == 0&lt;br /&gt;
  @  //postcondition&lt;br /&gt;
  @  ensures \this.toString != \old.toString&lt;br /&gt;
  @  ensures \this.size() == \old.size + 1&lt;br /&gt;
  @  ensures \this.top() == i&lt;br /&gt;
  @  ensures \this.contains(i) == true&lt;br /&gt;
  @  ensures \this.pop() == \old&lt;br /&gt;
  @ */&lt;br /&gt;
&lt;br /&gt;
//push adds a given element to the top of the stack leaving previous elements below&lt;br /&gt;
public void push(int i){ ... }&lt;br /&gt;
&lt;br /&gt;
// pop removes the current top element of the stack&lt;br /&gt;
public int top() { ... }&lt;br /&gt;
&lt;br /&gt;
// isEmpty checks whether the stack is empty or not&lt;br /&gt;
public boolean isEmpty() { ... }&lt;br /&gt;
&lt;br /&gt;
//contains checks whether the stack contains the given element or not&lt;br /&gt;
public boolean contains(int i) { ... }&lt;br /&gt;
&lt;br /&gt;
//size queries the number of elements stored in the stack&lt;br /&gt;
public int size() { ... }&lt;br /&gt;
&lt;br /&gt;
/* toString returns a string to represent the stack content. For example, it returns &lt;br /&gt;
&amp;quot; &amp;quot; for an empty stack; &amp;quot;8;&amp;quot; for a stack containing only one element 8, &amp;quot;8;9;&amp;quot; for a &lt;br /&gt;
stack containing 2 elements 8 and 9 */&lt;br /&gt;
public String toString() { ... }&lt;br /&gt;
&lt;br /&gt;
//isValidStack checks whether the stack has valid state; &lt;br /&gt;
public boolean isValidStack();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8845</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8845"/>
		<updated>2007-11-18T01:08:36Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Stack of integers===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Stack {&lt;br /&gt;
&lt;br /&gt;
/* @ public invariant&lt;br /&gt;
   @ \forall (isValidstack() == true)&lt;br /&gt;
     \forall (s.isEmpty == true &amp;lt;==&amp;gt; s.pop() == -1)&lt;br /&gt;
   @ */&lt;br /&gt;
&lt;br /&gt;
public Stack() { ... }&lt;br /&gt;
&lt;br /&gt;
/*@ normal behavior //non-exceptional specification&lt;br /&gt;
  @  // precondition&lt;br /&gt;
  @  requires i &amp;gt; 0&lt;br /&gt;
  @  requires i % 1 == 0&lt;br /&gt;
  @  //postcondition&lt;br /&gt;
  @  ensures \this.toString != \old.toString&lt;br /&gt;
  @  ensures \this.size() == \old.size + 1&lt;br /&gt;
  @  ensures \this.top() == i&lt;br /&gt;
  @  ensures \this.contains(i) == true&lt;br /&gt;
  @  ensures \this.pop() == \old&lt;br /&gt;
  @ */&lt;br /&gt;
&lt;br /&gt;
//push adds a given element to the top of the stack leaving previous elements below&lt;br /&gt;
public void push(int i){ ... }&lt;br /&gt;
&lt;br /&gt;
// pop removes the current top element of the stack&lt;br /&gt;
public int top() { ... }&lt;br /&gt;
&lt;br /&gt;
// isEmpty checks whether the stack is empty or not&lt;br /&gt;
public boolean isEmpty() { ... }&lt;br /&gt;
&lt;br /&gt;
//contains checks whether the stack contains the given element or not&lt;br /&gt;
public boolean contains(int i) { ... }&lt;br /&gt;
&lt;br /&gt;
//size queries the number of elements stored in the stack&lt;br /&gt;
public int size() { ... }&lt;br /&gt;
&lt;br /&gt;
/* toString returns a string to represent the stack content. For example, it returns &amp;quot; &amp;quot; for an empty stack; &amp;quot;8;&amp;quot; for a stack containing only one element 8, &amp;quot;8;9;&amp;quot; for a stack containing 2 elements 8 and 9 */&lt;br /&gt;
public String toString() { ... }&lt;br /&gt;
&lt;br /&gt;
//isValidStack checks whether the stack has valid state; &lt;br /&gt;
public boolean isValidStack();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8751</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8751"/>
		<updated>2007-11-17T17:53:52Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of eps (0.0001).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8750</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8750"/>
		<updated>2007-11-17T17:53:24Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calculating the square root===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SqrtExample {&lt;br /&gt;
&lt;br /&gt;
    public final static double eps = 0.0001;&lt;br /&gt;
&lt;br /&gt;
    //@ requires x &amp;gt;= 0.0;&lt;br /&gt;
    //@ ensures JMLDouble.approximatelyEqualTo(x, \result * \result, eps);&lt;br /&gt;
    &lt;br /&gt;
    public static double sqrt (double x) {&lt;br /&gt;
        return Math.sqrt(x);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the caller of the sqrt method (the client) needs to make sure that it is trying to find the &lt;br /&gt;
square root of a positive number. This is the precondition. The post condition is that the method sqrt will calculate the square root of x to a precision of 0.0001.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8749</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8749"/>
		<updated>2007-11-17T17:38:21Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   Precondition	  Postcondition&lt;br /&gt;
Supplier     Benefit	    Obligation&lt;br /&gt;
Client	    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8748</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8748"/>
		<updated>2007-11-17T17:37:17Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   '''Precondition'''	 ''' Postcondition'''&lt;br /&gt;
'''Supplier'''     Benefit	    Obligation&lt;br /&gt;
'''Client	'''    Obligation	     Benefit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8747</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8747"/>
		<updated>2007-11-17T17:36:26Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	   '''Precondition'''	 ''' Postcondition'''&lt;br /&gt;
'''Supplier'''     Benefit	    Obligation&lt;br /&gt;
'''Client	'''    Obligation	     Benefit&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8744</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8744"/>
		<updated>2007-11-17T17:26:40Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8742</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8742"/>
		<updated>2007-11-17T17:26:23Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
In the above example, the precondition for the setter method setAge is that the value of the input parameter being passed (the age of the person) should always be positive. Also, the getter method getAge has to satisfy the postcondition (obligation) that the age of the person on whom the method has been invoked is always positive.&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8741</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8741"/>
		<updated>2007-11-17T17:23:40Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
=== A simple interface ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
interface Person {&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
 * @post return &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
int getAge();&lt;br /&gt;
&lt;br /&gt;
/** age always positive&lt;br /&gt;
  * @pre years &amp;gt; 0&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
void setAge (int years);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Employee implements Person {&lt;br /&gt;
&lt;br /&gt;
private int age;&lt;br /&gt;
&lt;br /&gt;
public int getAge() {&lt;br /&gt;
  return age;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAge (int years) {&lt;br /&gt;
  age = years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8738</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8738"/>
		<updated>2007-11-17T17:02:37Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a '''contract''' which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind programming by contract is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8736</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8736"/>
		<updated>2007-11-17T17:01:15Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each program component has a &amp;quot;contract&amp;quot; which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in human understandable form rather than something syntactical. &lt;br /&gt;
eg- When given a positive real number, this function calculates its square root. &lt;br /&gt;
This contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind &amp;quot;programming by contract&amp;quot; is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8734</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8734"/>
		<updated>2007-11-17T16:57:02Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Programming by contract is a way of designing programs. Each part of a program has a &amp;quot;contract&amp;quot; which specifies how it should cooperate with the rest of the program.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This documentation is usually only written in a form that humans understand, something like &amp;quot;When given a positive real number, this function calculates its square root&amp;quot;. Note that this contract contains two parts, the input spesification (postive real number) and the output specification (calculates the square root).&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The idea behind &amp;quot;programming by contract&amp;quot; is that one should make as much of this information available to the computer as possible. This means that the system itself can catch a lot of the simple errors programmers make.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8731</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8731"/>
		<updated>2007-11-17T16:53:08Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as &lt;br /&gt;
pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8729</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8729"/>
		<updated>2007-11-17T16:52:45Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8728</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8728"/>
		<updated>2007-11-17T16:52:22Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are called as  pre-conditions. The module making the call is called the client. The preconditions are the obligations that the client needs &lt;br /&gt;
to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle &lt;br /&gt;
cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of &lt;br /&gt;
properties are called the supplier's postconditions. These postconditions are obligations for the supplier, and benefits for &lt;br /&gt;
the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on &lt;br /&gt;
exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8727</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8727"/>
		<updated>2007-11-17T16:51:26Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•  Preconditions - Certain obligations need to be fulfilled by any module which calls the software component are &lt;br /&gt;
called as  pre-conditions. The module making the call is called the client. The preconditions are the obligations &lt;br /&gt;
that the client needs to fulfill and are benefits for the software component, called the supplier, as it frees the &lt;br /&gt;
supplier from having to handle cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•  Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These &lt;br /&gt;
set of properties are called the supplier's postconditions. These postconditions are obligations for the supplier, &lt;br /&gt;
and benefits for the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•  Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry and is &lt;br /&gt;
guaranteed on exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8726</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8726"/>
		<updated>2007-11-17T16:50:04Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•	Preconditions - Certain obligations need to be fulfilled by any module which calls the software &lt;br /&gt;
component are called as  pre-conditions. The module making the call is called the client. The preconditions&lt;br /&gt;
are the obligations that the client needs to fulfill and are benefits for the software component, called the &lt;br /&gt;
supplier, as it frees the supplier from having to handle cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•	Postconditions - The supplier in turn, needs to guarantee certain outputs or certain properties on &lt;br /&gt;
exit. These set of properties are called the supplier's postconditions. These postconditions are obligations &lt;br /&gt;
for the supplier, and benefits for the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•	Class invariant - The supplier needs to maintain a certain property that is assumed to exist on entry &lt;br /&gt;
and is guaranteed on exit, called the class invariant.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8723</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8723"/>
		<updated>2007-11-17T16:48:16Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
•	Certain obligations need to be fulfilled by any module which calls the software component are called as  '''pre-conditions'''. The module making the call is called the client. The preconditions are the obligations that&lt;br /&gt;
 the client needs to fulfill and are benefits for the software component, called the supplier, as it frees the &lt;br /&gt;
supplier from having to handle cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•	The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of properties are called the supplier's '''postconditions'''. These postconditions are obligations for the supplier, and benefits for the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•	The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on exit, called the '''class invariant'''.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8719</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8719"/>
		<updated>2007-11-17T16:45:47Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
•	Certain obligations need to be fulfilled by any module which calls the software component are called as '''pre-conditions'''. The module making the call is called the client. The preconditions are the obligations that the client needs to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle cases outside of the precondition.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•	The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of properties are called the supplier's '''postconditions'''. These postconditions are obligations for the supplier, and benefits for the client obtained from calling the supplier module.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•	The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on exit, called the '''class invariant'''.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8718</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8718"/>
		<updated>2007-11-17T16:42:34Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
•	Certain obligations need to be fulfilled by any module which calls the software component are called as '''pre-conditions'''. The module making the call is called the client. The preconditions are the obligations that the client needs to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle cases outside of the precondition.&lt;br /&gt;
&lt;br /&gt;
•	The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of properties are called the supplier's '''postconditions'''. These postconditions are obligations for the supplier, and benefits for the client obtained from calling the supplier module.&lt;br /&gt;
&lt;br /&gt;
•	The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on exit, called the '''class invariant'''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8717</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8717"/>
		<updated>2007-11-17T16:42:01Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise examples that illustrate the principle of programming by contract, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
•	Certain obligations need to be fulfilled by any module which calls the software component are called as '''pre-conditions'''. The module making the call is called the client. The preconditions are the obligations that the client needs to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle cases outside of the precondition.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
•	The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of properties are called the supplier's '''postconditions'''. These postconditions are obligations for the supplier, and benefits for the client obtained from calling the supplier module.&lt;br /&gt;
•	The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on exit, called the '''class invariant'''.&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8716</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8716"/>
		<updated>2007-11-17T16:41:00Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise ones that illustrate the principle well, and are accessible to a general audience of programmers.''&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
Programming by contract is a software development approach that enforces the developers to define concrete and verifiable interface specifications for the software code. It is based on the theory of a business contract.&lt;br /&gt;
&lt;br /&gt;
==Norms of the contract==&lt;br /&gt;
&lt;br /&gt;
The core idea of programming by contract is how components of a software system collaborate with each other on the basis of mutual obligations and benefits. The concept is drawn from the business domain where clients and suppliers agree on a contract that defines certain norms. The corresponding norms that one can associate with a software system are – &lt;br /&gt;
•	Certain obligations need to be fulfilled by any module which calls the software component are called as '''pre-conditions'''. The module making the call is called the client. The preconditions are the obligations that the client needs to fulfill and are benefits for the software component, called the supplier, as it frees the supplier from having to handle cases outside of the precondition.&lt;br /&gt;
•	The supplier in turn, needs to guarantee certain outputs or certain properties on exit. These set of properties are called the supplier's '''postconditions'''. These postconditions are obligations for the supplier, and benefits for the client obtained from calling the supplier module.&lt;br /&gt;
•	The supplier needs to maintain a certain property that is assumed to exist on entry and is guaranteed on exit, called the '''class invariant'''.&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8707</id>
		<title>CSC/ECE 517 Fall 2007/wiki3 2 dp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki3_2_dp&amp;diff=8707"/>
		<updated>2007-11-17T16:23:01Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Find some concise ones that illustrate the principle well, and are accessible to a general audience of programmers.''&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=8159</id>
		<title>CSC/ECE 517 Fall 2007/wiki2 6 ap</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=8159"/>
		<updated>2007-10-30T02:19:46Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Type vs. class. Survey the differences on type vs. class in object-oriented languages. Often, the distinction is that class pertains to an object, whereas type pertains to a variable. Consider the distinction between the two terms in several different programming languages. Cover the differences between type and class, from type-theoretic definitions to practical aspects.''&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
In object oriented programming concepts, the difference between types and classes is not clearly understood. The differences between them are subtle and the two terms are often misunderstood to be the same. In this article we try to bring out the differences between Types and Classes and provide more insight into them. Furthermore, in OOP languages, classes are types, while most types are not classes. In pure object languages, by opposition (e.g. Smalltalk, Scala, perhaps Python), every type maps to a class.    &lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
===Type=== &lt;br /&gt;
A ''type'', in an object-oriented system, summarizes the common features of a set of objects with the same characteristics. It corresponds to the notion of an abstract data type. Type has 2 parts: the interface and the implementation(s). The interface, which is the only part visible to the user, consists of a list of operations and their signatures. The type implementation is of concern only to the type designer. [1]&lt;br /&gt;
&lt;br /&gt;
===Class===&lt;br /&gt;
A ''class'', in object oriented systems, is a kind of metadata that describes the rules by which objects behave; these objects are referred to as instances of that class. A class specifies the structure of data (a.k.a. properties, fields, attributes, data members) within each instance as well as methods (functions) (a.k.a. behaviors) which manipulate the data of the object and perform tasks. [1]&lt;br /&gt;
&lt;br /&gt;
==Types==&lt;br /&gt;
&lt;br /&gt;
Types are abstract views that define properties of a set of entities. Object-oriented programming languages must allow to implement these types. Consequently, once a type is implemented we have a particular representation of it available. We will use the seminal concept of the integer data type to explain the concept of type in detail. Programming languages such as C, Java, C++, Pascal and others already offer an implementation for it [3]. Sometimes it is called int or integer. Once you've created a variable of this type you can use its provided operations. For example, you can add two integers: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
  int i, j, k;    /* Define three integers */&lt;br /&gt;
&lt;br /&gt;
  i = 1;          /* Assign 1 to integer i */&lt;br /&gt;
  j = 2;          /* Assign 2 to integer j */&lt;br /&gt;
  k = i + j;      /* Assign the sum of i and j to k */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first line defines three instances i, j and k of type Integer. Consequently, for each instance the special operation constructor should be called. In our example, this is internally done by the compiler. The compiler reserves memory to hold the value of an integer and ''binds'' the corresponding name to it. If you refer to i you actually refer to this memory area which was ''constructed'' by the definition of i. &lt;br /&gt;
&lt;br /&gt;
The implementation of types comprises of the data (internal structure of the object’s data) and operation (methods / procedures which implement the interface operations). By making users declare the types of variables at compile time, the system simplifies the procedure of checking the program correctness at compile time, thereby increasing programmer productivity. The types cannot be modified at run-time.&lt;br /&gt;
&lt;br /&gt;
===Properties of a Type===&lt;br /&gt;
* It exports a set of operations. This set is called interface. &lt;br /&gt;
* Operations of the interface are the one and only access mechanism to the type's data structure. &lt;br /&gt;
* Axioms and preconditions define the application domain of the type. [2]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
&lt;br /&gt;
A class is a combination of state (data) and behavior (methods) that manipulate the state. [2] A class is a blueprint for an object.It is an actual representation of a type. It therefore provides implementation details for the data structure used and operations specified in the type. Now we will define a class that implements the Integer data type: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;  &lt;br /&gt;
class Integer {&lt;br /&gt;
  attributes: || implementation : &lt;br /&gt;
    int i /* Integer data type */&lt;br /&gt;
&lt;br /&gt;
  methods: || operation :&lt;br /&gt;
    setValue(int n) /* To assign value to i */&lt;br /&gt;
    Integer addValue(Integer j) /* To add integer j with i */&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this notation class {...} denotes the definition of a class. Enclosed in the curly brackets are two sections attributes: and methods: which define the implementation of the data structure and operations of the corresponding class. Again we distinguish the two levels with different terms: At the implementation level we speak of ''attributes'' which are elements of the data structure at the class level. The same applies to ''methods'' which are the implementation of the class operations. &lt;br /&gt;
In our example, the attribute is an ordinary integer of a programming language . We only define two methods setValue() and addValue() representing the two of the many operations that can be performed on an integer data type set and add, to make the comparison succinct and concise.&lt;br /&gt;
&lt;br /&gt;
Although the specification of a class is pretty similar to that of a type, it is more of a runtime notion. There are two major aspects of a class – an object factory and an object warehouse. The object factory is the means by which objects of a class are created, using the new operation on the class. Object warehouse stores the set of objects that are instances of the class. Users can work with all these objects by performing all the allowed operations on them and thereby change the contents of the object warehouse. Thus, classes by no means determine the correctness of a program, rather they are used to create and manipulate objects, thereby making the system more flexible.&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
The concept of ''type'' itself is an abstraction, such as it can be either a ''value type'' or a ''reference type''. In most languages, ''Type'' is the most general abstraction, categorized into ''value types'' and ''reference types''. [7]&lt;br /&gt;
&lt;br /&gt;
Value types in turn can be of different kinds, such as the primitive types, but some languages also allow you to construct compound types which are classes. Reference types can also have different constructions, such as class as one and some would consider arrays as another.&lt;br /&gt;
&lt;br /&gt;
In reality, type is whatever a variable can be cast into. This includes both value types and reference types. Since the concepts of types and classes are tightly coupled, in this article we don't explicitly show direct contrasts between them, but rather subtly bring out the differences in their implementations in various programming languages.&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in C++==&lt;br /&gt;
&lt;br /&gt;
C++ supports three kinds of object types:&lt;br /&gt;
    * Fundamental types are built into the language (such as int, float, or double). Instances of these fundamental types are &lt;br /&gt;
      often called ''variables''.&lt;br /&gt;
    * Derived types are new types derived from built-in types.&lt;br /&gt;
    * Class types are new types created by combining existing types. These include Classes, Structures, and Unions. [5]&lt;br /&gt;
&lt;br /&gt;
===Fundamental Types===&lt;br /&gt;
&lt;br /&gt;
Fundamental types in C++ are divided into three categories: integral, floating, and void. Integral types are capable of handling whole numbers. Floating types are capable of specifying values that may have fractional parts.The void type describes an empty set of values. No variable of type void can be specified — it is used primarily to declare functions that return no values or to declare generic pointers to untyped or arbitrarily typed data&lt;br /&gt;
&lt;br /&gt;
===Derived Types===&lt;br /&gt;
&lt;br /&gt;
Derived types are new types that can be used in a program, and can include directly derived types and composed derivative types.&lt;br /&gt;
====Directly Derived Types====&lt;br /&gt;
&lt;br /&gt;
New types derived directly from existing types are types that point to, refer to, or (in the case of functions) transform type data to return a new type.&lt;br /&gt;
&lt;br /&gt;
    * Arrays of Variables or Objects&lt;br /&gt;
    * Functions&lt;br /&gt;
    * Pointers of a Given Type&lt;br /&gt;
    * References to Objects&lt;br /&gt;
    * Constants&lt;br /&gt;
    * Pointers to Class Members&lt;br /&gt;
====Composed Derivative Types====&lt;br /&gt;
&lt;br /&gt;
The following are the various composed derivative types:&lt;br /&gt;
&lt;br /&gt;
    * Classes&lt;br /&gt;
    * Structures&lt;br /&gt;
    * Unions&lt;br /&gt;
&lt;br /&gt;
Class types are derivatives of composed types. More on class types below.&lt;br /&gt;
&lt;br /&gt;
===Class Types===&lt;br /&gt;
&lt;br /&gt;
Class types are defined using the class, struct, and union keywords. For simplicity, types defined with these keywords are called class declarations. Class Type names are introduced as identifiers immediately after the compiler processes them (before entry into the class body); they can be used to declare class members. This allows declaration of self-referential data structures&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define TRUE = 1&lt;br /&gt;
&lt;br /&gt;
class dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public:&lt;br /&gt;
   dog()&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(string dogSize)&lt;br /&gt;
   {&lt;br /&gt;
      _dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   string getDogSize()&lt;br /&gt;
   {&lt;br /&gt;
      return _dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(string breed)&lt;br /&gt;
   {&lt;br /&gt;
      _breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   private: // attributes || fundamental types&lt;br /&gt;
   string _dogSize, _breed;&lt;br /&gt;
   int _legs;&lt;br /&gt;
   bool _bark;&lt;br /&gt;
&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   dog mongrel;//class types&lt;br /&gt;
   //setting specific attributes that makes it different from types&lt;br /&gt;
   mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
   mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Ricky is a &amp;quot; &amp;lt;&amp;lt; mongrel.getDogSize() &amp;lt;&amp;lt; &amp;quot; sized dog&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Java==&lt;br /&gt;
&lt;br /&gt;
[4] Java is a strongly typed language i.e. the type of every variable and expression used in a program must be known at compile time. The type of a variable / expression defines the range of values that it can hold. The type of a variable also determines the operations that can be performed on that variable. The strong typing nature of Java enables it to determine errors at compile time.Whenever a variable is declared in Java, we need to mention its type, which may be a class, interface or a primitive. When an object of a subclass of some other class is instantiated, we can say that the object is of type subclass and type superclass and it can perform all operations of both the subclass and the superclass.&amp;lt;br&amp;gt; [4]&lt;br /&gt;
&lt;br /&gt;
There are two different types in Java :&lt;br /&gt;
    * Primitive Types are boolean and numeric. The numeric types are the integral types byte, short, int, long, and char, and the         &lt;br /&gt;
      floating-point types float and double. &lt;br /&gt;
    * Reference Types are class types, interface types and array types.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|width=&amp;quot;100%&amp;quot;  border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; bordercolor = &amp;quot;black&amp;quot; cellspacing=&amp;quot;2&amp;quot; align = &amp;quot;left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!A side note on Null Types&lt;br /&gt;
|-&lt;br /&gt;
|There is also a special null type in Java, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Primitive Types====&lt;br /&gt;
&lt;br /&gt;
A primitive type is predefined by the Java programming language and named by its reserved keyword.Primitive values do not share state with other primitive values. A variable whose type is a primitive type always holds a primitive value of that same type. The value of a variable of primitive type can be changed only by assignment operations on that variable.&lt;br /&gt;
&lt;br /&gt;
====Reference Types====&lt;br /&gt;
&lt;br /&gt;
There are three kinds of reference types: class types, interface types, and array types.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt; &lt;br /&gt;
ReferenceType:&lt;br /&gt;
	ClassOrInterfaceType&lt;br /&gt;
	ArrayType&lt;br /&gt;
&lt;br /&gt;
ClassOrInterfaceType:&lt;br /&gt;
	ClassType&lt;br /&gt;
	InterfaceType&lt;br /&gt;
&lt;br /&gt;
ClassType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
InterfaceType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
ArrayType:&lt;br /&gt;
        [ ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
class Dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public Dog() //constructor&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(String dogSize) //setter method&lt;br /&gt;
   {&lt;br /&gt;
      this.dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   String getDogSize() //getter method&lt;br /&gt;
   {&lt;br /&gt;
      return this.dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(String breed)&lt;br /&gt;
   {&lt;br /&gt;
      this.breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   // attributes || fundamental types&lt;br /&gt;
   String dogSize = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   Sting breed = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   int legs;&lt;br /&gt;
   boolean bark;&lt;br /&gt;
   public static void main(String[] args)&lt;br /&gt;
   {&lt;br /&gt;
     Dog mongrel = new Dog();//class types&lt;br /&gt;
     //setting specific attributes that makes it different from types&lt;br /&gt;
     mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
     mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
     System.out.println(&amp;quot;Ricky is a &amp;quot;+ mongrel.getSize() +&amp;quot; size dog&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby being a dynamically typed, reflective object oriented language, every variable is an object and we do not explicitly mention their type as in other object oriented languages, rather the type is implicitly inferred from the type of the value which is assigned to them at runtime. Hence there is no distinction between primitive data types and object types in ruby. In Ruby, all classes are instances of the class Class. Whenever a new class is defined, an object of type Class is created and assigned to the ''Name'' of the class. ''Name.new'' is used to create a new object of the class. This invokes the ''new'' instance method in Class, which in turn calls the ''allocate'' method to allocate memory for the object, before finally calling the new object's initialize method. Thus, the construction of an object is separate from its initialization, and both can be over-ridden. The initialization is done via the ''initialize'' instance method while the construction is done via the ''new'' class method [6].&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#since ruby is dynamic Oo language no explicit type assignment statements&lt;br /&gt;
class Dog &lt;br /&gt;
&lt;br /&gt;
   #implementation&lt;br /&gt;
   def initialize&lt;br /&gt;
      @legs = 4&lt;br /&gt;
      @bark = true&lt;br /&gt;
   end&lt;br /&gt;
   #attributes&lt;br /&gt;
   attr_accessor :dogSize, :breed &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
#at runtime   &lt;br /&gt;
mongrel = Dog.new #dynamiclly typed&lt;br /&gt;
#setting specific attributes that makes it different from types&lt;br /&gt;
mongrel.dogSize = &amp;quot;medium&amp;quot; # string class type&lt;br /&gt;
mongrel.breed = &amp;quot;country specific&amp;quot; # string class type&lt;br /&gt;
puts &amp;quot;Ricky is a #{mongrel.dogSize} size dog&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] [http://www.cs.cmu.edu/People/clamen/OODBMS/Manifesto/htManifesto/node6.html Types and Classes]&amp;lt;br&amp;gt;&lt;br /&gt;
[2] [http://en.wikipedia.org/wiki/Object-oriented_programming Object Oriented Programming concepts on Wikipedia]&amp;lt;br&amp;gt;&lt;br /&gt;
[3] [http://haskell.org/haskellwiki/OOP_vs_type_classes OOP vs type classes]&amp;lt;br&amp;gt;&lt;br /&gt;
[4] [http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html Java Language Specification,Second Edition Chapter4: Types, Values, Variables]&amp;lt;br&amp;gt;&lt;br /&gt;
[5] [http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=/com.ibm.xlcpp8l.doc/language/ref/cplr058.htm Classes and Types in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
[6] [http://rubylearning.com/satishtalim/writing_our_own_class_in_ruby.html Writing Classes in Ruby and Insipration for Example]&amp;lt;br&amp;gt;&lt;br /&gt;
[7] [http://www.velocityreviews.com/forums/t127376-what-is-the-difference-between-class-and-type.html What is the difference between class and type]&lt;br /&gt;
&lt;br /&gt;
==Further Reading / External Links== &lt;br /&gt;
&lt;br /&gt;
Bjarne Stroustrup's article on OOP in C++ and beyond http://www.research.att.com/~bs/bs_faq.html#oop&amp;lt;br&amp;gt;&lt;br /&gt;
B. Stroustrup, The C++ Programming Language, 3rd-ed., p. 158&amp;lt;br&amp;gt;&lt;br /&gt;
Fundamentals of OOP and Data Structures in Java - Page xiii by Richard Wiener, Lewis J. Pinson &amp;lt;br&amp;gt;&lt;br /&gt;
Type vs Class, A general overview http://lambda-the-ultimate.org/node/2079&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=8156</id>
		<title>CSC/ECE 517 Fall 2007/wiki2 6 ap</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=8156"/>
		<updated>2007-10-30T02:14:50Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Type vs. class. Survey the differences on type vs. class in object-oriented languages. Often, the distinction is that class pertains to an object, whereas type pertains to a variable. Consider the distinction between the two terms in several different programming languages. Cover the differences between type and class, from type-theoretic definitions to practical aspects.''&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
In object oriented programming concepts, the difference between types and classes is not clearly understood. The differences between them are subtle and the two terms are often misunderstood to be the same. In this article we try to bring out the differences between Types and Classes and provide more insight into them. Furthermore, in OOP languages, classes are types, while most types are not classes. In pure object languages, by opposition (e.g. Smalltalk, Scala, perhaps Python), every type maps to a class.    &lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
===Type=== &lt;br /&gt;
A ''type'', in an object-oriented system, summarizes the common features of a set of objects with the same characteristics. It corresponds to the notion of an abstract data type. Type has 2 parts: the interface and the implementation(s). The interface, which is the only part visible to the user, consists of a list of operations and their signatures. The type implementation is of concern only to the type designer. [1]&lt;br /&gt;
&lt;br /&gt;
===Class===&lt;br /&gt;
A ''class'', in object oriented systems, is a kind of metadata that describes the rules by which objects behave; these objects are referred to as instances of that class. A class specifies the structure of data (a.k.a. properties, fields, attributes, data members) within each instance as well as methods (functions) (a.k.a. behaviors) which manipulate the data of the object and perform tasks. [1]&lt;br /&gt;
&lt;br /&gt;
==Types==&lt;br /&gt;
&lt;br /&gt;
Types are abstract views that define properties of a set of entities. Object-oriented programming languages must allow to implement these types. Consequently, once a type is implemented we have a particular representation of it available. We will use the seminal concept of the integer data type to explain the concept of type in detail. Programming languages such as C, Java, C++, Pascal and others already offer an implementation for it [3]. Sometimes it is called int or integer. Once you've created a variable of this type you can use its provided operations. For example, you can add two integers: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
  int i, j, k;    /* Define three integers */&lt;br /&gt;
&lt;br /&gt;
  i = 1;          /* Assign 1 to integer i */&lt;br /&gt;
  j = 2;          /* Assign 2 to integer j */&lt;br /&gt;
  k = i + j;      /* Assign the sum of i and j to k */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first line defines three instances i, j and k of type Integer. Consequently, for each instance the special operation constructor should be called. In our example, this is internally done by the compiler. The compiler reserves memory to hold the value of an integer and ''binds'' the corresponding name to it. If you refer to i you actually refer to this memory area which was ''constructed'' by the definition of i. &lt;br /&gt;
&lt;br /&gt;
The implementation of types comprises of the data (internal structure of the object’s data) and operation (methods / procedures which implement the interface operations). By making users declare the types of variables at compile time, the system simplifies the procedure of checking the program correctness at compile time, thereby increasing programmer productivity. The types cannot be modified at run-time.&lt;br /&gt;
&lt;br /&gt;
===Properties of a Type===&lt;br /&gt;
* It exports a set of operations. This set is called interface. &lt;br /&gt;
* Operations of the interface are the one and only access mechanism to the type's data structure. &lt;br /&gt;
* Axioms and preconditions define the application domain of the type. [2]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
&lt;br /&gt;
A class is a combination of state (data) and behavior (methods) that manipulate the state. [2] A class is a blueprint for an object.It is an actual representation of a type. It therefore provides implementation details for the data structure used and operations specified in the type. Now we will define a class that implements the Integer data type: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;  &lt;br /&gt;
class Integer {&lt;br /&gt;
  attributes: || implementation : &lt;br /&gt;
    int i /* Integer data type */&lt;br /&gt;
&lt;br /&gt;
  methods: || operation :&lt;br /&gt;
    setValue(int n) /* To assign value to i */&lt;br /&gt;
    Integer addValue(Integer j) /* To add integer j with i */&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this notation class {...} denotes the definition of a class. Enclosed in the curly brackets are two sections attributes: and methods: which define the implementation of the data structure and operations of the corresponding class. Again we distinguish the two levels with different terms: At the implementation level we speak of ''attributes'' which are elements of the data structure at the class level. The same applies to ''methods'' which are the implementation of the class operations. &lt;br /&gt;
In our example, the attribute is an ordinary integer of a programming language . We only define two methods setValue() and addValue() representing the two of the many operations that can be performed on an integer data type set and add, to make the comparison succinct and concise.&lt;br /&gt;
&lt;br /&gt;
Although the specification of a class is pretty similar to that of a type, it is more of a runtime notion. There are two major aspects of a class – an object factory and an object warehouse. The object factory is the means by which objects of a class are created, using the new operation on the class. Object warehouse stores the set of objects that are instances of the class. Users can work with all these objects by performing all the allowed operations on them and thereby change the contents of the object warehouse. Thus, classes by no means determine the correctness of a program, rather they are used to create and manipulate objects, thereby making the system more flexible.&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
The concept of ''type'' itself is an abstraction, such as it can be either a ''value type'' or a ''reference type''. In most languages, ''Type'' is the most general abstraction, categorized into ''value types'' and ''reference types''.&lt;br /&gt;
&lt;br /&gt;
Value types in turn can be of different kinds, such as the primitive types, but some languages also allow you to construct compound types which are classes. Reference types can also have different constructions, such as class as one and some would consider arrays as another.&lt;br /&gt;
&lt;br /&gt;
In reality, type is whatever a variable can be cast into. This includes both value types and reference types. Since the concepts of types and classes are tightly coupled, in this article we don't explicitly show direct contrasts between them, but rather subtly bring out the differences in their implementations in various programming languages.&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in C++==&lt;br /&gt;
&lt;br /&gt;
C++ supports three kinds of object types:&lt;br /&gt;
    * Fundamental types are built into the language (such as int, float, or double). Instances of these fundamental types are &lt;br /&gt;
      often called ''variables''.&lt;br /&gt;
    * Derived types are new types derived from built-in types.&lt;br /&gt;
    * Class types are new types created by combining existing types. These include Classes, Structures, and Unions.&lt;br /&gt;
&lt;br /&gt;
===Fundamental Types===&lt;br /&gt;
&lt;br /&gt;
Fundamental types in C++ are divided into three categories: integral, floating, and void. Integral types are capable of handling whole numbers. Floating types are capable of specifying values that may have fractional parts.The void type describes an empty set of values. No variable of type void can be specified — it is used primarily to declare functions that return no values or to declare generic pointers to untyped or arbitrarily typed data&lt;br /&gt;
&lt;br /&gt;
===Derived Types===&lt;br /&gt;
&lt;br /&gt;
Derived types are new types that can be used in a program, and can include directly derived types and composed derivative types.&lt;br /&gt;
====Directly Derived Types====&lt;br /&gt;
&lt;br /&gt;
New types derived directly from existing types are types that point to, refer to, or (in the case of functions) transform type data to return a new type.&lt;br /&gt;
&lt;br /&gt;
    * Arrays of Variables or Objects&lt;br /&gt;
    * Functions&lt;br /&gt;
    * Pointers of a Given Type&lt;br /&gt;
    * References to Objects&lt;br /&gt;
    * Constants&lt;br /&gt;
    * Pointers to Class Members&lt;br /&gt;
====Composed Derivative Types====&lt;br /&gt;
&lt;br /&gt;
The following are the various composed derivative types:&lt;br /&gt;
&lt;br /&gt;
    * Classes&lt;br /&gt;
    * Structures&lt;br /&gt;
    * Unions&lt;br /&gt;
&lt;br /&gt;
Class types are derivatives of composed types. More on class types below.&lt;br /&gt;
&lt;br /&gt;
===Class Types===&lt;br /&gt;
&lt;br /&gt;
Class types are defined using the class, struct, and union keywords. For simplicity, types defined with these keywords are called class declarations. Class Type names are introduced as identifiers immediately after the compiler processes them (before entry into the class body); they can be used to declare class members. This allows declaration of self-referential data structures&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define TRUE = 1&lt;br /&gt;
&lt;br /&gt;
class dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public:&lt;br /&gt;
   dog()&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(string dogSize)&lt;br /&gt;
   {&lt;br /&gt;
      _dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   string getDogSize()&lt;br /&gt;
   {&lt;br /&gt;
      return _dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(string breed)&lt;br /&gt;
   {&lt;br /&gt;
      _breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   private: // attributes || fundamental types&lt;br /&gt;
   string _dogSize, _breed;&lt;br /&gt;
   int _legs;&lt;br /&gt;
   bool _bark;&lt;br /&gt;
&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   dog mongrel;//class types&lt;br /&gt;
   //setting specific attributes that makes it different from types&lt;br /&gt;
   mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
   mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Ricky is a &amp;quot; &amp;lt;&amp;lt; mongrel.getDogSize() &amp;lt;&amp;lt; &amp;quot; sized dog&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Java==&lt;br /&gt;
&lt;br /&gt;
[4] Java is a strongly typed language i.e. the type of every variable and expression used in a program must be known at compile time. The type of a variable / expression defines the range of values that it can hold. The type of a variable also determines the operations that can be performed on that variable. The strong typing nature of Java enables it to determine errors at compile time.Whenever a variable is declared in Java, we need to mention its type, which may be a class, interface or a primitive. When an object of a subclass of some other class is instantiated, we can say that the object is of type subclass and type superclass and it can perform all operations of both the subclass and the superclass.&amp;lt;br&amp;gt; [4]&lt;br /&gt;
&lt;br /&gt;
There are two different types in Java :&lt;br /&gt;
    * Primitive Types are boolean and numeric. The numeric types are the integral types byte, short, int, long, and char, and the         &lt;br /&gt;
      floating-point types float and double. &lt;br /&gt;
    * Reference Types are class types, interface types and array types.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|width=&amp;quot;100%&amp;quot;  border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; bordercolor = &amp;quot;black&amp;quot; cellspacing=&amp;quot;2&amp;quot; align = &amp;quot;left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!A side note on Null Types&lt;br /&gt;
|-&lt;br /&gt;
|There is also a special null type in Java, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Primitive Types====&lt;br /&gt;
&lt;br /&gt;
A primitive type is predefined by the Java programming language and named by its reserved keyword.Primitive values do not share state with other primitive values. A variable whose type is a primitive type always holds a primitive value of that same type. The value of a variable of primitive type can be changed only by assignment operations on that variable.&lt;br /&gt;
&lt;br /&gt;
====Reference Types====&lt;br /&gt;
&lt;br /&gt;
There are three kinds of reference types: class types, interface types, and array types.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt; &lt;br /&gt;
ReferenceType:&lt;br /&gt;
	ClassOrInterfaceType&lt;br /&gt;
	ArrayType&lt;br /&gt;
&lt;br /&gt;
ClassOrInterfaceType:&lt;br /&gt;
	ClassType&lt;br /&gt;
	InterfaceType&lt;br /&gt;
&lt;br /&gt;
ClassType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
InterfaceType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
ArrayType:&lt;br /&gt;
        [ ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
class Dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public Dog() //constructor&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(String dogSize) //setter method&lt;br /&gt;
   {&lt;br /&gt;
      this.dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   String getDogSize() //getter method&lt;br /&gt;
   {&lt;br /&gt;
      return this.dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(String breed)&lt;br /&gt;
   {&lt;br /&gt;
      this.breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   // attributes || fundamental types&lt;br /&gt;
   String dogSize = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   Sting breed = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   int legs;&lt;br /&gt;
   boolean bark;&lt;br /&gt;
   public static void main(String[] args)&lt;br /&gt;
   {&lt;br /&gt;
     Dog mongrel = new Dog();//class types&lt;br /&gt;
     //setting specific attributes that makes it different from types&lt;br /&gt;
     mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
     mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
     System.out.println(&amp;quot;Ricky is a &amp;quot;+ mongrel.getSize() +&amp;quot; size dog&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby being a dynamically typed, reflective object oriented language, every variable is an object and we do not explicitly mention their type as in other object oriented languages, rather the type is implicitly inferred from the type of the value which is assigned to them at runtime. Hence there is no distinction between primitive data types and object types in ruby. In Ruby, all classes are instances of the class Class. Whenever a new class is defined, an object of type Class is created and assigned to the ''Name'' of the class. ''Name.new'' is used to create a new object of the class. This invokes the ''new'' instance method in Class, which in turn calls the ''allocate'' method to allocate memory for the object, before finally calling the new object's initialize method. Thus, the construction of an object is separate from its initialization, and both can be over-ridden. The initialization is done via the ''initialize'' instance method while the construction is done via the ''new'' class method.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#since ruby is dynamic Oo language no explicit type assignment statements&lt;br /&gt;
class Dog &lt;br /&gt;
&lt;br /&gt;
   #implementation&lt;br /&gt;
   def initialize&lt;br /&gt;
      @legs = 4&lt;br /&gt;
      @bark = true&lt;br /&gt;
   end&lt;br /&gt;
   #attributes&lt;br /&gt;
   attr_accessor :dogSize, :breed &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
#at runtime   &lt;br /&gt;
mongrel = Dog.new #dynamiclly typed&lt;br /&gt;
#setting specific attributes that makes it different from types&lt;br /&gt;
mongrel.dogSize = &amp;quot;medium&amp;quot; # string class type&lt;br /&gt;
mongrel.breed = &amp;quot;country specific&amp;quot; # string class type&lt;br /&gt;
puts &amp;quot;Ricky is a #{mongrel.dogSize} size dog&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] [http://www.cs.cmu.edu/People/clamen/OODBMS/Manifesto/htManifesto/node6.html Types and Classes]&amp;lt;br&amp;gt;&lt;br /&gt;
[2] [http://en.wikipedia.org/wiki/Object-oriented_programming Object Oriented Programming concepts on Wikipedia]&amp;lt;br&amp;gt;&lt;br /&gt;
[3] [http://haskell.org/haskellwiki/OOP_vs_type_classes OOP vs type classes]&amp;lt;br&amp;gt;&lt;br /&gt;
[4] [http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html Java Language Specification,Second Edition Chapter4: Types, Values, Variables]&amp;lt;br&amp;gt;&lt;br /&gt;
[5] [http://en.wikibooks.org/wiki/Java_Programming/Types Java Programming/Types on Wikipedia]&amp;lt;br&amp;gt;&lt;br /&gt;
[6] [http://rubylearning.com/satishtalim/writing_our_own_class_in_ruby.html Writing Classes in Ruby and Insipration for Example]&amp;lt;br&amp;gt;&lt;br /&gt;
[7] [http://www.velocityreviews.com/forums/t127376-what-is-the-difference-between-class-and-type.html What is the difference between class and type]&lt;br /&gt;
&lt;br /&gt;
==Further Reading / External Links== &lt;br /&gt;
&lt;br /&gt;
Bjarne Stroustrup's article on OOP in C++ and beyond http://www.research.att.com/~bs/bs_faq.html#oop&amp;lt;br&amp;gt;&lt;br /&gt;
B. Stroustrup, The C++ Programming Language, 3rd-ed., p. 158&amp;lt;br&amp;gt;&lt;br /&gt;
Fundamentals of OOP and Data Structures in Java - Page xiii by Richard Wiener, Lewis J. Pinson &amp;lt;br&amp;gt;&lt;br /&gt;
Type vs Class, A general overview http://lambda-the-ultimate.org/node/2079&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=8004</id>
		<title>CSC/ECE 517 Fall 2007/wiki2 6 ap</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=8004"/>
		<updated>2007-10-29T06:04:39Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Type vs. class. Survey the differences on type vs. class in object-oriented languages. Often, the distinction is that class pertains to an object, whereas type pertains to a variable. Consider the distinction between the two terms in several different programming languages. Cover the differences between type and class, from type-theoretic definitions to practical aspects.''&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
In object oriented programming concepts, the difference between types and classes is not clearly understood. The differences between them are subtle and the two terms are often misunderstood to be the same. In this article we try to bring out the differences between Types and Classes and provide more insight into them. Furthermore, in OOP languages, classes are types, while most types are not classes. In pure object languages, by opposition (e.g. Smalltalk, Scala, perhaps Python), every type maps to a class.    &lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
===Type=== &lt;br /&gt;
A ''type'', in an object-oriented system, summarizes the common features of a set of objects with the same characteristics. It corresponds to the notion of an abstract data type. Type has 2 parts: the interface and the implementation(s). The interface, which is the only part visible to the user, consists of a list of operations and their signatures. The type implementation is of concern only to the type designer.&lt;br /&gt;
&lt;br /&gt;
===Class===&lt;br /&gt;
A ''class'', in object oriented systems, is a kind of metadata that describes the rules by which objects behave; these objects are referred to as instances of that class. A class specifies the structure of data (a.k.a. properties, fields, attributes, data members) within each instance as well as methods (functions) (a.k.a. behaviors) which manipulate the data of the object and perform tasks.&lt;br /&gt;
&lt;br /&gt;
==Types==&lt;br /&gt;
&lt;br /&gt;
Types are abstract views that define properties of a set of entities. Object-oriented programming languages must allow to implement these types. Consequently, once a type is implemented we have a particular representation of it available. We will use the seminal concept of the integer data type to explain the concept of type in detail. Programming languages such as C, Java, C++, Pascal and others already offer an implementation for it. Sometimes it is called int or integer. Once you've created a variable of this type you can use its provided operations. For example, you can add two integers: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
  int i, j, k;    /* Define three integers */&lt;br /&gt;
&lt;br /&gt;
  i = 1;          /* Assign 1 to integer i */&lt;br /&gt;
  j = 2;          /* Assign 2 to integer j */&lt;br /&gt;
  k = i + j;      /* Assign the sum of i and j to k */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first line defines three instances i, j and k of type Integer. Consequently, for each instance the special operation constructor should be called. In our example, this is internally done by the compiler. The compiler reserves memory to hold the value of an integer and ''binds'' the corresponding name to it. If you refer to i you actually refer to this memory area which was ''constructed'' by the definition of i. &lt;br /&gt;
&lt;br /&gt;
The implementation of types comprises of the data (internal structure of the object’s data) and operation (methods / procedures which implement the interface operations). By making users declare the types of variables at compile time, the system simplifies the procedure of checking the program correctness at compile time, thereby increasing programmer productivity. The types cannot be modified at run-time.&lt;br /&gt;
&lt;br /&gt;
===Properties of a Type===&lt;br /&gt;
* It exports a set of operations. This set is called interface. &lt;br /&gt;
* Operations of the interface are the one and only access mechanism to the type's data structure. &lt;br /&gt;
* Axioms and preconditions define the application domain of the type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
&lt;br /&gt;
A class is a combination of state (data) and behavior (methods) that manipulate the state. A class is a blueprint for an object.It is an actual representation of a type. It therefore provides implementation details for the data structure used and operations specified in the type. Now we will define a class that implements the Integer data type: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;  &lt;br /&gt;
class Integer {&lt;br /&gt;
  attributes: || implementation : &lt;br /&gt;
    int i /* Integer data type */&lt;br /&gt;
&lt;br /&gt;
  methods: || operation :&lt;br /&gt;
    setValue(int n) /* To assign value to i */&lt;br /&gt;
    Integer addValue(Integer j) /* To add integer j with i */&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this notation class {...} denotes the definition of a class. Enclosed in the curly brackets are two sections attributes: and methods: which define the implementation of the data structure and operations of the corresponding class. Again we distinguish the two levels with different terms: At the implementation level we speak of ''attributes'' which are elements of the data structure at the class level. The same applies to ''methods'' which are the implementation of the class operations. &lt;br /&gt;
In our example, the attribute is an ordinary integer of a programming language . We only define two methods setValue() and addValue() representing the two of the many operations that can be performed on an integer data type set and add, to make the comparison succinct and concise.&lt;br /&gt;
&lt;br /&gt;
Although the specification of a class is pretty similar to that of a type, it is more of a runtime notion. There are two major aspects of a class – an object factory and an object warehouse. The object factory is the means by which objects of a class are created, using the new operation on the class. Object warehouse stores the set of objects that are instances of the class. Users can work with all these objects by performing all the allowed operations on them and thereby change the contents of the object warehouse. Thus, classes by no means determine the correctness of a program, rather they are used to create and manipulate objects, thereby making the system more flexible.&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
The concept of ''type'' itself is an abstraction, such as it can be either a ''value type'' or a ''reference type''. In most languages, ''Type'' is the most general abstraction, categorized into ''value types'' and ''reference types''.&lt;br /&gt;
&lt;br /&gt;
Value types in turn can be of different kinds, such as the primitive types, but some languages also allow you to construct compound types which are classes. Reference types can also have different constructions, such as class as one and some would consider arrays as another.&lt;br /&gt;
&lt;br /&gt;
In reality, type is whatever a variable can be cast into. This includes both value types and reference types. Since the concepts of types and classes are tightly coupled, in this article we don't explicitly show direct contrasts between them, but rather subtly bring out the differences in their implementations in various programming languages.&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in C++==&lt;br /&gt;
&lt;br /&gt;
C++ supports three kinds of object types:&lt;br /&gt;
    * Fundamental types are built into the language (such as int, float, or double). Instances of these fundamental types are &lt;br /&gt;
      often called ''variables''.&lt;br /&gt;
    * Derived types are new types derived from built-in types.&lt;br /&gt;
    * Class types are new types created by combining existing types. These include Classes, Structures, and Unions.&lt;br /&gt;
&lt;br /&gt;
===Fundamental Types===&lt;br /&gt;
&lt;br /&gt;
Fundamental types in C++ are divided into three categories: integral, floating, and void. Integral types are capable of handling whole numbers. Floating types are capable of specifying values that may have fractional parts.The void type describes an empty set of values. No variable of type void can be specified — it is used primarily to declare functions that return no values or to declare generic pointers to untyped or arbitrarily typed data&lt;br /&gt;
&lt;br /&gt;
===Derived Types===&lt;br /&gt;
&lt;br /&gt;
Derived types are new types that can be used in a program, and can include directly derived types and composed derivative types.&lt;br /&gt;
====Directly Derived Types====&lt;br /&gt;
&lt;br /&gt;
New types derived directly from existing types are types that point to, refer to, or (in the case of functions) transform type data to return a new type.&lt;br /&gt;
&lt;br /&gt;
    * Arrays of Variables or Objects&lt;br /&gt;
    * Functions&lt;br /&gt;
    * Pointers of a Given Type&lt;br /&gt;
    * References to Objects&lt;br /&gt;
    * Constants&lt;br /&gt;
    * Pointers to Class Members&lt;br /&gt;
====Composed Derivative Types====&lt;br /&gt;
&lt;br /&gt;
The following are the various composed derivative types:&lt;br /&gt;
&lt;br /&gt;
    * Classes&lt;br /&gt;
    * Structures&lt;br /&gt;
    * Unions&lt;br /&gt;
&lt;br /&gt;
Class types are derivatives of composed types. More on class types below.&lt;br /&gt;
&lt;br /&gt;
===Class Types===&lt;br /&gt;
&lt;br /&gt;
Class types are defined using the class, struct, and union keywords. For simplicity, types defined with these keywords are called class declarations. Class Type names are introduced as identifiers immediately after the compiler processes them (before entry into the class body); they can be used to declare class members. This allows declaration of self-referential data structures&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define TRUE = 1&lt;br /&gt;
&lt;br /&gt;
class dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public:&lt;br /&gt;
   dog()&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(string dogSize)&lt;br /&gt;
   {&lt;br /&gt;
      _dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   string getDogSize()&lt;br /&gt;
   {&lt;br /&gt;
      return _dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(string breed)&lt;br /&gt;
   {&lt;br /&gt;
      _breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   private: // attributes || fundamental types&lt;br /&gt;
   string _dogSize, _breed;&lt;br /&gt;
   int _legs;&lt;br /&gt;
   bool _bark;&lt;br /&gt;
&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   dog mongrel;//class types&lt;br /&gt;
   //setting specific attributes that makes it different from types&lt;br /&gt;
   mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
   mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Ricky is a &amp;quot; &amp;lt;&amp;lt; mongrel.getDogSize() &amp;lt;&amp;lt; &amp;quot; sized dog&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Java==&lt;br /&gt;
&lt;br /&gt;
Java is a strongly typed language i.e. the type of every variable and expression used in a program must be known at compile time. The type of a variable / expression defines the range of values that it can hold. The type of a variable also determines the operations that can be performed on that variable. The strong typing nature of Java enables it to determine errors at compile time.Whenever a variable is declared in Java, we need to mention its type, which may be a class, interface or a primitive. When an object of a subclass of some other class is instantiated, we can say that the object is of type subclass and type superclass and it can perform all operations of both the subclass and the superclass.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are two different types in Java :&lt;br /&gt;
    * Primitive Types are boolean and numeric. The numeric types are the integral types byte, short, int, long, and char, and the         &lt;br /&gt;
      floating-point types float and double. &lt;br /&gt;
    * Reference Types are class types, interface types and array types.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|width=&amp;quot;100%&amp;quot;  border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; bordercolor = &amp;quot;black&amp;quot; cellspacing=&amp;quot;2&amp;quot; align = &amp;quot;left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!A side note on Null Types&lt;br /&gt;
|-&lt;br /&gt;
|There is also a special null type in Java, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Primitive Types====&lt;br /&gt;
&lt;br /&gt;
A primitive type is predefined by the Java programming language and named by its reserved keyword.Primitive values do not share state with other primitive values. A variable whose type is a primitive type always holds a primitive value of that same type. The value of a variable of primitive type can be changed only by assignment operations on that variable.&lt;br /&gt;
&lt;br /&gt;
====Reference Types====&lt;br /&gt;
&lt;br /&gt;
There are three kinds of reference types: class types, interface types, and array types.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt; &lt;br /&gt;
ReferenceType:&lt;br /&gt;
	ClassOrInterfaceType&lt;br /&gt;
	ArrayType&lt;br /&gt;
&lt;br /&gt;
ClassOrInterfaceType:&lt;br /&gt;
	ClassType&lt;br /&gt;
	InterfaceType&lt;br /&gt;
&lt;br /&gt;
ClassType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
InterfaceType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
ArrayType:&lt;br /&gt;
        [ ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
class Dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public Dog() //constructor&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(String dogSize) //setter method&lt;br /&gt;
   {&lt;br /&gt;
      this.dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   String getDogSize() //getter method&lt;br /&gt;
   {&lt;br /&gt;
      return this.dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(String breed)&lt;br /&gt;
   {&lt;br /&gt;
      this.breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   // attributes || fundamental types&lt;br /&gt;
   String dogSize = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   Sting breed = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   int legs;&lt;br /&gt;
   boolean bark;&lt;br /&gt;
   public static void main(String[] args)&lt;br /&gt;
   {&lt;br /&gt;
     Dog mongrel = new Dog();//class types&lt;br /&gt;
     //setting specific attributes that makes it different from types&lt;br /&gt;
     mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
     mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
     System.out.println(&amp;quot;Ricky is a &amp;quot;+ mongrel.getSize() +&amp;quot; size dog&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby being a dynamically typed, reflective object oriented language, every variable is an object and we do not explicitly mention their type as in other object oriented languages, rather the type is implicitly inferred from the type of the value which is assigned to them at runtime. Hence there is no distinction between primitive data types and object types in ruby. In Ruby, all classes are instances of the class Class. Whenever a new class is defined, an object of type Class is created and assigned to the ''Name'' of the class. ''Name.new'' is used to create a new object of the class. This invokes the ''new'' instance method in Class, which in turn calls the ''allocate'' method to allocate memory for the object, before finally calling the new object's initialize method. Thus, the construction of an object is separate from its initialization, and both can be over-ridden. The initialization is done via the ''initialize'' instance method while the construction is done via the ''new'' class method.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#since ruby is dynamic Oo language no explicit type assignment statements&lt;br /&gt;
class Dog &lt;br /&gt;
&lt;br /&gt;
   #implementation&lt;br /&gt;
   def initialize&lt;br /&gt;
      @legs = 4&lt;br /&gt;
      @bark = true&lt;br /&gt;
   end&lt;br /&gt;
   #attributes&lt;br /&gt;
   attr_accessor :dogSize, :breed &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
#at runtime   &lt;br /&gt;
mongrel = Dog.new #dynamiclly typed&lt;br /&gt;
#setting specific attributes that makes it different from types&lt;br /&gt;
mongrel.dogSize = &amp;quot;medium&amp;quot; # string class type&lt;br /&gt;
mongrel.breed = &amp;quot;country specific&amp;quot; # string class type&lt;br /&gt;
puts &amp;quot;Ricky is a #{mongrel.dogSize} size dog&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.cmu.edu/People/clamen/OODBMS/Manifesto/htManifesto/node6.html Types and Classes]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object-oriented_programming Object Oriented Programming concepts on Wikipedia]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://haskell.org/haskellwiki/OOP_vs_type_classes OOP vs type classes]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html Java Language Specification,Second Edition Chapter4: Types, Values, Variables]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikibooks.org/wiki/Java_Programming/Types Java Programming/Types on Wikipedia]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://rubylearning.com/satishtalim/writing_our_own_class_in_ruby.html Writing Classes in Ruby and Insipration for Example]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.velocityreviews.com/forums/t127376-what-is-the-difference-between-class-and-type.html What is the difference between class and type]&lt;br /&gt;
&lt;br /&gt;
==Further Reading / External Links== &lt;br /&gt;
&lt;br /&gt;
Bjarne Stroustrup's article on OOP in C++ and beyond http://www.research.att.com/~bs/bs_faq.html#oop&amp;lt;br&amp;gt;&lt;br /&gt;
B. Stroustrup, The C++ Programming Language, 3rd-ed., p. 158&amp;lt;br&amp;gt;&lt;br /&gt;
Fundamentals of OOP and Data Structures in Java - Page xiii by Richard Wiener, Lewis J. Pinson &amp;lt;br&amp;gt;&lt;br /&gt;
Type vs Class, A general overview http://lambda-the-ultimate.org/node/2079&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=8003</id>
		<title>CSC/ECE 517 Fall 2007/wiki2 6 ap</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=8003"/>
		<updated>2007-10-29T06:03:36Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Type vs. class. Survey the differences on type vs. class in object-oriented languages. Often, the distinction is that class pertains to an object, whereas type pertains to a variable. Consider the distinction between the two terms in several different programming languages. Cover the differences between type and class, from type-theoretic definitions to practical aspects.''&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
In object oriented programming concepts, the difference between types and classes is not clearly understood. The differences between them are subtle and the two terms are often misunderstood to be the same. In the article we try to bring out the differences between Types and Classes and provide more insight into them. Furthermore, in OOP languages, classes are types, while most types are not classes. In pure object languages, by opposition (e.g. Smalltalk, Scala, perhaps Python), every type maps to a class.    &lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
===Type=== &lt;br /&gt;
A ''type'', in an object-oriented system, summarizes the common features of a set of objects with the same characteristics. It corresponds to the notion of an abstract data type. Type has 2 parts: the interface and the implementation(s). The interface, which is the only part visible to the user, consists of a list of operations and their signatures. The type implementation is of concern only to the type designer.&lt;br /&gt;
&lt;br /&gt;
===Class===&lt;br /&gt;
A ''class'', in object oriented systems, is a kind of metadata that describes the rules by which objects behave; these objects are referred to as instances of that class. A class specifies the structure of data (a.k.a. properties, fields, attributes, data members) within each instance as well as methods (functions) (a.k.a. behaviors) which manipulate the data of the object and perform tasks.&lt;br /&gt;
&lt;br /&gt;
==Types==&lt;br /&gt;
&lt;br /&gt;
Types are abstract views that define properties of a set of entities. Object-oriented programming languages must allow to implement these types. Consequently, once a type is implemented we have a particular representation of it available. We will use the seminal concept of the integer data type to explain the concept of type in detail. Programming languages such as C, Java, C++, Pascal and others already offer an implementation for it. Sometimes it is called int or integer. Once you've created a variable of this type you can use its provided operations. For example, you can add two integers: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
  int i, j, k;    /* Define three integers */&lt;br /&gt;
&lt;br /&gt;
  i = 1;          /* Assign 1 to integer i */&lt;br /&gt;
  j = 2;          /* Assign 2 to integer j */&lt;br /&gt;
  k = i + j;      /* Assign the sum of i and j to k */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first line defines three instances i, j and k of type Integer. Consequently, for each instance the special operation constructor should be called. In our example, this is internally done by the compiler. The compiler reserves memory to hold the value of an integer and ''binds'' the corresponding name to it. If you refer to i you actually refer to this memory area which was ''constructed'' by the definition of i. &lt;br /&gt;
&lt;br /&gt;
The implementation of types comprises of the data (internal structure of the object’s data) and operation (methods / procedures which implement the interface operations). By making users declare the types of variables at compile time, the system simplifies the procedure of checking the program correctness at compile time, thereby increasing programmer productivity. The types cannot be modified at run-time.&lt;br /&gt;
&lt;br /&gt;
===Properties of a Type===&lt;br /&gt;
* It exports a set of operations. This set is called interface. &lt;br /&gt;
* Operations of the interface are the one and only access mechanism to the type's data structure. &lt;br /&gt;
* Axioms and preconditions define the application domain of the type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
&lt;br /&gt;
A class is a combination of state (data) and behavior (methods) that manipulate the state. A class is a blueprint for an object.It is an actual representation of a type. It therefore provides implementation details for the data structure used and operations specified in the type. Now we will define a class that implements the Integer data type: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;  &lt;br /&gt;
class Integer {&lt;br /&gt;
  attributes: || implementation : &lt;br /&gt;
    int i /* Integer data type */&lt;br /&gt;
&lt;br /&gt;
  methods: || operation :&lt;br /&gt;
    setValue(int n) /* To assign value to i */&lt;br /&gt;
    Integer addValue(Integer j) /* To add integer j with i */&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this notation class {...} denotes the definition of a class. Enclosed in the curly brackets are two sections attributes: and methods: which define the implementation of the data structure and operations of the corresponding class. Again we distinguish the two levels with different terms: At the implementation level we speak of ''attributes'' which are elements of the data structure at the class level. The same applies to ''methods'' which are the implementation of the class operations. &lt;br /&gt;
In our example, the attribute is an ordinary integer of a programming language . We only define two methods setValue() and addValue() representing the two of the many operations that can be performed on an integer data type set and add, to make the comparison succinct and concise.&lt;br /&gt;
&lt;br /&gt;
Although the specification of a class is pretty similar to that of a type, it is more of a runtime notion. There are two major aspects of a class – an object factory and an object warehouse. The object factory is the means by which objects of a class are created, using the new operation on the class. Object warehouse stores the set of objects that are instances of the class. Users can work with all these objects by performing all the allowed operations on them and thereby change the contents of the object warehouse. Thus, classes by no means determine the correctness of a program, rather they are used to create and manipulate objects, thereby making the system more flexible.&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
The concept of ''type'' itself is an abstraction, such as it can be either a ''value type'' or a ''reference type''. In most languages, ''Type'' is the most general abstraction, categorized into ''value types'' and ''reference types''.&lt;br /&gt;
&lt;br /&gt;
Value types in turn can be of different kinds, such as the primitive types, but some languages also allow you to construct compound types which are classes. Reference types can also have different constructions, such as class as one and some would consider arrays as another.&lt;br /&gt;
&lt;br /&gt;
In reality, type is whatever a variable can be cast into. This includes both value types and reference types. Since the concepts of types and classes are tightly coupled, in this article we don't explicitly show direct contrasts between them, but rather subtly bring out the differences in their implementations in various programming languages.&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in C++==&lt;br /&gt;
&lt;br /&gt;
C++ supports three kinds of object types:&lt;br /&gt;
    * Fundamental types are built into the language (such as int, float, or double). Instances of these fundamental types are &lt;br /&gt;
      often called ''variables''.&lt;br /&gt;
    * Derived types are new types derived from built-in types.&lt;br /&gt;
    * Class types are new types created by combining existing types. These include Classes, Structures, and Unions.&lt;br /&gt;
&lt;br /&gt;
===Fundamental Types===&lt;br /&gt;
&lt;br /&gt;
Fundamental types in C++ are divided into three categories: integral, floating, and void. Integral types are capable of handling whole numbers. Floating types are capable of specifying values that may have fractional parts.The void type describes an empty set of values. No variable of type void can be specified — it is used primarily to declare functions that return no values or to declare generic pointers to untyped or arbitrarily typed data&lt;br /&gt;
&lt;br /&gt;
===Derived Types===&lt;br /&gt;
&lt;br /&gt;
Derived types are new types that can be used in a program, and can include directly derived types and composed derivative types.&lt;br /&gt;
====Directly Derived Types====&lt;br /&gt;
&lt;br /&gt;
New types derived directly from existing types are types that point to, refer to, or (in the case of functions) transform type data to return a new type.&lt;br /&gt;
&lt;br /&gt;
    * Arrays of Variables or Objects&lt;br /&gt;
    * Functions&lt;br /&gt;
    * Pointers of a Given Type&lt;br /&gt;
    * References to Objects&lt;br /&gt;
    * Constants&lt;br /&gt;
    * Pointers to Class Members&lt;br /&gt;
====Composed Derivative Types====&lt;br /&gt;
&lt;br /&gt;
The following are the various composed derivative types:&lt;br /&gt;
&lt;br /&gt;
    * Classes&lt;br /&gt;
    * Structures&lt;br /&gt;
    * Unions&lt;br /&gt;
&lt;br /&gt;
Class types are derivatives of composed types. More on class types below.&lt;br /&gt;
&lt;br /&gt;
===Class Types===&lt;br /&gt;
&lt;br /&gt;
Class types are defined using the class, struct, and union keywords. For simplicity, types defined with these keywords are called class declarations. Class Type names are introduced as identifiers immediately after the compiler processes them (before entry into the class body); they can be used to declare class members. This allows declaration of self-referential data structures&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define TRUE = 1&lt;br /&gt;
&lt;br /&gt;
class dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public:&lt;br /&gt;
   dog()&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(string dogSize)&lt;br /&gt;
   {&lt;br /&gt;
      _dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   string getDogSize()&lt;br /&gt;
   {&lt;br /&gt;
      return _dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(string breed)&lt;br /&gt;
   {&lt;br /&gt;
      _breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   private: // attributes || fundamental types&lt;br /&gt;
   string _dogSize, _breed;&lt;br /&gt;
   int _legs;&lt;br /&gt;
   bool _bark;&lt;br /&gt;
&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   dog mongrel;//class types&lt;br /&gt;
   //setting specific attributes that makes it different from types&lt;br /&gt;
   mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
   mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Ricky is a &amp;quot; &amp;lt;&amp;lt; mongrel.getDogSize() &amp;lt;&amp;lt; &amp;quot; sized dog&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Java==&lt;br /&gt;
&lt;br /&gt;
Java is a strongly typed language i.e. the type of every variable and expression used in a program must be known at compile time. The type of a variable / expression defines the range of values that it can hold. The type of a variable also determines the operations that can be performed on that variable. The strong typing nature of Java enables it to determine errors at compile time.Whenever a variable is declared in Java, we need to mention its type, which may be a class, interface or a primitive. When an object of a subclass of some other class is instantiated, we can say that the object is of type subclass and type superclass and it can perform all operations of both the subclass and the superclass.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are two different types in Java :&lt;br /&gt;
    * Primitive Types are boolean and numeric. The numeric types are the integral types byte, short, int, long, and char, and the         &lt;br /&gt;
      floating-point types float and double. &lt;br /&gt;
    * Reference Types are class types, interface types and array types.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|width=&amp;quot;100%&amp;quot;  border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; bordercolor = &amp;quot;black&amp;quot; cellspacing=&amp;quot;2&amp;quot; align = &amp;quot;left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!A side note on Null Types&lt;br /&gt;
|-&lt;br /&gt;
|There is also a special null type in Java, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Primitive Types====&lt;br /&gt;
&lt;br /&gt;
A primitive type is predefined by the Java programming language and named by its reserved keyword.Primitive values do not share state with other primitive values. A variable whose type is a primitive type always holds a primitive value of that same type. The value of a variable of primitive type can be changed only by assignment operations on that variable.&lt;br /&gt;
&lt;br /&gt;
====Reference Types====&lt;br /&gt;
&lt;br /&gt;
There are three kinds of reference types: class types, interface types, and array types.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt; &lt;br /&gt;
ReferenceType:&lt;br /&gt;
	ClassOrInterfaceType&lt;br /&gt;
	ArrayType&lt;br /&gt;
&lt;br /&gt;
ClassOrInterfaceType:&lt;br /&gt;
	ClassType&lt;br /&gt;
	InterfaceType&lt;br /&gt;
&lt;br /&gt;
ClassType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
InterfaceType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
ArrayType:&lt;br /&gt;
        [ ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
class Dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public Dog() //constructor&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(String dogSize) //setter method&lt;br /&gt;
   {&lt;br /&gt;
      this.dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   String getDogSize() //getter method&lt;br /&gt;
   {&lt;br /&gt;
      return this.dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(String breed)&lt;br /&gt;
   {&lt;br /&gt;
      this.breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   // attributes || fundamental types&lt;br /&gt;
   String dogSize = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   Sting breed = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   int legs;&lt;br /&gt;
   boolean bark;&lt;br /&gt;
   public static void main(String[] args)&lt;br /&gt;
   {&lt;br /&gt;
     Dog mongrel = new Dog();//class types&lt;br /&gt;
     //setting specific attributes that makes it different from types&lt;br /&gt;
     mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
     mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
     System.out.println(&amp;quot;Ricky is a &amp;quot;+ mongrel.getSize() +&amp;quot; size dog&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby being a dynamically typed, reflective object oriented language, every variable is an object and we do not explicitly mention their type as in other object oriented languages, rather the type is implicitly inferred from the type of the value which is assigned to them at runtime. Hence there is no distinction between primitive data types and object types in ruby. In Ruby, all classes are instances of the class Class. Whenever a new class is defined, an object of type Class is created and assigned to the ''Name'' of the class. ''Name.new'' is used to create a new object of the class. This invokes the ''new'' instance method in Class, which in turn calls the ''allocate'' method to allocate memory for the object, before finally calling the new object's initialize method. Thus, the construction of an object is separate from its initialization, and both can be over-ridden. The initialization is done via the ''initialize'' instance method while the construction is done via the ''new'' class method.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#since ruby is dynamic Oo language no explicit type assignment statements&lt;br /&gt;
class Dog &lt;br /&gt;
&lt;br /&gt;
   #implementation&lt;br /&gt;
   def initialize&lt;br /&gt;
      @legs = 4&lt;br /&gt;
      @bark = true&lt;br /&gt;
   end&lt;br /&gt;
   #attributes&lt;br /&gt;
   attr_accessor :dogSize, :breed &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
#at runtime   &lt;br /&gt;
mongrel = Dog.new #dynamiclly typed&lt;br /&gt;
#setting specific attributes that makes it different from types&lt;br /&gt;
mongrel.dogSize = &amp;quot;medium&amp;quot; # string class type&lt;br /&gt;
mongrel.breed = &amp;quot;country specific&amp;quot; # string class type&lt;br /&gt;
puts &amp;quot;Ricky is a #{mongrel.dogSize} size dog&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.cmu.edu/People/clamen/OODBMS/Manifesto/htManifesto/node6.html Types and Classes]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object-oriented_programming Object Oriented Programming concepts on Wikipedia]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://haskell.org/haskellwiki/OOP_vs_type_classes OOP vs type classes]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html Java Language Specification,Second Edition Chapter4: Types, Values, Variables]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikibooks.org/wiki/Java_Programming/Types Java Programming/Types on Wikipedia]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://rubylearning.com/satishtalim/writing_our_own_class_in_ruby.html Writing Classes in Ruby and Insipration for Example]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.velocityreviews.com/forums/t127376-what-is-the-difference-between-class-and-type.html What is the difference between class and type]&lt;br /&gt;
&lt;br /&gt;
==Further Reading / External Links== &lt;br /&gt;
&lt;br /&gt;
Bjarne Stroustrup's article on OOP in C++ and beyond http://www.research.att.com/~bs/bs_faq.html#oop&amp;lt;br&amp;gt;&lt;br /&gt;
B. Stroustrup, The C++ Programming Language, 3rd-ed., p. 158&amp;lt;br&amp;gt;&lt;br /&gt;
Fundamentals of OOP and Data Structures in Java - Page xiii by Richard Wiener, Lewis J. Pinson &amp;lt;br&amp;gt;&lt;br /&gt;
Type vs Class, A general overview http://lambda-the-ultimate.org/node/2079&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=8002</id>
		<title>CSC/ECE 517 Fall 2007/wiki2 6 ap</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=8002"/>
		<updated>2007-10-29T06:01:29Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Type vs. class. Survey the differences on type vs. class in object-oriented languages. Often, the distinction is that class pertains to an object, whereas type pertains to a variable. Consider the distinction between the two terms in several different programming languages. Cover the differences between type and class, from type-theoretic definitions to practical aspects.''&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
In object oriented programming concepts, the difference between types and classes is not clearly understood. The differences between them are subtle and the two terms are often misunderstood to be the same. In the article we try to bring out the differences between Types and Classes and provide more insight into them. Furthermore, in OOP languages, classes are types, while most types are not classes. In pure object languages, by opposition (e.g. Smalltalk, Scala, perhaps Python), every type maps to a class.    &lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
===Type=== &lt;br /&gt;
A ''type'', in an object-oriented system, summarizes the common features of a set of objects with the same characteristics. It corresponds to the notion of an abstract data type. Type has 2 parts: the interface and the implementation(s). The interface, which is the only part visible to the user, consists of a list of operations and their signatures. The type implementation is of concern only to the type designer.&lt;br /&gt;
&lt;br /&gt;
===Class===&lt;br /&gt;
A ''class'', in object oriented systems, is a kind of metadata that describes the rules by which objects behave; these objects are referred to as instances of that class. A class specifies the structure of data (a.k.a. properties, fields, attributes, data members) within each instance as well as methods (functions) (a.k.a. behaviors) which manipulate the data of the object and perform tasks.&lt;br /&gt;
&lt;br /&gt;
==Types==&lt;br /&gt;
&lt;br /&gt;
Types are abstract views that define properties of a set of entities. Object-oriented programming languages must allow to implement these types. Consequently, once a type is implemented we have a particular representation of it available. We will use the seminal concept of the integer data type to explain the concept of type in detail. Programming languages such as C, Java, C++, Pascal and others already offer an implementation for it. Sometimes it is called int or integer. Once you've created a variable of this type you can use its provided operations. For example, you can add two integers: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
  int i, j, k;    /* Define three integers */&lt;br /&gt;
&lt;br /&gt;
  i = 1;          /* Assign 1 to integer i */&lt;br /&gt;
  j = 2;          /* Assign 2 to integer j */&lt;br /&gt;
  k = i + j;      /* Assign the sum of i and j to k */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first line defines three instances i, j and k of type Integer. Consequently, for each instance the special operation constructor should be called. In our example, this is internally done by the compiler. The compiler reserves memory to hold the value of an integer and ''binds'' the corresponding name to it. If you refer to i you actually refer to this memory area which was ''constructed'' by the definition of i. &lt;br /&gt;
&lt;br /&gt;
The implementation of types comprises of the data (internal structure of the object’s data) and operation (methods / procedures which implement the interface operations). By making users declare the types of variables at compile time, the system simplifies the procedure of checking the program correctness at compile time, thereby increasing programmer productivity. The types cannot be modified at run-time.&lt;br /&gt;
&lt;br /&gt;
===Properties of a Type===&lt;br /&gt;
* It exports a set of operations. This set is called interface. &lt;br /&gt;
* Operations of the interface are the one and only access mechanism to the type's data structure. &lt;br /&gt;
* Axioms and preconditions define the application domain of the type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
&lt;br /&gt;
A class is a combination of state (data) and behavior (methods) that manipulate the state. A class is a blueprint for an object.It is an actual representation of a type. It therefore provides implementation details for the data structure used and operations specified in the type. Now we will define a class that implements the Integer data type: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;  &lt;br /&gt;
class Integer {&lt;br /&gt;
  attributes: || implementation : &lt;br /&gt;
    int i /* Integer data type */&lt;br /&gt;
&lt;br /&gt;
  methods: || operation :&lt;br /&gt;
    setValue(int n) /* To assign value to i */&lt;br /&gt;
    Integer addValue(Integer j) /* To add integer j with i */&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this notation class {...} denotes the definition of a class. Enclosed in the curly brackets are two sections attributes: and methods: which define the implementation of the data structure and operations of the corresponding class. Again we distinguish the two levels with different terms: At the implementation level we speak of ''attributes'' which are elements of the data structure at the class level. The same applies to ''methods'' which are the implementation of the class operations. &lt;br /&gt;
In our example, the attribute is an ordinary integer of a programming language . We only define two methods setValue() and addValue() representing the two of the many operations that can be performed on an integer data type set and add, to make the comparison succinct and concise.&lt;br /&gt;
&lt;br /&gt;
Although the specification of a class is pretty similar to that of a type, it is more of a runtime notion. There are two major aspects of a class – an object factory and an object warehouse. The object factory is the means by which objects of a class are created, using the new operation on the class. Object warehouse stores the set of objects that are instances of the class. Users can work with all these objects by performing all the allowed operations on them and thereby change the contents of the object warehouse. Thus, classes by no means determine the correctness of a program, rather they are used to create and manipulate objects, thereby making the system more flexible.&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
The concept of ''type'' itself is an abstraction, such as it can be either a ''value type'' or a ''reference type''. In most languages, ''Type'' is the most general abstraction, categorized into ''value types'' and ''reference types''.&lt;br /&gt;
&lt;br /&gt;
Value types in turn can be of different kinds, such as the primitive types, but some languages also allow you to construct compound types which are classes. Reference types can also have different constructions, such as class as one and some would consider arrays as another.&lt;br /&gt;
&lt;br /&gt;
In reality, type is whatever you can assign as a type to a variable. This includes both value types and reference types. Since the concepts of types and classes are tightly coupled, in this article we don't explicitly show direct contrasts between them, but rather subtly bring out the differences in their implementations in various programming languages.&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in C++==&lt;br /&gt;
&lt;br /&gt;
C++ supports three kinds of object types:&lt;br /&gt;
    * Fundamental types are built into the language (such as int, float, or double). Instances of these fundamental types are &lt;br /&gt;
      often called ''variables''.&lt;br /&gt;
    * Derived types are new types derived from built-in types.&lt;br /&gt;
    * Class types are new types created by combining existing types. These include Classes, Structures, and Unions.&lt;br /&gt;
&lt;br /&gt;
===Fundamental Types===&lt;br /&gt;
&lt;br /&gt;
Fundamental types in C++ are divided into three categories: integral, floating, and void. Integral types are capable of handling whole numbers. Floating types are capable of specifying values that may have fractional parts.The void type describes an empty set of values. No variable of type void can be specified — it is used primarily to declare functions that return no values or to declare generic pointers to untyped or arbitrarily typed data&lt;br /&gt;
&lt;br /&gt;
===Derived Types===&lt;br /&gt;
&lt;br /&gt;
Derived types are new types that can be used in a program, and can include directly derived types and composed derivative types.&lt;br /&gt;
====Directly Derived Types====&lt;br /&gt;
&lt;br /&gt;
New types derived directly from existing types are types that point to, refer to, or (in the case of functions) transform type data to return a new type.&lt;br /&gt;
&lt;br /&gt;
    * Arrays of Variables or Objects&lt;br /&gt;
    * Functions&lt;br /&gt;
    * Pointers of a Given Type&lt;br /&gt;
    * References to Objects&lt;br /&gt;
    * Constants&lt;br /&gt;
    * Pointers to Class Members&lt;br /&gt;
====Composed Derivative Types====&lt;br /&gt;
&lt;br /&gt;
The following are the various composed derivative types:&lt;br /&gt;
&lt;br /&gt;
    * Classes&lt;br /&gt;
    * Structures&lt;br /&gt;
    * Unions&lt;br /&gt;
&lt;br /&gt;
Class types are derivatives of composed types. More on class types below.&lt;br /&gt;
&lt;br /&gt;
===Class Types===&lt;br /&gt;
&lt;br /&gt;
Class types are defined using the class, struct, and union keywords. For simplicity, types defined with these keywords are called class declarations. Class Type names are introduced as identifiers immediately after the compiler processes them (before entry into the class body); they can be used to declare class members. This allows declaration of self-referential data structures&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define TRUE = 1&lt;br /&gt;
&lt;br /&gt;
class dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public:&lt;br /&gt;
   dog()&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(string dogSize)&lt;br /&gt;
   {&lt;br /&gt;
      _dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   string getDogSize()&lt;br /&gt;
   {&lt;br /&gt;
      return _dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(string breed)&lt;br /&gt;
   {&lt;br /&gt;
      _breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   private: // attributes || fundamental types&lt;br /&gt;
   string _dogSize, _breed;&lt;br /&gt;
   int _legs;&lt;br /&gt;
   bool _bark;&lt;br /&gt;
&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   dog mongrel;//class types&lt;br /&gt;
   //setting specific attributes that makes it different from types&lt;br /&gt;
   mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
   mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Ricky is a &amp;quot; &amp;lt;&amp;lt; mongrel.getDogSize() &amp;lt;&amp;lt; &amp;quot; sized dog&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Java==&lt;br /&gt;
&lt;br /&gt;
Java is a strongly typed language i.e. the type of every variable and expression used in a program must be known at compile time. The type of a variable / expression defines the range of values that it can hold. The type of a variable also determines the operations that can be performed on that variable. The strong typing nature of Java enables it to determine errors at compile time.Whenever a variable is declared in Java, we need to mention its type, which may be a class, interface or a primitive. When an object of a subclass of some other class is instantiated, we can say that the object is of type subclass and type superclass and it can perform all operations of both the subclass and the superclass.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are two different types in Java :&lt;br /&gt;
    * Primitive Types are boolean and numeric. The numeric types are the integral types byte, short, int, long, and char, and the         &lt;br /&gt;
      floating-point types float and double. &lt;br /&gt;
    * Reference Types are class types, interface types and array types.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|width=&amp;quot;100%&amp;quot;  border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; bordercolor = &amp;quot;black&amp;quot; cellspacing=&amp;quot;2&amp;quot; align = &amp;quot;left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!A side note on Null Types&lt;br /&gt;
|-&lt;br /&gt;
|There is also a special null type in Java, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Primitive Types====&lt;br /&gt;
&lt;br /&gt;
A primitive type is predefined by the Java programming language and named by its reserved keyword.Primitive values do not share state with other primitive values. A variable whose type is a primitive type always holds a primitive value of that same type. The value of a variable of primitive type can be changed only by assignment operations on that variable.&lt;br /&gt;
&lt;br /&gt;
====Reference Types====&lt;br /&gt;
&lt;br /&gt;
There are three kinds of reference types: class types, interface types, and array types.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt; &lt;br /&gt;
ReferenceType:&lt;br /&gt;
	ClassOrInterfaceType&lt;br /&gt;
	ArrayType&lt;br /&gt;
&lt;br /&gt;
ClassOrInterfaceType:&lt;br /&gt;
	ClassType&lt;br /&gt;
	InterfaceType&lt;br /&gt;
&lt;br /&gt;
ClassType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
InterfaceType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
ArrayType:&lt;br /&gt;
        [ ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
class Dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public Dog() //constructor&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(String dogSize) //setter method&lt;br /&gt;
   {&lt;br /&gt;
      this.dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   String getDogSize() //getter method&lt;br /&gt;
   {&lt;br /&gt;
      return this.dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(String breed)&lt;br /&gt;
   {&lt;br /&gt;
      this.breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   // attributes || fundamental types&lt;br /&gt;
   String dogSize = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   Sting breed = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   int legs;&lt;br /&gt;
   boolean bark;&lt;br /&gt;
   public static void main(String[] args)&lt;br /&gt;
   {&lt;br /&gt;
     Dog mongrel = new Dog();//class types&lt;br /&gt;
     //setting specific attributes that makes it different from types&lt;br /&gt;
     mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
     mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
     System.out.println(&amp;quot;Ricky is a &amp;quot;+ mongrel.getSize() +&amp;quot; size dog&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby being a dynamically typed, reflective object oriented language, every variable is an object and we do not explicitly mention their type as in other object oriented languages, rather the type is implicitly inferred from the type of the value which is assigned to them at runtime. Hence there is no distinction between primitive data types and object types in ruby. In Ruby, all classes are instances of the class Class. Whenever a new class is defined, an object of type Class is created and assigned to the ''Name'' of the class. ''Name.new'' is used to create a new object of the class. This invokes the ''new'' instance method in Class, which in turn calls the ''allocate'' method to allocate memory for the object, before finally calling the new object's initialize method. Thus, the construction of an object is separate from its initialization, and both can be over-ridden. The initialization is done via the ''initialize'' instance method while the construction is done via the ''new'' class method.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#since ruby is dynamic Oo language no explicit type assignment statements&lt;br /&gt;
class Dog &lt;br /&gt;
&lt;br /&gt;
   #implementation&lt;br /&gt;
   def initialize&lt;br /&gt;
      @legs = 4&lt;br /&gt;
      @bark = true&lt;br /&gt;
   end&lt;br /&gt;
   #attributes&lt;br /&gt;
   attr_accessor :dogSize, :breed &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
#at runtime   &lt;br /&gt;
mongrel = Dog.new #dynamiclly typed&lt;br /&gt;
#setting specific attributes that makes it different from types&lt;br /&gt;
mongrel.dogSize = &amp;quot;medium&amp;quot; # string class type&lt;br /&gt;
mongrel.breed = &amp;quot;country specific&amp;quot; # string class type&lt;br /&gt;
puts &amp;quot;Ricky is a #{mongrel.dogSize} size dog&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.cmu.edu/People/clamen/OODBMS/Manifesto/htManifesto/node6.html Types and Classes]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object-oriented_programming Object Oriented Programming concepts on Wikipedia]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://haskell.org/haskellwiki/OOP_vs_type_classes OOP vs type classes]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html Java Language Specification,Second Edition Chapter4: Types, Values, Variables]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikibooks.org/wiki/Java_Programming/Types Java Programming/Types on Wikipedia]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://rubylearning.com/satishtalim/writing_our_own_class_in_ruby.html Writing Classes in Ruby and Insipration for Example]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.velocityreviews.com/forums/t127376-what-is-the-difference-between-class-and-type.html What is the difference between class and type]&lt;br /&gt;
&lt;br /&gt;
==Further Reading / External Links== &lt;br /&gt;
&lt;br /&gt;
Bjarne Stroustrup's article on OOP in C++ and beyond http://www.research.att.com/~bs/bs_faq.html#oop&amp;lt;br&amp;gt;&lt;br /&gt;
B. Stroustrup, The C++ Programming Language, 3rd-ed., p. 158&amp;lt;br&amp;gt;&lt;br /&gt;
Fundamentals of OOP and Data Structures in Java - Page xiii by Richard Wiener, Lewis J. Pinson &amp;lt;br&amp;gt;&lt;br /&gt;
Type vs Class, A general overview http://lambda-the-ultimate.org/node/2079&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=8001</id>
		<title>CSC/ECE 517 Fall 2007/wiki2 6 ap</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=8001"/>
		<updated>2007-10-29T06:00:14Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Type vs. class. Survey the differences on type vs. class in object-oriented languages. Often, the distinction is that class pertains to an object, whereas type pertains to a variable. Consider the distinction between the two terms in several different programming languages. Cover the differences between type and class, from type-theoretic definitions to practical aspects.''&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
In object oriented programming concepts, the difference between types and classes is not clearly understood. The differences between them are subtle and the two terms are often misunderstood to be the same. In the article we try to bring out the differences between Types and Classes and provide more insight into them. Furthermore, in OOP languages, classes are types, while most types are not classes. In pure object languages, by opposition (e.g. Smalltalk, Scala, perhaps Python), every type maps to a class.    &lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
===Type=== &lt;br /&gt;
A ''type'', in an object-oriented system, summarizes the common features of a set of objects with the same characteristics. It corresponds to the notion of an abstract data type. Type has 2 parts: the interface and the implementation(s). The interface, which is the only part visible to the user, consists of a list of operations and their signatures. The type implementation is of concern only to the type designer.&lt;br /&gt;
&lt;br /&gt;
===Class===&lt;br /&gt;
A ''class'', in object oriented systems, is a kind of metadata that describes the rules by which objects behave; these objects are referred to as instances of that class. A class specifies the structure of data (a.k.a. properties, fields, attributes, data members) within each instance as well as methods (functions) (a.k.a. behaviors) which manipulate the data of the object and perform tasks.&lt;br /&gt;
&lt;br /&gt;
==Types==&lt;br /&gt;
&lt;br /&gt;
Types are abstract views that define properties of a set of entities. Object-oriented programming languages must allow to implement these types. Consequently, once a type is implemented we have a particular representation of it available. We will use the seminal concept of the integer data type to explain the concept of type in detail. Programming languages such as C, Java, C++, Pascal and others already offer an implementation for it. Sometimes it is called int or integer. Once you've created a variable of this type you can use its provided operations. For example, you can add two integers: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
  int i, j, k;    /* Define three integers */&lt;br /&gt;
&lt;br /&gt;
  i = 1;          /* Assign 1 to integer i */&lt;br /&gt;
  j = 2;          /* Assign 2 to integer j */&lt;br /&gt;
  k = i + j;      /* Assign the sum of i and j to k */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first line defines three instances i, j and k of type Integer. Consequently, for each instance the special operation constructor should be called. In our example, this is internally done by the compiler. The compiler reserves memory to hold the value of an integer and ''binds'' the corresponding name to it. If you refer to i you actually refer to this memory area which was ''constructed'' by the definition of i. &lt;br /&gt;
&lt;br /&gt;
The implementation of types comprises of the data (internal structure of the object’s data) and operation (methods / procedures which implement the interface operations). By making users declare the types of variables at compile time, the system simplifies the procedure of checking the program correctness at compile time, thereby increasing programmer productivity. The types cannot be modified at run-time.&lt;br /&gt;
&lt;br /&gt;
===Properties of a Type===&lt;br /&gt;
* It exports a set of operations. This set is called interface. &lt;br /&gt;
* Operations of the interface are the one and only access mechanism to the type's data structure. &lt;br /&gt;
* Axioms and preconditions define the application domain of the type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
&lt;br /&gt;
A class is a combination of state (data) and behavior (methods) that manipulate the state. A class is a blueprint for an object.It is an actual representation of a type. It therefore provides implementation details for the data structure used and operations specified in the type. Now we will define a class that implements the Integer data type: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;  &lt;br /&gt;
class Integer {&lt;br /&gt;
  attributes: || implementation : &lt;br /&gt;
    int i /* Integer data type */&lt;br /&gt;
&lt;br /&gt;
  methods: || operation :&lt;br /&gt;
    setValue(int n) /* To assign value to i */&lt;br /&gt;
    Integer addValue(Integer j) /* To add integer j with i */&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this notation class {...} denotes the definition of a class. Enclosed in the curly brackets are two sections attributes: and methods: which define the implementation of the data structure and operations of the corresponding class. Again we distinguish the two levels with different terms: At the implementation level we speak of ''attributes'' which are elements of the data structure at the class level. The same applies to ''methods'' which are the implementation of the class operations. &lt;br /&gt;
In our example, the attribute is an ordinary integer of a programming language . We only define two methods setValue() and addValue() representing the two of the many operations that can be performed on an integer data type set and add, to make the comparison succinct and concise.&lt;br /&gt;
&lt;br /&gt;
Although the specification of a class is pretty similar to that of a type, it is more of a runtime notion. There are two major aspects of a class – an object factory and an object warehouse. The object factory is the means by which objects of a class are created, using the new operation on the class. Object warehouse stores the set of objects that are instances of the class. Users can work with all these objects by performing all the allowed operations on them and thereby change the contents of the object warehouse. Thus, classes by no means determine the correctness of a program, rather they are used to create and manipulate objects, thereby making the system more flexible.&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
The concept of ''type'' itself is an abstraction, such as it can be either a ''value type'' or a ''reference type''. In most languages, ''Type'' is the most general abstraction, with ''value types'' and ''reference types'' as subtypes of the general type.&lt;br /&gt;
&lt;br /&gt;
Value types in turn can be of different kinds, such as the primitive types, but some languages also allow you to construct compound types which are classes. Reference types can also have different constructions, such as class as one and some would consider arrays as another.&lt;br /&gt;
&lt;br /&gt;
In reality, type is whatever you can assign as a type to a variable. This includes both value types and reference types. Since the concepts of types and classes are tightly coupled, in this article we don't explicitly show direct contrasts between them, but rather subtly bring out the differences in their implementations in various programming languages.&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in C++==&lt;br /&gt;
&lt;br /&gt;
C++ supports three kinds of object types:&lt;br /&gt;
    * Fundamental types are built into the language (such as int, float, or double). Instances of these fundamental types are &lt;br /&gt;
      often called ''variables''.&lt;br /&gt;
    * Derived types are new types derived from built-in types.&lt;br /&gt;
    * Class types are new types created by combining existing types. These include Classes, Structures, and Unions.&lt;br /&gt;
&lt;br /&gt;
===Fundamental Types===&lt;br /&gt;
&lt;br /&gt;
Fundamental types in C++ are divided into three categories: integral, floating, and void. Integral types are capable of handling whole numbers. Floating types are capable of specifying values that may have fractional parts.The void type describes an empty set of values. No variable of type void can be specified — it is used primarily to declare functions that return no values or to declare generic pointers to untyped or arbitrarily typed data&lt;br /&gt;
&lt;br /&gt;
===Derived Types===&lt;br /&gt;
&lt;br /&gt;
Derived types are new types that can be used in a program, and can include directly derived types and composed derivative types.&lt;br /&gt;
====Directly Derived Types====&lt;br /&gt;
&lt;br /&gt;
New types derived directly from existing types are types that point to, refer to, or (in the case of functions) transform type data to return a new type.&lt;br /&gt;
&lt;br /&gt;
    * Arrays of Variables or Objects&lt;br /&gt;
    * Functions&lt;br /&gt;
    * Pointers of a Given Type&lt;br /&gt;
    * References to Objects&lt;br /&gt;
    * Constants&lt;br /&gt;
    * Pointers to Class Members&lt;br /&gt;
====Composed Derivative Types====&lt;br /&gt;
&lt;br /&gt;
The following are the various composed derivative types:&lt;br /&gt;
&lt;br /&gt;
    * Classes&lt;br /&gt;
    * Structures&lt;br /&gt;
    * Unions&lt;br /&gt;
&lt;br /&gt;
Class types are derivatives of composed types. More on class types below.&lt;br /&gt;
&lt;br /&gt;
===Class Types===&lt;br /&gt;
&lt;br /&gt;
Class types are defined using the class, struct, and union keywords. For simplicity, types defined with these keywords are called class declarations. Class Type names are introduced as identifiers immediately after the compiler processes them (before entry into the class body); they can be used to declare class members. This allows declaration of self-referential data structures&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define TRUE = 1&lt;br /&gt;
&lt;br /&gt;
class dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public:&lt;br /&gt;
   dog()&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(string dogSize)&lt;br /&gt;
   {&lt;br /&gt;
      _dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   string getDogSize()&lt;br /&gt;
   {&lt;br /&gt;
      return _dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(string breed)&lt;br /&gt;
   {&lt;br /&gt;
      _breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   private: // attributes || fundamental types&lt;br /&gt;
   string _dogSize, _breed;&lt;br /&gt;
   int _legs;&lt;br /&gt;
   bool _bark;&lt;br /&gt;
&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   dog mongrel;//class types&lt;br /&gt;
   //setting specific attributes that makes it different from types&lt;br /&gt;
   mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
   mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Ricky is a &amp;quot; &amp;lt;&amp;lt; mongrel.getDogSize() &amp;lt;&amp;lt; &amp;quot; sized dog&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Java==&lt;br /&gt;
&lt;br /&gt;
Java is a strongly typed language i.e. the type of every variable and expression used in a program must be known at compile time. The type of a variable / expression defines the range of values that it can hold. The type of a variable also determines the operations that can be performed on that variable. The strong typing nature of Java enables it to determine errors at compile time.Whenever a variable is declared in Java, we need to mention its type, which may be a class, interface or a primitive. When an object of a subclass of some other class is instantiated, we can say that the object is of type subclass and type superclass and it can perform all operations of both the subclass and the superclass.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are two different types in Java :&lt;br /&gt;
    * Primitive Types are boolean and numeric. The numeric types are the integral types byte, short, int, long, and char, and the         &lt;br /&gt;
      floating-point types float and double. &lt;br /&gt;
    * Reference Types are class types, interface types and array types.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|width=&amp;quot;100%&amp;quot;  border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; bordercolor = &amp;quot;black&amp;quot; cellspacing=&amp;quot;2&amp;quot; align = &amp;quot;left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!A side note on Null Types&lt;br /&gt;
|-&lt;br /&gt;
|There is also a special null type in Java, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Primitive Types====&lt;br /&gt;
&lt;br /&gt;
A primitive type is predefined by the Java programming language and named by its reserved keyword.Primitive values do not share state with other primitive values. A variable whose type is a primitive type always holds a primitive value of that same type. The value of a variable of primitive type can be changed only by assignment operations on that variable.&lt;br /&gt;
&lt;br /&gt;
====Reference Types====&lt;br /&gt;
&lt;br /&gt;
There are three kinds of reference types: class types, interface types, and array types.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt; &lt;br /&gt;
ReferenceType:&lt;br /&gt;
	ClassOrInterfaceType&lt;br /&gt;
	ArrayType&lt;br /&gt;
&lt;br /&gt;
ClassOrInterfaceType:&lt;br /&gt;
	ClassType&lt;br /&gt;
	InterfaceType&lt;br /&gt;
&lt;br /&gt;
ClassType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
InterfaceType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
ArrayType:&lt;br /&gt;
        [ ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
class Dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public Dog() //constructor&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(String dogSize) //setter method&lt;br /&gt;
   {&lt;br /&gt;
      this.dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   String getDogSize() //getter method&lt;br /&gt;
   {&lt;br /&gt;
      return this.dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(String breed)&lt;br /&gt;
   {&lt;br /&gt;
      this.breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   // attributes || fundamental types&lt;br /&gt;
   String dogSize = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   Sting breed = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   int legs;&lt;br /&gt;
   boolean bark;&lt;br /&gt;
   public static void main(String[] args)&lt;br /&gt;
   {&lt;br /&gt;
     Dog mongrel = new Dog();//class types&lt;br /&gt;
     //setting specific attributes that makes it different from types&lt;br /&gt;
     mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
     mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
     System.out.println(&amp;quot;Ricky is a &amp;quot;+ mongrel.getSize() +&amp;quot; size dog&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby being a dynamically typed, reflective object oriented language, every variable is an object and we do not explicitly mention their type as in other object oriented languages, rather the type is implicitly inferred from the type of the value which is assigned to them at runtime. Hence there is no distinction between primitive data types and object types in ruby. In Ruby, all classes are instances of the class Class. Whenever a new class is defined, an object of type Class is created and assigned to the ''Name'' of the class. ''Name.new'' is used to create a new object of the class. This invokes the ''new'' instance method in Class, which in turn calls the ''allocate'' method to allocate memory for the object, before finally calling the new object's initialize method. Thus, the construction of an object is separate from its initialization, and both can be over-ridden. The initialization is done via the ''initialize'' instance method while the construction is done via the ''new'' class method.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#since ruby is dynamic Oo language no explicit type assignment statements&lt;br /&gt;
class Dog &lt;br /&gt;
&lt;br /&gt;
   #implementation&lt;br /&gt;
   def initialize&lt;br /&gt;
      @legs = 4&lt;br /&gt;
      @bark = true&lt;br /&gt;
   end&lt;br /&gt;
   #attributes&lt;br /&gt;
   attr_accessor :dogSize, :breed &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
#at runtime   &lt;br /&gt;
mongrel = Dog.new #dynamiclly typed&lt;br /&gt;
#setting specific attributes that makes it different from types&lt;br /&gt;
mongrel.dogSize = &amp;quot;medium&amp;quot; # string class type&lt;br /&gt;
mongrel.breed = &amp;quot;country specific&amp;quot; # string class type&lt;br /&gt;
puts &amp;quot;Ricky is a #{mongrel.dogSize} size dog&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.cmu.edu/People/clamen/OODBMS/Manifesto/htManifesto/node6.html Types and Classes]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object-oriented_programming Object Oriented Programming concepts on Wikipedia]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://haskell.org/haskellwiki/OOP_vs_type_classes OOP vs type classes]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html Java Language Specification,Second Edition Chapter4: Types, Values, Variables]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikibooks.org/wiki/Java_Programming/Types Java Programming/Types on Wikipedia]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://rubylearning.com/satishtalim/writing_our_own_class_in_ruby.html Writing Classes in Ruby and Insipration for Example]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.velocityreviews.com/forums/t127376-what-is-the-difference-between-class-and-type.html What is the difference between class and type]&lt;br /&gt;
&lt;br /&gt;
==Further Reading / External Links== &lt;br /&gt;
&lt;br /&gt;
Bjarne Stroustrup's article on OOP in C++ and beyond http://www.research.att.com/~bs/bs_faq.html#oop&amp;lt;br&amp;gt;&lt;br /&gt;
B. Stroustrup, The C++ Programming Language, 3rd-ed., p. 158&amp;lt;br&amp;gt;&lt;br /&gt;
Fundamentals of OOP and Data Structures in Java - Page xiii by Richard Wiener, Lewis J. Pinson &amp;lt;br&amp;gt;&lt;br /&gt;
Type vs Class, A general overview http://lambda-the-ultimate.org/node/2079&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=8000</id>
		<title>CSC/ECE 517 Fall 2007/wiki2 6 ap</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=8000"/>
		<updated>2007-10-29T05:59:18Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Type vs. class. Survey the differences on type vs. class in object-oriented languages. Often, the distinction is that class pertains to an object, whereas type pertains to a variable. Consider the distinction between the two terms in several different programming languages. Cover the differences between type and class, from type-theoretic definitions to practical aspects.''&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
In object oriented programming concepts, the difference between types and classes is not clearly understood. The differences between them are subtle and the two terms are often misunderstood to be the same. In the article we try to bring out the differences between Types and Classes and provide more insight into them. Furthermore, in OOP languages, classes are types, while most types are not classes. In pure object languages, by opposition (e.g. Smalltalk, Scala, perhaps Python), every type maps to a class.    &lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
===Type=== &lt;br /&gt;
A ''type'', in an object-oriented system, summarizes the common features of a set of objects with the same characteristics. It corresponds to the notion of an abstract data type. Type has 2 parts: the interface and the implementation(s). The interface, which is the only part visible to the user, consists of a list of operations and their signatures. The type implementation is of concern only to the type designer.&lt;br /&gt;
&lt;br /&gt;
===Class===&lt;br /&gt;
A ''class'', in object oriented systems, is a kind of metadata that describes the rules by which objects behave; these objects are referred to as instances of that class. A class specifies the structure of data (a.k.a. properties, fields, attributes, data members) within each instance as well as methods (functions) (a.k.a. behaviors) which manipulate the data of the object and perform tasks.&lt;br /&gt;
&lt;br /&gt;
==Types==&lt;br /&gt;
&lt;br /&gt;
Types are abstract views that define properties of a set of entities. Object-oriented programming languages must allow to implement these types. Consequently, once a type is implemented we have a particular representation of it available. We will use the seminal concept of the integer data type to explain the concept of type in detail. Programming languages such as C, Java, C++, Pascal and others already offer an implementation for it. Sometimes it is called int or integer. Once you've created a variable of this type you can use its provided operations. For example, you can add two integers: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
  int i, j, k;    /* Define three integers */&lt;br /&gt;
&lt;br /&gt;
  i = 1;          /* Assign 1 to integer i */&lt;br /&gt;
  j = 2;          /* Assign 2 to integer j */&lt;br /&gt;
  k = i + j;      /* Assign the sum of i and j to k */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first line defines three instances i, j and k of type Integer. Consequently, for each instance the special operation constructor should be called. In our example, this is internally done by the compiler. The compiler reserves memory to hold the value of an integer and ''binds'' the corresponding name to it. If you refer to i you actually refer to this memory area which was ''constructed'' by the definition of i. &lt;br /&gt;
&lt;br /&gt;
The implementation of types comprises of the data (internal structure of the object’s data) and operation (methods / procedures which implement the interface operations). By making users declare the types of variables at compile time, the system simplifies the procedure of checking the program correctness at compile time, thereby increasing programmer productivity. The types cannot be modified at run-time.&lt;br /&gt;
&lt;br /&gt;
===Properties of a Type===&lt;br /&gt;
* It exports a set of operations. This set is called interface. &lt;br /&gt;
* Operations of the interface are the one and only access mechanism to the type's data structure. &lt;br /&gt;
* Axioms and preconditions define the application domain of the type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
&lt;br /&gt;
A class is a combination of state (data) and behavior (methods) that manipulate the state. A class is a blueprint for an object.It is an actual representation of a type. It therefore provides implementation details for the data structure used and operations specified in the type. Now we will define a class that implements the Integer data type: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;  &lt;br /&gt;
class Integer {&lt;br /&gt;
  attributes: || implementation : &lt;br /&gt;
    int i /* Integer data type */&lt;br /&gt;
&lt;br /&gt;
  methods: || operation :&lt;br /&gt;
    setValue(int n) /* To assign value to i */&lt;br /&gt;
    Integer addValue(Integer j) /* To add integer j with i */&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this notation class {...} denotes the definition of a class. Enclosed in the curly brackets are two sections attributes: and methods: which define the implementation of the data structure and operations of the corresponding class. Again we distinguish the two levels with different terms: At the implementation level we speak of ''attributes'' which are elements of the data structure at the class level. The same applies to ''methods'' which are the implementation of the class operations. &lt;br /&gt;
In our example, the attribute is an ordinary integer of a programming language . We only define two methods setValue() and addValue() representing the two of the many operations that can be performed on an integer data type set and add, to make the comparison succinct and concise.&lt;br /&gt;
&lt;br /&gt;
Although the specification of a class is pretty similar to that of a type, it is more of a runtime notion. There are two major aspects of a class – an object factory and an object warehouse. The object factory is the means by which objects of a class are created, using the new operation on the class. Object warehouse stores the set of objects that are instances of the class. Users can work with all these objects by performing all the allowed operations on them and thereby change the contents of the object warehouse. Thus, classes by no means determine the correctness of a program, rather they are used to create and manipulate objects, thereby making the system more flexible.&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
The concept of ''type'' itself is an abstraction, such as it can be either a ''value type'' or a ''reference type''. In most languages, ''Type'' is the most general abstraction, with ''value types'' and ''reference types'' as subtypes of the general type.&lt;br /&gt;
&lt;br /&gt;
Value types in turn can be of different kinds, such as the primitive types, but some languages also allow you to construct compound types which are classes. Reference types can also have different constructions, such as class as one and some would consider arrays as another.&lt;br /&gt;
&lt;br /&gt;
In reality, type is whatever you can assign as a type to a variable, which includes both value types and reference types. Since the concepts of types and classes are tightly coupled, in this article we don't explicitly show direct contrasts between them, but rather subtly bring out the differences in their implementations in various programming languages.&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in C++==&lt;br /&gt;
&lt;br /&gt;
C++ supports three kinds of object types:&lt;br /&gt;
    * Fundamental types are built into the language (such as int, float, or double). Instances of these fundamental types are &lt;br /&gt;
      often called ''variables''.&lt;br /&gt;
    * Derived types are new types derived from built-in types.&lt;br /&gt;
    * Class types are new types created by combining existing types. These include Classes, Structures, and Unions.&lt;br /&gt;
&lt;br /&gt;
===Fundamental Types===&lt;br /&gt;
&lt;br /&gt;
Fundamental types in C++ are divided into three categories: integral, floating, and void. Integral types are capable of handling whole numbers. Floating types are capable of specifying values that may have fractional parts.The void type describes an empty set of values. No variable of type void can be specified — it is used primarily to declare functions that return no values or to declare generic pointers to untyped or arbitrarily typed data&lt;br /&gt;
&lt;br /&gt;
===Derived Types===&lt;br /&gt;
&lt;br /&gt;
Derived types are new types that can be used in a program, and can include directly derived types and composed derivative types.&lt;br /&gt;
====Directly Derived Types====&lt;br /&gt;
&lt;br /&gt;
New types derived directly from existing types are types that point to, refer to, or (in the case of functions) transform type data to return a new type.&lt;br /&gt;
&lt;br /&gt;
    * Arrays of Variables or Objects&lt;br /&gt;
    * Functions&lt;br /&gt;
    * Pointers of a Given Type&lt;br /&gt;
    * References to Objects&lt;br /&gt;
    * Constants&lt;br /&gt;
    * Pointers to Class Members&lt;br /&gt;
====Composed Derivative Types====&lt;br /&gt;
&lt;br /&gt;
The following are the various composed derivative types:&lt;br /&gt;
&lt;br /&gt;
    * Classes&lt;br /&gt;
    * Structures&lt;br /&gt;
    * Unions&lt;br /&gt;
&lt;br /&gt;
Class types are derivatives of composed types. More on class types below.&lt;br /&gt;
&lt;br /&gt;
===Class Types===&lt;br /&gt;
&lt;br /&gt;
Class types are defined using the class, struct, and union keywords. For simplicity, types defined with these keywords are called class declarations. Class Type names are introduced as identifiers immediately after the compiler processes them (before entry into the class body); they can be used to declare class members. This allows declaration of self-referential data structures&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define TRUE = 1&lt;br /&gt;
&lt;br /&gt;
class dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public:&lt;br /&gt;
   dog()&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(string dogSize)&lt;br /&gt;
   {&lt;br /&gt;
      _dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   string getDogSize()&lt;br /&gt;
   {&lt;br /&gt;
      return _dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(string breed)&lt;br /&gt;
   {&lt;br /&gt;
      _breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   private: // attributes || fundamental types&lt;br /&gt;
   string _dogSize, _breed;&lt;br /&gt;
   int _legs;&lt;br /&gt;
   bool _bark;&lt;br /&gt;
&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   dog mongrel;//class types&lt;br /&gt;
   //setting specific attributes that makes it different from types&lt;br /&gt;
   mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
   mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Ricky is a &amp;quot; &amp;lt;&amp;lt; mongrel.getDogSize() &amp;lt;&amp;lt; &amp;quot; sized dog&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Java==&lt;br /&gt;
&lt;br /&gt;
Java is a strongly typed language i.e. the type of every variable and expression used in a program must be known at compile time. The type of a variable / expression defines the range of values that it can hold. The type of a variable also determines the operations that can be performed on that variable. The strong typing nature of Java enables it to determine errors at compile time.Whenever a variable is declared in Java, we need to mention its type, which may be a class, interface or a primitive. When an object of a subclass of some other class is instantiated, we can say that the object is of type subclass and type superclass and it can perform all operations of both the subclass and the superclass.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are two different types in Java :&lt;br /&gt;
    * Primitive Types are boolean and numeric. The numeric types are the integral types byte, short, int, long, and char, and the         &lt;br /&gt;
      floating-point types float and double. &lt;br /&gt;
    * Reference Types are class types, interface types and array types.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|width=&amp;quot;100%&amp;quot;  border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; bordercolor = &amp;quot;black&amp;quot; cellspacing=&amp;quot;2&amp;quot; align = &amp;quot;left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!A side note on Null Types&lt;br /&gt;
|-&lt;br /&gt;
|There is also a special null type in Java, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Primitive Types====&lt;br /&gt;
&lt;br /&gt;
A primitive type is predefined by the Java programming language and named by its reserved keyword.Primitive values do not share state with other primitive values. A variable whose type is a primitive type always holds a primitive value of that same type. The value of a variable of primitive type can be changed only by assignment operations on that variable.&lt;br /&gt;
&lt;br /&gt;
====Reference Types====&lt;br /&gt;
&lt;br /&gt;
There are three kinds of reference types: class types, interface types, and array types.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt; &lt;br /&gt;
ReferenceType:&lt;br /&gt;
	ClassOrInterfaceType&lt;br /&gt;
	ArrayType&lt;br /&gt;
&lt;br /&gt;
ClassOrInterfaceType:&lt;br /&gt;
	ClassType&lt;br /&gt;
	InterfaceType&lt;br /&gt;
&lt;br /&gt;
ClassType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
InterfaceType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
ArrayType:&lt;br /&gt;
        [ ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
class Dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public Dog() //constructor&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(String dogSize) //setter method&lt;br /&gt;
   {&lt;br /&gt;
      this.dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   String getDogSize() //getter method&lt;br /&gt;
   {&lt;br /&gt;
      return this.dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(String breed)&lt;br /&gt;
   {&lt;br /&gt;
      this.breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   // attributes || fundamental types&lt;br /&gt;
   String dogSize = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   Sting breed = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   int legs;&lt;br /&gt;
   boolean bark;&lt;br /&gt;
   public static void main(String[] args)&lt;br /&gt;
   {&lt;br /&gt;
     Dog mongrel = new Dog();//class types&lt;br /&gt;
     //setting specific attributes that makes it different from types&lt;br /&gt;
     mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
     mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
     System.out.println(&amp;quot;Ricky is a &amp;quot;+ mongrel.getSize() +&amp;quot; size dog&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby being a dynamically typed, reflective object oriented language, every variable is an object and we do not explicitly mention their type as in other object oriented languages, rather the type is implicitly inferred from the type of the value which is assigned to them at runtime. Hence there is no distinction between primitive data types and object types in ruby. In Ruby, all classes are instances of the class Class. Whenever a new class is defined, an object of type Class is created and assigned to the ''Name'' of the class. ''Name.new'' is used to create a new object of the class. This invokes the ''new'' instance method in Class, which in turn calls the ''allocate'' method to allocate memory for the object, before finally calling the new object's initialize method. Thus, the construction of an object is separate from its initialization, and both can be over-ridden. The initialization is done via the ''initialize'' instance method while the construction is done via the ''new'' class method.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#since ruby is dynamic Oo language no explicit type assignment statements&lt;br /&gt;
class Dog &lt;br /&gt;
&lt;br /&gt;
   #implementation&lt;br /&gt;
   def initialize&lt;br /&gt;
      @legs = 4&lt;br /&gt;
      @bark = true&lt;br /&gt;
   end&lt;br /&gt;
   #attributes&lt;br /&gt;
   attr_accessor :dogSize, :breed &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
#at runtime   &lt;br /&gt;
mongrel = Dog.new #dynamiclly typed&lt;br /&gt;
#setting specific attributes that makes it different from types&lt;br /&gt;
mongrel.dogSize = &amp;quot;medium&amp;quot; # string class type&lt;br /&gt;
mongrel.breed = &amp;quot;country specific&amp;quot; # string class type&lt;br /&gt;
puts &amp;quot;Ricky is a #{mongrel.dogSize} size dog&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.cmu.edu/People/clamen/OODBMS/Manifesto/htManifesto/node6.html Types and Classes]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object-oriented_programming Object Oriented Programming concepts on Wikipedia]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://haskell.org/haskellwiki/OOP_vs_type_classes OOP vs type classes]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html Java Language Specification,Second Edition Chapter4: Types, Values, Variables]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikibooks.org/wiki/Java_Programming/Types Java Programming/Types on Wikipedia]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://rubylearning.com/satishtalim/writing_our_own_class_in_ruby.html Writing Classes in Ruby and Insipration for Example]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.velocityreviews.com/forums/t127376-what-is-the-difference-between-class-and-type.html What is the difference between class and type]&lt;br /&gt;
&lt;br /&gt;
==Further Reading / External Links== &lt;br /&gt;
&lt;br /&gt;
Bjarne Stroustrup's article on OOP in C++ and beyond http://www.research.att.com/~bs/bs_faq.html#oop&amp;lt;br&amp;gt;&lt;br /&gt;
B. Stroustrup, The C++ Programming Language, 3rd-ed., p. 158&amp;lt;br&amp;gt;&lt;br /&gt;
Fundamentals of OOP and Data Structures in Java - Page xiii by Richard Wiener, Lewis J. Pinson &amp;lt;br&amp;gt;&lt;br /&gt;
Type vs Class, A general overview http://lambda-the-ultimate.org/node/2079&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=7465</id>
		<title>CSC/ECE 517 Fall 2007/wiki2 6 ap</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=7465"/>
		<updated>2007-10-24T21:29:26Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Type vs. class. Survey the differences on type vs. class in object-oriented languages. Often, the distinction is that class pertains to an object, whereas type pertains to a variable. Consider the distinction between the two terms in several different programming languages. Cover the differences between type and class, from type-theoretic definitions to practical aspects.''&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
In object oriented programming concepts, the difference between types and classes is not clearly understood. The differences between them are subtle and the two terms are often misunderstood to be the same. In the article we try to bring out the differences between Types and Classes and provide more insight into them. Furthermore, in OOP languages, classes are types, while most types are not classes. In pure object languages, by opposition (e.g. Smalltalk, Scala, perhaps Python), every type maps to a class.    &lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
===Type=== &lt;br /&gt;
A ''type'', in an object-oriented system, summarizes the common features of a set of objects with the same characteristics. It corresponds to the notion of an abstract data type. Type has 2 parts: the interface and the implementation(s). The interface, which is the only part visible to the user, consists of a list of operations and their signatures. The type implementation is of concern only to the type designer.&lt;br /&gt;
&lt;br /&gt;
===Class===&lt;br /&gt;
A ''class'', in object oriented systems, is a kind of metadata that describes the rules by which objects behave; these objects are referred to as instances of that class. A class specifies the structure of data (a.k.a. properties, fields, attributes, data members) within each instance as well as methods (functions) (a.k.a. behaviors) which manipulate the data of the object and perform tasks.&lt;br /&gt;
&lt;br /&gt;
==Types==&lt;br /&gt;
&lt;br /&gt;
Types are abstract views that define properties of a set of entities. Object-oriented programming languages must allow to implement these types. Consequently, once a type is implemented we have a particular representation of it available. We will use the seminal concept of the integer data type to explain the concept of type in detail. Programming languages such as C, Java, C++, Pascal and others already offer an implementation for it. Sometimes it is called int or integer. Once you've created a variable of this type you can use its provided operations. For example, you can add two integers: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
  int i, j, k;    /* Define three integers */&lt;br /&gt;
&lt;br /&gt;
  i = 1;          /* Assign 1 to integer i */&lt;br /&gt;
  j = 2;          /* Assign 2 to integer j */&lt;br /&gt;
  k = i + j;      /* Assign the sum of i and j to k */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first line defines three instances i, j and k of type Integer. Consequently, for each instance the special operation constructor should be called. In our example, this is internally done by the compiler. The compiler reserves memory to hold the value of an integer and ''binds'' the corresponding name to it. If you refer to i you actually refer to this memory area which was ''constructed'' by the definition of i. &lt;br /&gt;
&lt;br /&gt;
The implementation of types comprises of the data (internal structure of the object’s data) and operation (methods / procedures which implement the interface operations). By making users declare the types of variables at compile time, the system simplifies the procedure of checking the program correctness at compile time, thereby increasing programmer productivity. The types cannot be modified at run-time.&lt;br /&gt;
&lt;br /&gt;
===Properties of a Type===&lt;br /&gt;
* It exports a set of operations. This set is called interface. &lt;br /&gt;
* Operations of the interface are the one and only access mechanism to the type's data structure. &lt;br /&gt;
* Axioms and preconditions define the application domain of the type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
&lt;br /&gt;
A class is a combination of state (data) and behavior (methods) that manipulate the state. A class is a blueprint for an object.It is an actual representation of a type. It therefore provides implementation details for the data structure used and operations specified in the type. Now we will define a class that implements the Integer data type: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;  &lt;br /&gt;
class Integer {&lt;br /&gt;
  attributes: || implementation : &lt;br /&gt;
    int i /* Integer data type */&lt;br /&gt;
&lt;br /&gt;
  methods: || operation :&lt;br /&gt;
    setValue(int n) /* To assign value to i */&lt;br /&gt;
    Integer addValue(Integer j) /* To add integer j with i */&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this notation class {...} denotes the definition of a class. Enclosed in the curly brackets are two sections attributes: and methods: which define the implementation of the data structure and operations of the corresponding class. Again we distinguish the two levels with different terms: At the implementation level we speak of ''attributes'' which are elements of the data structure at the class level. The same applies to ''methods'' which are the implementation of the class operations. &lt;br /&gt;
In our example, the attribute is an ordinary integer of a programming language . We only define two methods setValue() and addValue() representing the two of the many operations that can be performed on an integer data type set and add, to make the comparison succinct and concise.&lt;br /&gt;
&lt;br /&gt;
Although the specification of a class is pretty similar to that of a type, it is more of a runtime notion. There are two major aspects of a class – an object factory and an object warehouse. The object factory is the means by which objects of a class are created, using the new operation on the class. Object warehouse stores the set of objects that are instances of the class. Users can work with all these objects by performing all the allowed operations on them and thereby change the contents of the object warehouse. Thus, classes by no means determine the correctness of a program, rather they are used to create and manipulate objects, thereby making the system more flexible.&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
The concept of ''type'' itself is an abstraction, such as it can be either a ''value type'' or a ''reference type''. In most languages, ''Type'' is the most general abstraction, with ''value types'' and ''reference types'' as subtypes of the general type.&lt;br /&gt;
&lt;br /&gt;
Value types in turn can be of different kinds, such as the primitive types, but some languages also allow you to construct compound types which are classes. Reference types can also have different constructions, such as class as one and some would consider arrays as another.&lt;br /&gt;
&lt;br /&gt;
In reality, type is whatever type you can assign as a type to a variable, which includes both value types and reference types. Since the concepts of types and classes are tightly coupled, in this article we don't explicitly show direct contrasts between them, but rather subtly bring out the differences in their implementations in various programming languages.&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in C++==&lt;br /&gt;
&lt;br /&gt;
C++ supports three kinds of object types:&lt;br /&gt;
    * Fundamental types are built into the language (such as int, float, or double). Instances of these fundamental types are &lt;br /&gt;
      often called ''variables''.&lt;br /&gt;
    * Derived types are new types derived from built-in types.&lt;br /&gt;
    * Class types are new types created by combining existing types. These include Classes, Structures, and Unions.&lt;br /&gt;
&lt;br /&gt;
===Fundamental Types===&lt;br /&gt;
&lt;br /&gt;
Fundamental types in C++ are divided into three categories: integral, floating, and void. Integral types are capable of handling whole numbers. Floating types are capable of specifying values that may have fractional parts.The void type describes an empty set of values. No variable of type void can be specified — it is used primarily to declare functions that return no values or to declare generic pointers to untyped or arbitrarily typed data&lt;br /&gt;
&lt;br /&gt;
===Derived Types===&lt;br /&gt;
&lt;br /&gt;
Derived types are new types that can be used in a program, and can include directly derived types and composed derivative types.&lt;br /&gt;
====Directly Derived Types====&lt;br /&gt;
&lt;br /&gt;
New types derived directly from existing types are types that point to, refer to, or (in the case of functions) transform type data to return a new type.&lt;br /&gt;
&lt;br /&gt;
    * Arrays of Variables or Objects&lt;br /&gt;
    * Functions&lt;br /&gt;
    * Pointers of a Given Type&lt;br /&gt;
    * References to Objects&lt;br /&gt;
    * Constants&lt;br /&gt;
    * Pointers to Class Members&lt;br /&gt;
====Composed Derivative Types====&lt;br /&gt;
&lt;br /&gt;
The following are the various composed derivative types:&lt;br /&gt;
&lt;br /&gt;
    * Classes&lt;br /&gt;
    * Structures&lt;br /&gt;
    * Unions&lt;br /&gt;
&lt;br /&gt;
Class types are derivatives of composed types. More on class types below.&lt;br /&gt;
&lt;br /&gt;
===Class Types===&lt;br /&gt;
&lt;br /&gt;
Class types are defined using the class, struct, and union keywords. For simplicity, types defined with these keywords are called class declarations. Class Type names are introduced as identifiers immediately after the compiler processes them (before entry into the class body); they can be used to declare class members. This allows declaration of self-referential data structures&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define TRUE = 1&lt;br /&gt;
&lt;br /&gt;
class dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public:&lt;br /&gt;
   dog()&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(string dogSize)&lt;br /&gt;
   {&lt;br /&gt;
      _dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   string getDogSize()&lt;br /&gt;
   {&lt;br /&gt;
      return _dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(string breed)&lt;br /&gt;
   {&lt;br /&gt;
      _breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   private: // attributes || fundamental types&lt;br /&gt;
   string _dogSize, _breed;&lt;br /&gt;
   int _legs;&lt;br /&gt;
   bool _bark;&lt;br /&gt;
&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   dog mongrel;//class types&lt;br /&gt;
   //setting specific attributes that makes it different from types&lt;br /&gt;
   mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
   mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Ricky is a &amp;quot; &amp;lt;&amp;lt; mongrel.getDogSize() &amp;lt;&amp;lt; &amp;quot; sized dog&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Java==&lt;br /&gt;
&lt;br /&gt;
Java is a strongly typed language i.e. the type of every variable and expression used in a program must be known at compile time. The type of a variable / expression defines the range of values that it can hold. The type of a variable also determines the operations that can be performed on that variable. The strong typing nature of Java enables it to determine errors at compile time.Whenever a variable is declared in Java, we need to mention its type, which may be a class, interface or a primitive. When an object of a subclass of some other class is instantiated, we can say that the object is of type subclass and type superclass and it can perform all operations of both the subclass and the superclass.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are two different types in Java :&lt;br /&gt;
    * Primitive Types are boolean and numeric. The numeric types are the integral types byte, short, int, long, and char, and the         &lt;br /&gt;
      floating-point types float and double. &lt;br /&gt;
    * Reference Types are class types, interface types and array types.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|width=&amp;quot;100%&amp;quot;  border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; bordercolor = &amp;quot;black&amp;quot; cellspacing=&amp;quot;2&amp;quot; align = &amp;quot;left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!A side note on Null Types&lt;br /&gt;
|-&lt;br /&gt;
|There is also a special null type in Java, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Primitive Types====&lt;br /&gt;
&lt;br /&gt;
A primitive type is predefined by the Java programming language and named by its reserved keyword.Primitive values do not share state with other primitive values. A variable whose type is a primitive type always holds a primitive value of that same type. The value of a variable of primitive type can be changed only by assignment operations on that variable.&lt;br /&gt;
&lt;br /&gt;
====Reference Types====&lt;br /&gt;
&lt;br /&gt;
There are three kinds of reference types: class types, interface types, and array types.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt; &lt;br /&gt;
ReferenceType:&lt;br /&gt;
	ClassOrInterfaceType&lt;br /&gt;
	ArrayType&lt;br /&gt;
&lt;br /&gt;
ClassOrInterfaceType:&lt;br /&gt;
	ClassType&lt;br /&gt;
	InterfaceType&lt;br /&gt;
&lt;br /&gt;
ClassType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
InterfaceType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
ArrayType:&lt;br /&gt;
        [ ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
class Dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public Dog() //constructor&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(String dogSize) //setter method&lt;br /&gt;
   {&lt;br /&gt;
      this.dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   String getDogSize() //getter method&lt;br /&gt;
   {&lt;br /&gt;
      return this.dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(String breed)&lt;br /&gt;
   {&lt;br /&gt;
      this.breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   // attributes || fundamental types&lt;br /&gt;
   String dogSize = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   Sting breed = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   int legs;&lt;br /&gt;
   boolean bark;&lt;br /&gt;
   public static void main(String[] args)&lt;br /&gt;
   {&lt;br /&gt;
     Dog mongrel = new Dog();//class types&lt;br /&gt;
     //setting specific attributes that makes it different from types&lt;br /&gt;
     mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
     mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
     System.out.println(&amp;quot;Ricky is a &amp;quot;+ mongrel.getSize() +&amp;quot; size dog&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby being a dynamically typed, reflective object oriented language, every variable is an object and we do not explicitly mention their type as in other object oriented languages, rather the type is implicitly inferred from the type of the value which is assigned to them at runtime. Hence there is no distinction between primitive data types and object types in ruby. In Ruby, all classes are instances of the class Class. Whenever a new class is defined, an object of type Class is created and assigned to the ''Name'' of the class. ''Name.new'' is used to create a new object of the class. This invokes the ''new'' instance method in Class, which in turn calls the ''allocate'' method to allocate memory for the object, before finally calling the new object's initialize method. Thus, the construction of an object is separate from its initialization, and both can be over-ridden. The initialization is done via the ''initialize'' instance method while the construction is done via the ''new'' class method.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#since ruby is dynamic Oo language no explicit type assignment statements&lt;br /&gt;
class Dog &lt;br /&gt;
&lt;br /&gt;
   #implementation&lt;br /&gt;
   def initialize&lt;br /&gt;
      @legs = 4&lt;br /&gt;
      @bark = true&lt;br /&gt;
   end&lt;br /&gt;
   #attributes&lt;br /&gt;
   attr_accessor :dogSize, :breed &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
#at runtime   &lt;br /&gt;
mongrel = Dog.new #dynamiclly typed&lt;br /&gt;
#setting specific attributes that makes it different from types&lt;br /&gt;
mongrel.dogSize = &amp;quot;medium&amp;quot; # string class type&lt;br /&gt;
mongrel.breed = &amp;quot;country specific&amp;quot; # string class type&lt;br /&gt;
puts &amp;quot;Ricky is a #{mongrel.dogSize} size dog&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.cmu.edu/People/clamen/OODBMS/Manifesto/htManifesto/node6.html Types and Classes]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object-oriented_programming Object Oriented Programming concepts on Wikipedia]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://haskell.org/haskellwiki/OOP_vs_type_classes OOP vs type classes]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html Java Language Specification,Second Edition Chapter4: Types, Values, Variables]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikibooks.org/wiki/Java_Programming/Types Java Programming/Types on Wikipedia]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://rubylearning.com/satishtalim/writing_our_own_class_in_ruby.html Writing Classes in Ruby and Insipration for Example]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.velocityreviews.com/forums/t127376-what-is-the-difference-between-class-and-type.html What is the difference between class and type]&lt;br /&gt;
&lt;br /&gt;
==Further Reading / External Links== &lt;br /&gt;
&lt;br /&gt;
Bjarne Stroustrup's article on OOP in C++ and beyond http://www.research.att.com/~bs/bs_faq.html#oop&amp;lt;br&amp;gt;&lt;br /&gt;
B. Stroustrup, The C++ Programming Language, 3rd-ed., p. 158&amp;lt;br&amp;gt;&lt;br /&gt;
Fundamentals of OOP and Data Structures in Java - Page xiii by Richard Wiener, Lewis J. Pinson &amp;lt;br&amp;gt;&lt;br /&gt;
Type vs Class, A general overview http://lambda-the-ultimate.org/node/2079&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=7461</id>
		<title>CSC/ECE 517 Fall 2007/wiki2 6 ap</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=7461"/>
		<updated>2007-10-24T21:26:50Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Type vs. class. Survey the differences on type vs. class in object-oriented languages. Often, the distinction is that class pertains to an object, whereas type pertains to a variable. Consider the distinction between the two terms in several different programming languages. Cover the differences between type and class, from type-theoretic definitions to practical aspects.''&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
In object oriented programming concepts, the difference between types and classes is not clearly understood. The differences between them are subtle and the two terms are often misunderstood to be the same. In the article we try to bring out the differences between Types and Classes and provide more insight into them. Furthermore, in OOP languages, classes are types, while most types are not classes. In pure object languages, by opposition (e.g. Smalltalk, Scala, perhaps Python), every type maps to a class.    &lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
===Type=== &lt;br /&gt;
A ''type'', in an object-oriented system, summarizes the common features of a set of objects with the same characteristics. It corresponds to the notion of an abstract data type. Type has 2 parts: the interface and the implementation(s). The interface, which is the only part visible to the user, consists of a list of operations and their signatures. The type implementation is of concern only to the type designer.&lt;br /&gt;
&lt;br /&gt;
===Class===&lt;br /&gt;
A ''class'', in object oriented systems, is a kind of metadata that describes the rules by which objects behave; these objects are referred to as instances of that class. A class specifies the structure of data (a.k.a. properties, fields, attributes, data members) within each instance as well as methods (functions) (a.k.a. behaviors) which manipulate the data of the object and perform tasks.&lt;br /&gt;
&lt;br /&gt;
==Types==&lt;br /&gt;
&lt;br /&gt;
Types are abstract views that define properties of a set of entities. Object-oriented programming languages must allow to implement these types. Consequently, once a type is implemented we have a particular representation of it available. We will use the seminal concept of the integer data type to explain the concept of type in detail. Programming languages such as C, Java, C++, Pascal and others already offer an implementation for it. Sometimes it is called int or integer. Once you've created a variable of this type you can use its provided operations. For example, you can add two integers: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
  int i, j, k;    /* Define three integers */&lt;br /&gt;
&lt;br /&gt;
  i = 1;          /* Assign 1 to integer i */&lt;br /&gt;
  j = 2;          /* Assign 2 to integer j */&lt;br /&gt;
  k = i + j;      /* Assign the sum of i and j to k */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first line defines three instances i, j and k of type Integer. Consequently, for each instance the special operation constructor should be called. In our example, this is internally done by the compiler. The compiler reserves memory to hold the value of an integer and ''binds'' the corresponding name to it. If you refer to i you actually refer to this memory area which was ''constructed'' by the definition of i. &lt;br /&gt;
&lt;br /&gt;
The implementation of types comprises of the data (internal structure of the object’s data) and operation (methods / procedures which implement the interface operations). By making users declare the types of variables at compile time, the system simplifies the procedure of checking the program correctness at compile time, thereby increasing programmer productivity. The types cannot be modified at run-time.&lt;br /&gt;
&lt;br /&gt;
===Properties of a Type===&lt;br /&gt;
* It exports a set of operations. This set is called interface. &lt;br /&gt;
* Operations of the interface are the one and only access mechanism to the type's data structure. &lt;br /&gt;
* Axioms and preconditions define the application domain of the type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
&lt;br /&gt;
A class is a combination of state (data) and behavior (methods) that manipulate the state. A class is a blueprint for an object.It is an actual representation of a type. It therefore provides implementation details for the data structure used and operations specified in the type. Now we will define a class that implements the Integer data type: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;  &lt;br /&gt;
class Integer {&lt;br /&gt;
  attributes: || implementation : &lt;br /&gt;
    int i /* Integer data type */&lt;br /&gt;
&lt;br /&gt;
  methods: || operation :&lt;br /&gt;
    setValue(int n) /* To assign value to i */&lt;br /&gt;
    Integer addValue(Integer j) /* To add integer j with i */&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this notation class {...} denotes the definition of a class. Enclosed in the curly brackets are two sections attributes: and methods: which define the implementation of the data structure and operations of the corresponding class. Again we distinguish the two levels with different terms: At the implementation level we speak of ''attributes'' which are elements of the data structure at the class level. The same applies to ''methods'' which are the implementation of the class operations. &lt;br /&gt;
In our example, the attribute is an ordinary integer of a programming language . We only define two methods setValue() and addValue() representing the two of the many operations that can be performed on an integer data type set and add, to make the comparison succinct and concise.&lt;br /&gt;
&lt;br /&gt;
Although the specification of a class is pretty similar to that of a type, it is more of a runtime notion. There are two major aspects of a class – an object factory and an object warehouse. The object factory is the means by which objects of a class are created, using the new operation on the class. Object warehouse stores the set of objects that are instances of the class. Users can work with all these objects by performing all the allowed operations on them and thereby change the contents of the object warehouse. Thus, classes by no means determine the correctness of a program, rather they are used to create and manipulate objects, thereby making the system more flexible.&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
The concept of ''type'' itself is an abstraction, such as it can be either a ''value type'' or a ''reference type''. In most languages, ''Type'' is the most general abstraction, with ''value types'' and ''reference types'' as subtypes of the general type.&lt;br /&gt;
&lt;br /&gt;
Value types in turn can be of different kinds, such as the primitive types, but some languages also allow you to construct compound types which are classes. Reference types can also have different constructions, such as class as one and some would consider arrays as another.&lt;br /&gt;
&lt;br /&gt;
In reality, type is whatever type you can assign as a type to a variable, which includes both value types and reference types. Since the concepts of types and classes are tightly coupled, in this article we don't explicitly show direct contrasts between them, but rather subtly bring out the differences in their implementations in various programming languages.&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in C++==&lt;br /&gt;
&lt;br /&gt;
C++ supports three kinds of object types:&lt;br /&gt;
    * Fundamental types are built into the language (such as int, float, or double). Instances of these fundamental types are &lt;br /&gt;
      often called ''variables''.&lt;br /&gt;
    * Derived types are new types derived from built-in types.&lt;br /&gt;
    * Class types are new types created by combining existing types. These include Classes, Structures, and Unions.&lt;br /&gt;
&lt;br /&gt;
===Fundamental Types===&lt;br /&gt;
&lt;br /&gt;
Fundamental types in C++ are divided into three categories: integral, floating, and void. Integral types are capable of handling whole numbers. Floating types are capable of specifying values that may have fractional parts.The void type describes an empty set of values. No variable of type void can be specified — it is used primarily to declare functions that return no values or to declare generic pointers to untyped or arbitrarily typed data&lt;br /&gt;
&lt;br /&gt;
===Derived Types===&lt;br /&gt;
&lt;br /&gt;
Derived types are new types that can be used in a program, and can include directly derived types and composed derivative types.&lt;br /&gt;
====Directly Derived Types====&lt;br /&gt;
&lt;br /&gt;
New types derived directly from existing types are types that point to, refer to, or (in the case of functions) transform type data to return a new type.&lt;br /&gt;
&lt;br /&gt;
    * Arrays of Variables or Objects&lt;br /&gt;
    * Functions&lt;br /&gt;
    * Pointers of a Given Type&lt;br /&gt;
    * References to Objects&lt;br /&gt;
    * Constants&lt;br /&gt;
    * Pointers to Class Members&lt;br /&gt;
====Composed Derivative Types====&lt;br /&gt;
&lt;br /&gt;
The following are the various composed derivative types:&lt;br /&gt;
&lt;br /&gt;
    * Classes&lt;br /&gt;
    * Structures&lt;br /&gt;
    * Unions&lt;br /&gt;
&lt;br /&gt;
Class types are derivatives of composed types. More on class types below.&lt;br /&gt;
&lt;br /&gt;
===Class Types===&lt;br /&gt;
&lt;br /&gt;
Class types are defined using the class, struct, and union keywords. For simplicity, types defined with these keywords are called class declarations. Class Type names are introduced as identifiers immediately after the compiler processes them (before entry into the class body); they can be used to declare class members. This allows declaration of self-referential data structures&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define TRUE = 1&lt;br /&gt;
&lt;br /&gt;
class dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public:&lt;br /&gt;
   dog()&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(string dogSize)&lt;br /&gt;
   {&lt;br /&gt;
      _dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   string getDogSize()&lt;br /&gt;
   {&lt;br /&gt;
      return _dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(string breed)&lt;br /&gt;
   {&lt;br /&gt;
      _breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   private: // attributes || fundamental types&lt;br /&gt;
   string _dogSize, _breed;&lt;br /&gt;
   int _legs;&lt;br /&gt;
   bool _bark;&lt;br /&gt;
&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   dog mongrel;//class types&lt;br /&gt;
   //setting specific attributes that makes it different from types&lt;br /&gt;
   mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
   mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Ricky is a &amp;quot; &amp;lt;&amp;lt; mongrel.getDogSize() &amp;lt;&amp;lt; &amp;quot; sized dog&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Java==&lt;br /&gt;
&lt;br /&gt;
Java is a strongly typed language i.e. the type of every variable and expression used in a program must be known at compile time. The type of a variable / expression defines the range of values that it can hold. The type of a variable also determines the operations that can be performed on that variable. The strong typing nature of Java enables it to determine errors at compile time.Whenever a variable is declared in Java, we need to mention its type, which may be a class, interface or a primitive. When an object of a subclass of some other class is instantiated, we can say that the object is of type subclass and type superclass and it can perform all operations of both the subclass and the superclass.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are two different types in Java :&lt;br /&gt;
    * Primitive Types are boolean and numeric. The numeric types are the integral types byte, short, int, long, and char, and the         &lt;br /&gt;
      floating-point types float and double. &lt;br /&gt;
    * Reference Types are class types, interface types and array types.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|width=&amp;quot;100%&amp;quot;  border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; bordercolor = &amp;quot;black&amp;quot; cellspacing=&amp;quot;2&amp;quot; align = &amp;quot;left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!A side note on Null Types&lt;br /&gt;
|-&lt;br /&gt;
|There is also a special null type in Java, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Primitive Types====&lt;br /&gt;
&lt;br /&gt;
A primitive type is predefined by the Java programming language and named by its reserved keyword.Primitive values do not share state with other primitive values. A variable whose type is a primitive type always holds a primitive value of that same type. The value of a variable of primitive type can be changed only by assignment operations on that variable.&lt;br /&gt;
&lt;br /&gt;
====Reference Types====&lt;br /&gt;
&lt;br /&gt;
There are three kinds of reference types: class types, interface types, and array types.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt; &lt;br /&gt;
ReferenceType:&lt;br /&gt;
	ClassOrInterfaceType&lt;br /&gt;
	ArrayType&lt;br /&gt;
&lt;br /&gt;
ClassOrInterfaceType:&lt;br /&gt;
	ClassType&lt;br /&gt;
	InterfaceType&lt;br /&gt;
&lt;br /&gt;
ClassType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
InterfaceType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
ArrayType:&lt;br /&gt;
        [ ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
class Dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public Dog() //constructor&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(String dogSize) //setter method&lt;br /&gt;
   {&lt;br /&gt;
      this.dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   String getDogSize() //getter method&lt;br /&gt;
   {&lt;br /&gt;
      return this.dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(String breed)&lt;br /&gt;
   {&lt;br /&gt;
      this.breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   // attributes || fundamental types&lt;br /&gt;
   String dogSize = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   Sting breed = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   int legs;&lt;br /&gt;
   boolean bark;&lt;br /&gt;
   public static void main(String[] args)&lt;br /&gt;
   {&lt;br /&gt;
     Dog mongrel = new Dog();//class types&lt;br /&gt;
     //setting specific attributes that makes it different from types&lt;br /&gt;
     mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
     mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
     System.out.println(&amp;quot;Ricky is a &amp;quot;+ mongrel.getSize() +&amp;quot; size dog&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby being a dynamically typed, reflective object oriented language, every variable is an object and we do not explicitly mention their type as in other object oriented languages, rather the type is implicitly inferred from the type of the value which is assigned to them at runtime. Hence there is no distinction between primitive data types and object types in ruby. In Ruby, all classes are instances of the class Class. Whenever a new class is defined, an object of type Class is created and assigned to the ''Name'' of the class. ''Name.new'' is used to create a new object of the class. This invokes the ''new'' instance method in Class, which in turn calls the ''allocate'' method to allocate memory for the object, before finally calling the new object's initialize method. Thus, the construction of an object is separate from its initialization, and both can be over-ridden. The initialization is done via the ''initialize'' instance method while the construction is done via the ''new'' class method.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#since ruby is dynamic Oo language no explicit type assignment statements&lt;br /&gt;
class Dog &lt;br /&gt;
&lt;br /&gt;
   #implementation&lt;br /&gt;
   def initialize&lt;br /&gt;
      @legs = 4&lt;br /&gt;
      @bark = true&lt;br /&gt;
   end&lt;br /&gt;
   #attributes&lt;br /&gt;
   attr_accessor :dogSize, :breed &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
#at runtime   &lt;br /&gt;
mongrel = Dog.new #dynamiclly typed&lt;br /&gt;
#setting specific attributes that makes it different from types&lt;br /&gt;
mongrel.dogSize = &amp;quot;medium&amp;quot; # string class type&lt;br /&gt;
mongrel.breed = &amp;quot;country specific&amp;quot; # string class type&lt;br /&gt;
puts &amp;quot;Ricky is a #{mongrel.dogSize} size dog&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[Types and Classes http://www.cs.cmu.edu/People/clamen/OODBMS/Manifesto/htManifesto/node6.html]&amp;lt;br&amp;gt;&lt;br /&gt;
[Object Oriented Programming concepts on Wiki http://en.wikipedia.org/wiki/Object-oriented_programming]&amp;lt;br&amp;gt;&lt;br /&gt;
[OOP vs type classes http://haskell.org/haskellwiki/OOP_vs_type_classes]&amp;lt;br&amp;gt;&lt;br /&gt;
[Java Language Specification,Second Edition Chapter4: Types, Values, Variables http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html]&amp;lt;br&amp;gt;&lt;br /&gt;
[Java Programming/Types on wiki http://en.wikibooks.org/wiki/Java_Programming/Types]&amp;lt;br&amp;gt;&lt;br /&gt;
[Writing Classes in Ruby and Insipration for Example http://rubylearning.com/satishtalim/writing_our_own_class_in_ruby.html]&amp;lt;br&amp;gt;&lt;br /&gt;
[What is the difference between class and type http://www.velocityreviews.com/forums/t127376-what-is-the-difference-between-class-and-type.html]&lt;br /&gt;
&lt;br /&gt;
==Further Reading / External Links== &lt;br /&gt;
&lt;br /&gt;
Bjarne Stroustrup's article on OOP in C++ and beyond http://www.research.att.com/~bs/bs_faq.html#oop&amp;lt;br&amp;gt;&lt;br /&gt;
B. Stroustrup, The C++ Programming Language, 3rd-ed., p. 158&amp;lt;br&amp;gt;&lt;br /&gt;
Fundamentals of OOP and Data Structures in Java - Page xiii by Richard Wiener, Lewis J. Pinson &amp;lt;br&amp;gt;&lt;br /&gt;
Type vs Class, A general overview http://lambda-the-ultimate.org/node/2079&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=7459</id>
		<title>CSC/ECE 517 Fall 2007/wiki2 6 ap</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=7459"/>
		<updated>2007-10-24T21:24:05Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Type vs. class. Survey the differences on type vs. class in object-oriented languages. Often, the distinction is that class pertains to an object, whereas type pertains to a variable. Consider the distinction between the two terms in several different programming languages. Cover the differences between type and class, from type-theoretic definitions to practical aspects.''&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
In object oriented programming concepts, the difference between types and classes is not clearly understood. The differences between them are subtle and the two terms are often misunderstood to be the same. In the article we try to bring out the differences between Types and Classes and provide more insight into them. Furthermore, in OOP languages, classes are types, while most types are not classes. In pure object languages, by opposition (e.g. Smalltalk, Scala, perhaps Python), every type maps to a class.    &lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
===Type=== &lt;br /&gt;
A ''type'', in an object-oriented system, summarizes the common features of a set of objects with the same characteristics. It corresponds to the notion of an abstract data type. Type has 2 parts: the interface and the implementation(s). The interface, which is the only part visible to the user, consists of a list of operations and their signatures. The type implementation is of concern only to the type designer.&lt;br /&gt;
&lt;br /&gt;
===Class===&lt;br /&gt;
A ''class'', in object oriented systems, is a kind of metadata that describes the rules by which objects behave; these objects are referred to as instances of that class. A class specifies the structure of data (a.k.a. properties, fields, attributes, data members) within each instance as well as methods (functions) (a.k.a. behaviors) which manipulate the data of the object and perform tasks.&lt;br /&gt;
&lt;br /&gt;
==Types==&lt;br /&gt;
&lt;br /&gt;
Types are abstract views that define properties of a set of entities. Object-oriented programming languages must allow to implement these types. Consequently, once a type is implemented we have a particular representation of it available. We will use the seminal concept of the integer data type to explain the concept of type in detail. Programming languages such as C, Java, C++, Pascal and others already offer an implementation for it. Sometimes it is called int or integer. Once you've created a variable of this type you can use its provided operations. For example, you can add two integers: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
  int i, j, k;    /* Define three integers */&lt;br /&gt;
&lt;br /&gt;
  i = 1;          /* Assign 1 to integer i */&lt;br /&gt;
  j = 2;          /* Assign 2 to integer j */&lt;br /&gt;
  k = i + j;      /* Assign the sum of i and j to k */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first line defines three instances i, j and k of type Integer. Consequently, for each instance the special operation constructor should be called. In our example, this is internally done by the compiler. The compiler reserves memory to hold the value of an integer and ''binds'' the corresponding name to it. If you refer to i you actually refer to this memory area which was ''constructed'' by the definition of i. &lt;br /&gt;
&lt;br /&gt;
The implementation of types comprises of the data (internal structure of the object’s data) and operation (methods / procedures which implement the interface operations). By making users declare the types of variables at compile time, the system simplifies the procedure of checking the program correctness at compile time, thereby increasing programmer productivity. The types cannot be modified at run-time.&lt;br /&gt;
&lt;br /&gt;
===Properties of a Type===&lt;br /&gt;
* It exports a set of operations. This set is called interface. &lt;br /&gt;
* Operations of the interface are the one and only access mechanism to the type's data structure. &lt;br /&gt;
* Axioms and preconditions define the application domain of the type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
&lt;br /&gt;
A class is a combination of state (data) and behavior (methods) that manipulate the state. A class is a blueprint for an object.It is an actual representation of a type. It therefore provides implementation details for the data structure used and operations specified in the type. Now we will define a class that implements the Integer data type: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;  &lt;br /&gt;
class Integer {&lt;br /&gt;
  attributes: || implementation : &lt;br /&gt;
    int i /* Integer data type */&lt;br /&gt;
&lt;br /&gt;
  methods: || operation :&lt;br /&gt;
    setValue(int n) /* To assign value to i */&lt;br /&gt;
    Integer addValue(Integer j) /* To add integer j with i */&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this notation class {...} denotes the definition of a class. Enclosed in the curly brackets are two sections attributes: and methods: which define the implementation of the data structure and operations of the corresponding class. Again we distinguish the two levels with different terms: At the implementation level we speak of ''attributes'' which are elements of the data structure at the class level. The same applies to ''methods'' which are the implementation of the class operations. &lt;br /&gt;
In our example, the attribute is an ordinary integer of a programming language . We only define two methods setValue() and addValue() representing the two of the many operations that can be performed on an integer data type set and add, to make the comparison succinct and concise.&lt;br /&gt;
&lt;br /&gt;
Although the specification of a class is pretty similar to that of a type, it is more of a runtime notion. There are two major aspects of a class – an object factory and an object warehouse. The object factory is the means by which objects of a class are created, using the new operation on the class. Object warehouse stores the set of objects that are instances of the class. Users can work with all these objects by performing all the allowed operations on them and thereby change the contents of the object warehouse. Thus, classes by no means determine the correctness of a program, rather they are used to create and manipulate objects, thereby making the system more flexible.&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
The concept of ''type'' itself is an abstraction, such as it can be either a ''value type'' or a ''reference type''. In most languages, ''Type'' is the most general abstraction, with ''value types'' and ''reference types'' as subtypes of the general type.&lt;br /&gt;
&lt;br /&gt;
Value types in turn can be of different kinds, such as the primitive types, but some languages also allow you to construct compound types which are classes. Reference types can also have different constructions, such as class as one and some would consider arrays as another.&lt;br /&gt;
&lt;br /&gt;
In reality, type is whatever type you can assign as a type to a variable, which includes both value types and reference types. Since the concepts of types and classes are tightly coupled, in this article we don't explicitly show direct contrasts between them, but rather subtly bring out the differences in their implementations in various programming languages.&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in C++==&lt;br /&gt;
&lt;br /&gt;
C++ supports three kinds of object types:&lt;br /&gt;
    * Fundamental types are built into the language (such as int, float, or double). Instances of these fundamental types are &lt;br /&gt;
      often called ''variables''.&lt;br /&gt;
    * Derived types are new types derived from built-in types.&lt;br /&gt;
    * Class types are new types created by combining existing types. These include Classes, Structures, and Unions.&lt;br /&gt;
&lt;br /&gt;
===Fundamental Types===&lt;br /&gt;
&lt;br /&gt;
Fundamental types in C++ are divided into three categories: integral, floating, and void. Integral types are capable of handling whole numbers. Floating types are capable of specifying values that may have fractional parts.The void type describes an empty set of values. No variable of type void can be specified — it is used primarily to declare functions that return no values or to declare generic pointers to untyped or arbitrarily typed data&lt;br /&gt;
&lt;br /&gt;
===Derived Types===&lt;br /&gt;
&lt;br /&gt;
Derived types are new types that can be used in a program, and can include directly derived types and composed derivative types.&lt;br /&gt;
====Directly Derived Types====&lt;br /&gt;
&lt;br /&gt;
New types derived directly from existing types are types that point to, refer to, or (in the case of functions) transform type data to return a new type.&lt;br /&gt;
&lt;br /&gt;
    * Arrays of Variables or Objects&lt;br /&gt;
    * Functions&lt;br /&gt;
    * Pointers of a Given Type&lt;br /&gt;
    * References to Objects&lt;br /&gt;
    * Constants&lt;br /&gt;
    * Pointers to Class Members&lt;br /&gt;
====Composed Derivative Types====&lt;br /&gt;
&lt;br /&gt;
The following are the various composed derivative types:&lt;br /&gt;
&lt;br /&gt;
    * Classes&lt;br /&gt;
    * Structures&lt;br /&gt;
    * Unions&lt;br /&gt;
&lt;br /&gt;
Class types are derivatives of composed types. More on class types below.&lt;br /&gt;
&lt;br /&gt;
===Class Types===&lt;br /&gt;
&lt;br /&gt;
Class types are defined using the class, struct, and union keywords. For simplicity, types defined with these keywords are called class declarations. Class Type names are introduced as identifiers immediately after the compiler processes them (before entry into the class body); they can be used to declare class members. This allows declaration of self-referential data structures&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define TRUE = 1&lt;br /&gt;
&lt;br /&gt;
class dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public:&lt;br /&gt;
   dog()&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(string dogSize)&lt;br /&gt;
   {&lt;br /&gt;
      _dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   string getDogSize()&lt;br /&gt;
   {&lt;br /&gt;
      return _dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(string breed)&lt;br /&gt;
   {&lt;br /&gt;
      _breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   private: // attributes || fundamental types&lt;br /&gt;
   string _dogSize, _breed;&lt;br /&gt;
   int _legs;&lt;br /&gt;
   bool _bark;&lt;br /&gt;
&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   dog mongrel;//class types&lt;br /&gt;
   //setting specific attributes that makes it different from types&lt;br /&gt;
   mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
   mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Ricky is a &amp;quot; &amp;lt;&amp;lt; mongrel.getDogSize() &amp;lt;&amp;lt; &amp;quot; sized dog&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Java==&lt;br /&gt;
&lt;br /&gt;
Java is a strongly typed language i.e. the type of every variable and expression used in a program must be known at compile time. The type of a variable / expression defines the range of values that it can hold. The type of a variable also determines the operations that can be performed on that variable. The strong typing nature of Java enables it to determine errors at compile time.Whenever a variable is declared in Java, we need to mention its type, which may be a class, interface or a primitive. When an object of a subclass of some other class is instantiated, we can say that the object is of type subclass and type superclass and it can perform all operations of both the subclass and the superclass.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are two different types in Java :&lt;br /&gt;
    * Primitive Types are boolean and numeric. The numeric types are the integral types byte, short, int, long, and char, and the         &lt;br /&gt;
      floating-point types float and double. &lt;br /&gt;
    * Reference Types are class types, interface types and array types.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|width=&amp;quot;100%&amp;quot;  border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; bordercolor = &amp;quot;black&amp;quot; cellspacing=&amp;quot;2&amp;quot; align = &amp;quot;left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!A side note on Null Types&lt;br /&gt;
|-&lt;br /&gt;
|There is also a special null type in Java, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Primitive Types====&lt;br /&gt;
&lt;br /&gt;
A primitive type is predefined by the Java programming language and named by its reserved keyword.Primitive values do not share state with other primitive values. A variable whose type is a primitive type always holds a primitive value of that same type. The value of a variable of primitive type can be changed only by assignment operations on that variable.&lt;br /&gt;
&lt;br /&gt;
====Reference Types====&lt;br /&gt;
&lt;br /&gt;
There are three kinds of reference types: class types, interface types, and array types.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt; &lt;br /&gt;
ReferenceType:&lt;br /&gt;
	ClassOrInterfaceType&lt;br /&gt;
	ArrayType&lt;br /&gt;
&lt;br /&gt;
ClassOrInterfaceType:&lt;br /&gt;
	ClassType&lt;br /&gt;
	InterfaceType&lt;br /&gt;
&lt;br /&gt;
ClassType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
InterfaceType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
ArrayType:&lt;br /&gt;
        [ ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
class Dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public Dog() //constructor&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(String dogSize) //setter method&lt;br /&gt;
   {&lt;br /&gt;
      this.dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   String getDogSize() //getter method&lt;br /&gt;
   {&lt;br /&gt;
      return this.dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(String breed)&lt;br /&gt;
   {&lt;br /&gt;
      this.breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   // attributes || fundamental types&lt;br /&gt;
   String dogSize = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   Sting breed = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   int legs;&lt;br /&gt;
   boolean bark;&lt;br /&gt;
   public static void main(String[] args)&lt;br /&gt;
   {&lt;br /&gt;
     Dog mongrel = new Dog();//class types&lt;br /&gt;
     //setting specific attributes that makes it different from types&lt;br /&gt;
     mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
     mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
     System.out.println(&amp;quot;Ricky is a &amp;quot;+ mongrel.getSize() +&amp;quot; size dog&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby being a dynamically typed, reflective object oriented language, every variable is an object and we do not explicitly mention their type as in other object oriented languages, rather the type is implicitly inferred from the type of the value which is assigned to them at runtime. Hence there is no distinction between primitive data types and object types in ruby. In Ruby, all classes are instances of the class Class. Whenever a new class is defined, an object of type Class is created and assigned to the ''Name'' of the class. ''Name.new'' is used to create a new object of the class. This invokes the ''new'' instance method in Class, which in turn calls the ''allocate'' method to allocate memory for the object, before finally calling the new object's initialize method. Thus, the construction of an object is separate from its initialization, and both can be over-ridden. The initialization is done via the ''initialize'' instance method while the construction is done via the ''new'' class method.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#since ruby is dynamic Oo language no explicit type assignment statements&lt;br /&gt;
class Dog &lt;br /&gt;
&lt;br /&gt;
   #implementation&lt;br /&gt;
   def initialize&lt;br /&gt;
      @legs = 4&lt;br /&gt;
      @bark = true&lt;br /&gt;
   end&lt;br /&gt;
   #attributes&lt;br /&gt;
   attr_accessor :dogSize, :breed &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
#at runtime   &lt;br /&gt;
mongrel = Dog.new #dynamiclly typed&lt;br /&gt;
#setting specific attributes that makes it different from types&lt;br /&gt;
mongrel.dogSize = &amp;quot;medium&amp;quot; # string class type&lt;br /&gt;
mongrel.breed = &amp;quot;country specific&amp;quot; # string class type&lt;br /&gt;
puts &amp;quot;Ricky is a #{mongrel.dogSize} size dog&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
Types and Classes [http://www.cs.cmu.edu/People/clamen/OODBMS/Manifesto/htManifesto/node6.html]&amp;lt;br&amp;gt;&lt;br /&gt;
Object Oriented Programming concepts on Wiki [http://en.wikipedia.org/wiki/Object-oriented_programming]&amp;lt;br&amp;gt;&lt;br /&gt;
OOP vs type classes [http://haskell.org/haskellwiki/OOP_vs_type_classes]&amp;lt;br&amp;gt;&lt;br /&gt;
Java Language Specification,Second Edition Chapter4: Types, Values, Variables [http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html]&amp;lt;br&amp;gt;&lt;br /&gt;
Java Programming/Types on wiki [http://en.wikibooks.org/wiki/Java_Programming/Types]&amp;lt;br&amp;gt;&lt;br /&gt;
Writing Classes in Ruby and Insipration for Example[http://rubylearning.com/satishtalim/writing_our_own_class_in_ruby.html]&amp;lt;br&amp;gt;&lt;br /&gt;
What is the difference between class and type [http://www.velocityreviews.com/forums/t127376-what-is-the-difference-between-class-and-type.html]&lt;br /&gt;
&lt;br /&gt;
==Further Reading / External Links== &lt;br /&gt;
&lt;br /&gt;
Bjarne Stroustrup's article on OOP in C++ and beyond http://www.research.att.com/~bs/bs_faq.html#oop&amp;lt;br&amp;gt;&lt;br /&gt;
B. Stroustrup, The C++ Programming Language, 3rd-ed., p. 158&amp;lt;br&amp;gt;&lt;br /&gt;
Fundamentals of OOP and Data Structures in Java - Page xiii by Richard Wiener, Lewis J. Pinson &amp;lt;br&amp;gt;&lt;br /&gt;
Type vs Class, A general overview http://lambda-the-ultimate.org/node/2079&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=7450</id>
		<title>CSC/ECE 517 Fall 2007/wiki2 6 ap</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2007/wiki2_6_ap&amp;diff=7450"/>
		<updated>2007-10-24T21:12:24Z</updated>

		<summary type="html">&lt;p&gt;Pnphadni: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Topic'''&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Type vs. class. Survey the differences on type vs. class in object-oriented languages. Often, the distinction is that class pertains to an object, whereas type pertains to a variable. Consider the distinction between the two terms in several different programming languages. Cover the differences between type and class, from type-theoretic definitions to practical aspects.&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
In object oriented programming concepts, the difference between types and classes is not clearly understood. The differences between them are subtle and the two terms are often misunderstood to be the same. In the article we try to bring out the differences between Types and Classes and provide more insight into them. Furthermore, in OOP languages, classes are types, while most types are not classes. In pure object languages, by opposition (e.g. Smalltalk, Scala, perhaps Python), every type maps to a class.    &lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
===Type=== &lt;br /&gt;
A ''type'', in an object-oriented system, summarizes the common features of a set of objects with the same characteristics. It corresponds to the notion of an abstract data type. Type has 2 parts: the interface and the implementation(s). The interface, which is the only part visible to the user, consists of a list of operations and their signatures. The type implementation is of concern only to the type designer.&lt;br /&gt;
&lt;br /&gt;
===Class===&lt;br /&gt;
A ''class'', in object oriented systems, is a kind of metadata that describes the rules by which objects behave; these objects are referred to as instances of that class. A class specifies the structure of data (a.k.a. properties, fields, attributes, data members) within each instance as well as methods (functions) (a.k.a. behaviors) which manipulate the data of the object and perform tasks.&lt;br /&gt;
&lt;br /&gt;
==Types==&lt;br /&gt;
&lt;br /&gt;
Types are abstract views that define properties of a set of entities. Object-oriented programming languages must allow to implement these types. Consequently, once a type is implemented we have a particular representation of it available. We will use the seminal concept of the integer data type to explain the concept of type in detail. Programming languages such as C, Java, C++, Pascal and others already offer an implementation for it. Sometimes it is called int or integer. Once you've created a variable of this type you can use its provided operations. For example, you can add two integers: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
  int i, j, k;    /* Define three integers */&lt;br /&gt;
&lt;br /&gt;
  i = 1;          /* Assign 1 to integer i */&lt;br /&gt;
  j = 2;          /* Assign 2 to integer j */&lt;br /&gt;
  k = i + j;      /* Assign the sum of i and j to k */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first line defines three instances i, j and k of type Integer. Consequently, for each instance the special operation constructor should be called. In our example, this is internally done by the compiler. The compiler reserves memory to hold the value of an integer and ''binds'' the corresponding name to it. If you refer to i you actually refer to this memory area which was ''constructed'' by the definition of i. &lt;br /&gt;
&lt;br /&gt;
The implementation of types comprises of the data (internal structure of the object’s data) and operation (methods / procedures which implement the interface operations). By making users declare the types of variables at compile time, the system simplifies the procedure of checking the program correctness at compile time, thereby increasing programmer productivity. The types cannot be modified at run-time.&lt;br /&gt;
&lt;br /&gt;
===Properties of a Type===&lt;br /&gt;
* It exports a set of operations. This set is called interface. &lt;br /&gt;
* Operations of the interface are the one and only access mechanism to the type's data structure. &lt;br /&gt;
* Axioms and preconditions define the application domain of the type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
&lt;br /&gt;
A class is a combination of state (data) and behavior (methods) that manipulate the state. A class is a blueprint for an object.It is an actual representation of a type. It therefore provides implementation details for the data structure used and operations specified in the type. Now we will define a class that implements the Integer data type: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;  &lt;br /&gt;
class Integer {&lt;br /&gt;
  attributes: || implementation : &lt;br /&gt;
    int i /* Integer data type */&lt;br /&gt;
&lt;br /&gt;
  methods: || operation :&lt;br /&gt;
    setValue(int n) /* To assign value to i */&lt;br /&gt;
    Integer addValue(Integer j) /* To add integer j with i */&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this notation class {...} denotes the definition of a class. Enclosed in the curly brackets are two sections attributes: and methods: which define the implementation of the data structure and operations of the corresponding class. Again we distinguish the two levels with different terms: At the implementation level we speak of ''attributes'' which are elements of the data structure at the class level. The same applies to ''methods'' which are the implementation of the class operations. &lt;br /&gt;
In our example, the attribute is an ordinary integer of a programming language . We only define two methods setValue() and addValue() representing the two of the many operations that can be performed on an integer data type set and add, to make the comparison succinct and concise.&lt;br /&gt;
&lt;br /&gt;
Although the specification of a class is pretty similar to that of a type, it is more of a runtime notion. There are two major aspects of a class – an object factory and an object warehouse. The object factory is the means by which objects of a class are created, using the new operation on the class. Object warehouse stores the set of objects that are instances of the class. Users can work with all these objects by performing all the allowed operations on them and thereby change the contents of the object warehouse. Thus, classes by no means determine the correctness of a program, rather they are used to create and manipulate objects, thereby making the system more flexible.&lt;br /&gt;
&lt;br /&gt;
==Types vs Classes==&lt;br /&gt;
&lt;br /&gt;
The concept of ''type'' itself is an abstraction, such as it can be either a ''value type'' or a ''reference type''. In most languages, ''Type'' is the most general abstraction, with ''value types'' and ''reference types'' as subtypes of the general type.&lt;br /&gt;
&lt;br /&gt;
Value types in turn can be of different kinds, such as the primitive types, but some languages also allow you to construct compound types which are classes. Reference types can also have different constructions, such as class as one and some would consider arrays as another.&lt;br /&gt;
&lt;br /&gt;
In reality, type is whatever type you can assign as a type to a variable, which includes both value types and reference types. Since the concepts of types and classes are tightly coupled, in this article we don't explicitly show direct contrasts between them, but rather subtly bring out the differences in their implementations in various programming languages.&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in C++==&lt;br /&gt;
&lt;br /&gt;
C++ supports three kinds of object types:&lt;br /&gt;
    * Fundamental types are built into the language (such as int, float, or double). Instances of these fundamental types are &lt;br /&gt;
      often called ''variables''.&lt;br /&gt;
    * Derived types are new types derived from built-in types.&lt;br /&gt;
    * Class types are new types created by combining existing types. These include Classes, Structures, and Unions.&lt;br /&gt;
&lt;br /&gt;
===Fundamental Types===&lt;br /&gt;
&lt;br /&gt;
Fundamental types in C++ are divided into three categories: integral, floating, and void. Integral types are capable of handling whole numbers. Floating types are capable of specifying values that may have fractional parts.The void type describes an empty set of values. No variable of type void can be specified — it is used primarily to declare functions that return no values or to declare generic pointers to untyped or arbitrarily typed data&lt;br /&gt;
&lt;br /&gt;
===Derived Types===&lt;br /&gt;
&lt;br /&gt;
Derived types are new types that can be used in a program, and can include directly derived types and composed derivative types.&lt;br /&gt;
====Directly Derived Types====&lt;br /&gt;
&lt;br /&gt;
New types derived directly from existing types are types that point to, refer to, or (in the case of functions) transform type data to return a new type.&lt;br /&gt;
&lt;br /&gt;
    * Arrays of Variables or Objects&lt;br /&gt;
    * Functions&lt;br /&gt;
    * Pointers of a Given Type&lt;br /&gt;
    * References to Objects&lt;br /&gt;
    * Constants&lt;br /&gt;
    * Pointers to Class Members&lt;br /&gt;
====Composed Derivative Types====&lt;br /&gt;
&lt;br /&gt;
The following are the various composed derivative types:&lt;br /&gt;
&lt;br /&gt;
    * Classes&lt;br /&gt;
    * Structures&lt;br /&gt;
    * Unions&lt;br /&gt;
&lt;br /&gt;
Class types are derivatives of composed types. More on class types below.&lt;br /&gt;
&lt;br /&gt;
===Class Types===&lt;br /&gt;
&lt;br /&gt;
Class types are defined using the class, struct, and union keywords. For simplicity, types defined with these keywords are called class declarations. Class Type names are introduced as identifiers immediately after the compiler processes them (before entry into the class body); they can be used to declare class members. This allows declaration of self-referential data structures&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define TRUE = 1&lt;br /&gt;
&lt;br /&gt;
class dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public:&lt;br /&gt;
   dog()&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(string dogSize)&lt;br /&gt;
   {&lt;br /&gt;
      _dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   string getDogSize()&lt;br /&gt;
   {&lt;br /&gt;
      return _dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(string breed)&lt;br /&gt;
   {&lt;br /&gt;
      _breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   private: // attributes || fundamental types&lt;br /&gt;
   string _dogSize, _breed;&lt;br /&gt;
   int _legs;&lt;br /&gt;
   bool _bark;&lt;br /&gt;
&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   dog mongrel;//class types&lt;br /&gt;
   //setting specific attributes that makes it different from types&lt;br /&gt;
   mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
   mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Ricky is a &amp;quot; &amp;lt;&amp;lt; mongrel.getDogSize() &amp;lt;&amp;lt; &amp;quot; sized dog&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Java==&lt;br /&gt;
&lt;br /&gt;
Java is a strongly typed language i.e. the type of every variable and expression used in a program must be known at compile time. The type of a variable / expression defines the range of values that it can hold. The type of a variable also determines the operations that can be performed on that variable. The strong typing nature of Java enables it to determine errors at compile time.Whenever a variable is declared in Java, we need to mention its type, which may be a class, interface or a primitive. When an object of a subclass of some other class is instantiated, we can say that the object is of type subclass and type superclass and it can perform all operations of both the subclass and the superclass.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are two different types in Java :&lt;br /&gt;
    * Primitive Types are boolean and numeric. The numeric types are the integral types byte, short, int, long, and char, and the         &lt;br /&gt;
      floating-point types float and double. &lt;br /&gt;
    * Reference Types are class types, interface types and array types.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|width=&amp;quot;100%&amp;quot;  border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; bordercolor = &amp;quot;black&amp;quot; cellspacing=&amp;quot;2&amp;quot; align = &amp;quot;left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!A side note on Null Types&lt;br /&gt;
|-&lt;br /&gt;
|There is also a special null type in Java, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Primitive Types====&lt;br /&gt;
&lt;br /&gt;
A primitive type is predefined by the Java programming language and named by its reserved keyword.Primitive values do not share state with other primitive values. A variable whose type is a primitive type always holds a primitive value of that same type. The value of a variable of primitive type can be changed only by assignment operations on that variable.&lt;br /&gt;
&lt;br /&gt;
====Reference Types====&lt;br /&gt;
&lt;br /&gt;
There are three kinds of reference types: class types, interface types, and array types.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt; &lt;br /&gt;
ReferenceType:&lt;br /&gt;
	ClassOrInterfaceType&lt;br /&gt;
	ArrayType&lt;br /&gt;
&lt;br /&gt;
ClassOrInterfaceType:&lt;br /&gt;
	ClassType&lt;br /&gt;
	InterfaceType&lt;br /&gt;
&lt;br /&gt;
ClassType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
InterfaceType:&lt;br /&gt;
	TypeName&lt;br /&gt;
&lt;br /&gt;
ArrayType:&lt;br /&gt;
        [ ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
class Dog &lt;br /&gt;
{&lt;br /&gt;
   //implementation&lt;br /&gt;
   public Dog() //constructor&lt;br /&gt;
   {&lt;br /&gt;
      legs = 4;&lt;br /&gt;
      bark = true;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   void setDogSize(String dogSize) //setter method&lt;br /&gt;
   {&lt;br /&gt;
      this.dogSize = dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   String getDogSize() //getter method&lt;br /&gt;
   {&lt;br /&gt;
      return this.dogSize;&lt;br /&gt;
   }&lt;br /&gt;
   void setBreed(String breed)&lt;br /&gt;
   {&lt;br /&gt;
      this.breed = breed;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   // attributes || fundamental types&lt;br /&gt;
   String dogSize = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   Sting breed = new String (&amp;quot;&amp;quot;);&lt;br /&gt;
   int legs;&lt;br /&gt;
   boolean bark;&lt;br /&gt;
   public static void main(String[] args)&lt;br /&gt;
   {&lt;br /&gt;
     Dog mongrel = new Dog();//class types&lt;br /&gt;
     //setting specific attributes that makes it different from types&lt;br /&gt;
     mongrel.setDogSize(&amp;quot;medium&amp;quot;);&lt;br /&gt;
     mongrel.setBreed(&amp;quot;country specific&amp;quot;);&lt;br /&gt;
     System.out.println(&amp;quot;Ricky is a &amp;quot;+ mongrel.getSize() +&amp;quot; size dog&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Types and Classes in Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby being a dynamically typed, reflective object oriented language, every variable is an object and we do not explicitly mention their type as in other object oriented languages, rather the type is implicitly inferred from the type of the value which is assigned to them at runtime. Hence there is no distinction between primitive data types and object types in ruby. In Ruby, all classes are instances of the class Class. Whenever a new class is defined, an object of type Class is created and assigned to the ''Name'' of the class. ''Name.new'' is used to create a new object of the class. This invokes the ''new'' instance method in Class, which in turn calls the ''allocate'' method to allocate memory for the object, before finally calling the new object's initialize method. Thus, the construction of an object is separate from its initialization, and both can be over-ridden. The initialization is done via the ''initialize'' instance method while the construction is done via the ''new'' class method.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example :'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#since ruby is dynamic Oo language no explicit type assignment statements&lt;br /&gt;
class Dog &lt;br /&gt;
&lt;br /&gt;
   #implementation&lt;br /&gt;
   def initialize&lt;br /&gt;
      @legs = 4&lt;br /&gt;
      @bark = true&lt;br /&gt;
   end&lt;br /&gt;
   #attributes&lt;br /&gt;
   attr_accessor :dogSize, :breed &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
#at runtime   &lt;br /&gt;
mongrel = Dog.new #dynamiclly typed&lt;br /&gt;
#setting specific attributes that makes it different from types&lt;br /&gt;
mongrel.dogSize = &amp;quot;medium&amp;quot; # string class type&lt;br /&gt;
mongrel.breed = &amp;quot;country specific&amp;quot; # string class type&lt;br /&gt;
puts &amp;quot;Ricky is a #{mongrel.dogSize} size dog&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Ricky is a medium sized dog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
Types and Classes [http://www.cs.cmu.edu/People/clamen/OODBMS/Manifesto/htManifesto/node6.html]&amp;lt;br&amp;gt;&lt;br /&gt;
Object Oriented Programming concepts on Wiki [http://en.wikipedia.org/wiki/Object-oriented_programming]&amp;lt;br&amp;gt;&lt;br /&gt;
OOP vs type classes [http://haskell.org/haskellwiki/OOP_vs_type_classes]&amp;lt;br&amp;gt;&lt;br /&gt;
Java Language Specification,Second Edition Chapter4: Types, Values, Variables [http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html]&amp;lt;br&amp;gt;&lt;br /&gt;
Java Programming/Types on wiki [http://en.wikibooks.org/wiki/Java_Programming/Types]&amp;lt;br&amp;gt;&lt;br /&gt;
Writing Classes in Ruby and Insipration for Example[http://rubylearning.com/satishtalim/writing_our_own_class_in_ruby.html]&amp;lt;br&amp;gt;&lt;br /&gt;
What is the difference between class and type [http://www.velocityreviews.com/forums/t127376-what-is-the-difference-between-class-and-type.html]&lt;br /&gt;
&lt;br /&gt;
==Further Reading / External Links== &lt;br /&gt;
&lt;br /&gt;
Bjarne Stroustrup's article on OOP in C++ and beyond http://www.research.att.com/~bs/bs_faq.html#oop&amp;lt;br&amp;gt;&lt;br /&gt;
B. Stroustrup, The C++ Programming Language, 3rd-ed., p. 158&amp;lt;br&amp;gt;&lt;br /&gt;
Fundamentals of OOP and Data Structures in Java - Page xiii by Richard Wiener, Lewis J. Pinson &amp;lt;br&amp;gt;&lt;br /&gt;
Type vs Class, A general overview http://lambda-the-ultimate.org/node/2079&lt;/div&gt;</summary>
		<author><name>Pnphadni</name></author>
	</entry>
</feed>