Tuesday, February 2, 2010

Object-Oriented Design II

Object-Oriented Programming (OOP) deals with object hierarchies and relationships between classes. The concept of inheritance is very powerful in Object Oriented Programming (OOP). It applies to an idea that each new class can be derived from an existing class. Java programming characteristic is that each class is inherited from and existing class. For instance, C1 is a superclass from which C2 is extended, and therefore is called subclass. Polymorphism in OOP is related to the inheritance relationship. A new subclass inherits features from a superclass. Java also supports dynamic binding, where objects could come from anywhere.

Object-Oriented approach to a design is more common due to the fact that OOP methodologies are more effective in complex software design. Objects used in OOP provide abstraction and encapsulation. Abstraction puts the emphasis on the important problems that have to be solved in a design and eliminates the unrelated ones. Encapsulation has been defined by Booch (2007) as "the process of compartmentalizing the elements of an abstraction that constitute its structure and behavior; encapsulation serves to separate the contractual interface of an abstraction and its implementation." (p.51). Encapsulating data and procedures allows hiding information from the user of the object.

In Java programming we can define the following steps:
• Creating and modifying source code
• Compiling the code
• Executing the code

Programming errors are often observed, even by advanced programmers. There are three types of errors:
• syntax errors,
• runtime errors,
• and logic errors.

Finding and debugging the syntax and runtime errors is usually straightforward. Syntax error is recognized by compiler, and occurs when the rules of the programming language are not followed. Runtime error arises when running application tries to perform an operation impossible to execute, like division by zero, or an attempt to access an out-of-bound array element. The program is usually terminated abnormally when the runtime error takes place. However, Java offers capability to handle runtime errors through exception handling, and allows programming of robust applications. Java makes it possible for programs to catch and process exceptions, which may be achieved by using a construct called the try-catch block. Logic errors are usually the most difficult to handle, and occur if the program does not execute the code the way it was intended. Logic errors are often referred to as “bugs” and are difficult to find. Therefore, they require more complex approach.

Java programming uses several data structures that are supported in the Java API. They are arrays, lists, stacks, and queues, binary trees, heaps and priority queues. In OOP data structure is defined similarly to declaring a class and it uses data fields to store data. A data structure stores data as well as provides methods to access and manipulate data. Such operations include deletion insertion, searching, retrieving, modifying, etc.

An array is one of simplest and easiest to use data structures which hold data elements in sequential order. However, the main limitation of an array is its size, which cannot be altered once the arrayed was created. Java offers other structures like lists which allow dynamic sizing of data structure.

Java is very dynamic, versatile language that allows for flexibility in programming of robust applications. Programs written in Java are characterized by portability, which means they run similarly on any hardware and operating system by using Java Virtual Machine.



References
Booch, G. (2007). Object-Oriented Analysis and Design with Applications. Addison-Wesley.
Liang, D. (6th ed.). Introduction to Java Programming. Pearson Prentice Hall.
Sun Developer Network (SDN). (n.d.). Retrieved November 6 2009, from http://java.sun.com/

No comments: