CSC/ECE 517 Fall 2011/ch1 1e lm: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
L M
==5. Block-structured vs. o-o languages. Before o-o languages"took over the world" in the 1980s, the spotlight was on block-structured languages. Why were o-o languages more effective and more durable than block-structured languages? Can block structure be useful in an object-oriented language? Explain.==


==Introduction==
This topic will discuss 2 things viz the effectiveness & durability of object oriented languages (like Java, Python, etc) over block structured languages(like C, Pascal, Algol etc) and how block structure can be leveraged in an object oriented language.


5.  Block-structured vs. o-o languages.  Before o-o languages"took over the world" in the 1980s, the spotlight was on block-structured languages.  Why were o-o languages more effective and more durable than block-structured languages?  Can block structure be useful in an object-oriented language?  Explain.


Introduction<br>
==Block structured languages==
===Definition:===
A block(http://en.wikipedia.org/wiki/Block_(programming)) is consisting of one or more declarations(http://en.wikipedia.org/wiki/Declaration_(computer_science)) and statements(http://en.wikipedia.org/wiki/Statement_(programming)). A block structured programming language is the one that would allow usage of such blocks & including nesting(http://en.wikipedia.org/wiki/Nesting_(computing)) of such blocks.
Features of block structured languages:
The purpose of blocks is to allow a group of statements to be treated as one.
For instance, you might want to have a block of statements which does matrix multiplication.


Block structured languages<br>
Blocks also narrow the lexical scope of the variables, procedures & functions declared in a block so that they don’t conflict others(which might be used for a totally different purpose)  having the same name with elsewhere in the program.
Definition<br>
For instance, you might want to have a local variable “count” to count the sum of some variables whereas you might have another local variable with the same name “count” to count the number of elements in an array.
Description<br>
Examples<br>


o-o languages motivation<br>


===Examples:===
1. Adding two numbers in Pascal.
var a,b,s:integer;
begin
write ('Type a: '); readln (a);
write ('Type b: '); readln (b);
s:=a+b;
writeln ('The sum of a+b is ', s);
readln;
end


Oo same as above
Definition<br>
Description<br>
Examples<br>


o-o advantages over block-structured<br>


usefulness of bloc-structured in o-o with examples<br>
 
 
 
2. “Hello World!” in ALGOL 60
BEGIN
FILE F(KIND=REMOTE);
EBCDIC ARRAY E[0:11];
REPLACE E BY "HELLO WORLD!";
WRITE(F, *, E);
END.
 
 
==o-o languages motivation==
 
 
==Object Oriented Languages:==
===Definition===
Object oriented languages is the programming paradigm that bundles the data and the methods that access and manage this data into single entity called an “Object”. This bundling of data and methods allows the object to have a  fluid interface through which it can interact with the outside world. The object tis generally modeled on real world objects.
 
===Fundamental features of OO languages:===
http://en.wikipedia.org/wiki/Object-oriented_design
 
§  Object/Class: Class consists of tightly coupled data fields and methods which act on the data. An object is an instance of a class. An object can be defined by its state (current value of its data members) and its behavior (the methods that can be called on the object 
 
§  Encapsulation: This involves restricting access to data fields and certain methods from external entities. Encapsulation protects an object from accidental modifications y an external entity since data fields can be accessed only through predetermined interfaces.  Encapsulation implemented using language constructs like private, public, protected, etc.
 
§  Inheritance:  Inheritance is the ability of a class to inherit partly or completely the features of another class. Pre-existing classes can be reused by extending them and adding new functionality to create sub classes.
 
§  Interface: Interface is an abstract type containing no data but only a list of method definitions. A class that has all the methods defined in the interface is said to have implemented the method interface.  Interfaces allows us to completely ….. the calling entities. So long
 
§  Polymorphism: This is the ability of a variable, method or an object to take more than 1 forms. This enables an objects of different types to respond to same method or property call but in its own type specific way. The exact type of the object being called is not known until actual runtime.
 
Examples:
              Languages implement different degrees of OO  features
·        Ruby, Scala, Smalltalk, Eiffel are said to be purely OO languages. Here even primitives are impememnted as OO objects.
·          Java, C# , VB.NET, Python are OO languages but have some degree of procedural elements
·        Visual Basic, PHP, Perl are basically procesural languages with some OO features.
 
o-o advantages over block-structured
usefulness of block-structured in o-o with examples

Revision as of 20:11, 5 September 2011

5. Block-structured vs. o-o languages. Before o-o languages"took over the world" in the 1980s, the spotlight was on block-structured languages. Why were o-o languages more effective and more durable than block-structured languages? Can block structure be useful in an object-oriented language? Explain.

Introduction

This topic will discuss 2 things viz the effectiveness & durability of object oriented languages (like Java, Python, etc) over block structured languages(like C, Pascal, Algol etc) and how block structure can be leveraged in an object oriented language.


Block structured languages

Definition:

A block(http://en.wikipedia.org/wiki/Block_(programming)) is consisting of one or more declarations(http://en.wikipedia.org/wiki/Declaration_(computer_science)) and statements(http://en.wikipedia.org/wiki/Statement_(programming)). A block structured programming language is the one that would allow usage of such blocks & including nesting(http://en.wikipedia.org/wiki/Nesting_(computing)) of such blocks. Features of block structured languages: The purpose of blocks is to allow a group of statements to be treated as one. For instance, you might want to have a block of statements which does matrix multiplication.

Blocks also narrow the lexical scope of the variables, procedures & functions declared in a block so that they don’t conflict others(which might be used for a totally different purpose) having the same name with elsewhere in the program. For instance, you might want to have a local variable “count” to count the sum of some variables whereas you might have another local variable with the same name “count” to count the number of elements in an array.


Examples:

1. Adding two numbers in Pascal. var a,b,s:integer; begin write ('Type a: '); readln (a); write ('Type b: '); readln (b); s:=a+b; writeln ('The sum of a+b is ', s); readln; end




2. “Hello World!” in ALGOL 60 BEGIN

FILE F(KIND=REMOTE);
EBCDIC ARRAY E[0:11];
REPLACE E BY "HELLO WORLD!";
WRITE(F, *, E);

END.


o-o languages motivation

Object Oriented Languages:

Definition

Object oriented languages is the programming paradigm that bundles the data and the methods that access and manage this data into single entity called an “Object”. This bundling of data and methods allows the object to have a fluid interface through which it can interact with the outside world. The object tis generally modeled on real world objects.

Fundamental features of OO languages:

http://en.wikipedia.org/wiki/Object-oriented_design

§ Object/Class: Class consists of tightly coupled data fields and methods which act on the data. An object is an instance of a class. An object can be defined by its state (current value of its data members) and its behavior (the methods that can be called on the object

§ Encapsulation: This involves restricting access to data fields and certain methods from external entities. Encapsulation protects an object from accidental modifications y an external entity since data fields can be accessed only through predetermined interfaces. Encapsulation implemented using language constructs like private, public, protected, etc.

§ Inheritance: Inheritance is the ability of a class to inherit partly or completely the features of another class. Pre-existing classes can be reused by extending them and adding new functionality to create sub classes.

§ Interface: Interface is an abstract type containing no data but only a list of method definitions. A class that has all the methods defined in the interface is said to have implemented the method interface. Interfaces allows us to completely ….. the calling entities. So long

§ Polymorphism: This is the ability of a variable, method or an object to take more than 1 forms. This enables an objects of different types to respond to same method or property call but in its own type specific way. The exact type of the object being called is not known until actual runtime.

Examples:

              Languages implement different degrees of OO  features

· Ruby, Scala, Smalltalk, Eiffel are said to be purely OO languages. Here even primitives are impememnted as OO objects. · Java, C# , VB.NET, Python are OO languages but have some degree of procedural elements · Visual Basic, PHP, Perl are basically procesural languages with some OO features.

o-o advantages over block-structured usefulness of block-structured in o-o with examples