CSC/ECE 517 Fall 2007/wiki2 6 ap

From Expertiza_Wiki
Revision as of 12:54, 20 October 2007 by Pnphadni (talk | contribs)
Jump to navigation Jump to search
Types vs Classes


In object oriented languages, type defines the common features of a set of similar objects. A 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.

The implementation comprises 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.

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.


Types vs Classes in Java


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. The 2 types in Java are – primitive types and reference types. The primitive types are boolean and numeric. The reference types are class types, interface types and array types.


Types vs Classes in Ruby


References:


http://www.cs.cmu.edu/People/clamen/OODBMS/Manifesto/htManifesto/node6.html
http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html