CSC/ECE 517 Fall 2011/ch1 1e dm: Difference between revisions
No edit summary |
No edit summary |
||
Line 56: | Line 56: | ||
[http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Data Encapsulation:] | [http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Data Encapsulation:] | ||
Data Encapsulation is the process of combining [http://en.wikipedia.org/wiki/Data_(computing) data] and [http://en.wikipedia.org/wiki/Function_(computer_science) functions] into a single unit called [http://en.wikipedia.org/wiki/Class_(computer_science) class]. Using this method, one cannot access the data directly, and is accessible only through functions present in a class. It thus gives rise to the concept of data hiding. | Data Encapsulation is the process of combining [http://en.wikipedia.org/wiki/Data_(computing) data] and [http://en.wikipedia.org/wiki/Function_(computer_science) functions] into a single unit called [http://en.wikipedia.org/wiki/Class_(computer_science) class]. Using this method, one cannot access the data directly, and is accessible only through functions present in a class. It thus gives rise to the concept of data hiding. It thus means that the internal representation of an [http://en.wikipedia.org/wiki/Object_(computer_science) object] is generally hidden from view outside of the object's definition. | ||
[http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming Polymorphism:] | [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming Polymorphism:] |
Revision as of 20:19, 5 September 2011
CSC/ECE 517 Fall 2011/ch1 1e dm
Introduction
This wiki article describes the block structured and object oriented languages by highlighting their advantages and limitations along with providing a comparison between them. It also discusses the application of block structured concept in the object oriented programming.
Block Structured Languages
Block structured languages are a class of high-level languages in which a program is made up of blocks. A block is a section of code which can be grouped together. Blocks consist of one or more declarations and statements. A block structured programming language uses and permits the creation of blocks and may also include nested blocks as components. The major function of using blocks is to enable the groups of statements within the block to be treated as if they were a single statement.
Block structured programming is related to structured programming, which is a technique for organizing and coding computer programs in which a hierarchy of modules is used, each having a single entry and a single exit point, and in which control is passed downward through the structure without unconditional branches to higher levels of the structure. A structured program is decomposed into a hierarchy of processes. A process in this context is a body of code, typically a function or subroutine, that takes some input and manipulates it to produce an output. A process may be composed of other, more specialized processes, i.e., it may be a function that calls other functions. Structured Programming uses three types of control flow: sequential, test, and iteration.
Examples of block structured programming languages are ALGOL, FORTAN, Pascal, C, Python, Lisp, Ada, PL/SQL.
Characteristics
- Takes on the top-to-bottom approach.
- Based around data structures and subroutines.
- Uses single entry and exit block.
- The names of variables and other objects such as procedures which are declared in outer blocks are visible inside other inner blocks, unless they are shadowed by an object of the same name.
- Splits the tasks into modular forms.
Advantages
- Splitting of tasks into blocks/modules makes the program simpler and easier to read with less lines and codes.
- Leave the solution coarse where the solution is not interesting.
- Can save an order of magnitude in memory.
- Can save an order of magnitude in run time.
- Numerical accuracy improves with more grid where gradients are strongest.
- Being block-structured allows Fortran to be used for array operations.
- Overhead involved in coarse-fine interactions can be amortized over larger array calculations.
- Numerical accuracy is improved if the coarse-fine interface is kept to a codimension smaller than the solution.
Limitations
- Communication patterns between levels can be complex.
- Algorithm complexity can be substantial.
- No data abstraction or information hiding supported.
Object Oriented Languages
Object oriented programming is an approach to programming in which each data item with the operations used on it is designated as an object; the routines used to operate on the data item are called methods; and objects are grouped in a hierarchy of classes, with each class inheriting characteristics from the class above it.
The four fundamentals of object oriented programming languages are Polymorphism, Inheritance, Encapsulation and Abstraction.
Examples of object oriented programming languages are C++, Java, Smalltalk, Ruby.
Concepts
Objects: Object is the basic unit of object oriented programming. Data and function that operate on data can be bundles as a unit which is called as object.
Classes: Classes are the data types on which objects are created. This concept is similar to that of structures in C. Memory is allocated to the class only when an object is created.
Inheritance: Inheritance is the way to reuse and compartmentalize the code by creating collections of objects that can be based on previously created objects with slightly different or different properties and behaviour. A superclass, base class, or parent class is a class from which other classes are derived. The classes that are derived from a superclass are known as child classes, derived classes, or subclasses.
Data Abstraction: Data abstraction makes it possible to represent the needed information in program without presenting the details. It is also possible to create user defined data types and thus increase the power of programming language.
Data Encapsulation: Data Encapsulation is the process of combining data and functions into a single unit called class. Using this method, one cannot access the data directly, and is accessible only through functions present in a class. It thus gives rise to the concept of data hiding. It thus means that the internal representation of an object is generally hidden from view outside of the object's definition.
Polymorphism: The ability to use an operator or function in different ways in other words giving different meaning or functions to the operators or functions is called polymorphism. Poly refers many. That is a single function or an operator functioning in many ways different upon the usage is called polymorphism.
Overloading: The concept of overloading is also a branch of polymorphism. When the exiting operator or function is made to operate on new data type it is said to be overloaded.
Reusability: That is object oriented programming has the feature of allowing an existing class which is written and debugged to be used by other programmers and there by provides a great time saving and also code efficiency to the language. Also it is possible to a have the existing class and adds new features to the existing class as pet the programmer’s choice.
Thus the object oriented programming features helps the program ad there by users of the application to achieve increased performance, it saves time of developing the application, give optimized code for the application, helps in gaining secured applications and there by helps in easier maintenance.
Advantages
- Simplicity: software objects model real world objects, so the complexity is reduced and the program structure is very clear.
- Modularity: each object forms a separate entity whose internal workings are decoupled from other parts of the system. Hence helps to reduce large problems to smaller, more manageable problems.
- Modifiability: it is easy to make minor changes in the data representation or the procedures in an OO program. Changes inside a class do not affect any other part of a program, since the only public interface that the external world has to a class is through the use of methods. *Extensibility: adding new features or responding to changing operating environments can be solved by introducing a few new objects and modifying some existing ones.
- Maintainability: objects can be maintained separately, making locating and fixing problems easier.
- Re-usability: objects can be reused in different programs.
Limitations
- Over generalization
- Artificial class relations
- Unnecessary complications
Compare and Contrast
Block Structure in Object Oriented Programming
Conclusion
See Also
References
- Advantages of block structured languages
- Advantages of object oriented languages
- Advantages of object oriented languages
- [1]