CSC/ECE 517 Fall 2011/ch1 2b jp: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 15: Line 15:


 
 
C++
{| class="wikitable"
Java
|-
Ruby
!
Access Control Public,protected,private,
! C++
”friends” Public,protected,package,
! Java
private Public,protected,
! Ruby
private
|-
| Access  
control


|Public,protected,private,”friends


|public,private,package,protected


C++
|private,public,protected


Java
|}


Ruby
=== C++ ===
 
=== Java ===
 
=== Ruby ===

Revision as of 01:10, 18 September 2011

Access Control in OO Language

Access control is defined as the ability for a modules implementation to remain hidden behind its public interface. This is achieved in object oriented languages via encapsulation. Access control is closely related to the encapsulation/information hiding principle of object-oriented languages.

Introduction

The term “object oriented programming” was first used by Xerox PARC in Smalltalk programming language so as to refer to the process of using objects as the foundation for computation. Since the introduction of OOP, a large number of modern programming languages are now using the concept. Some of these are FORTRAN, BASIC, and Pascal. There have been some compatibility issues, because many programs were not designed with a OOPs approach in mind. To solve this researcher’s suggested designing languages that used OOP concepts and still retained many of the functions that programmers needed. Examples of this type are Eiffel, Java, and Ruby.

Need for Access Control In OO Languages

One of the key OOP’s concept considered while designing programming languages is encapsulation. Encapsulation will allow a class to hide information from objects that may use the code. For example, the Cat class will have a purr() method. A code will be written which will explain how the cat purrs. Despite this, it is not necessary for Betsy the cat to know how she purrs. Encapsulation makes it easier for the developer to change the code without having to change the code for Betsy. When the structure of class is hidden, it is harder for it to be used in the wrong way.

Encapsulation will basically state which class is allowed to use the members of a certain object. This concept makes it easier for programmers to deal with or avoid errors when developing a program. The members within OOP can be categorized as being protected, public, or private.

Access Control in various OO Languagues

C++ Java Ruby
Access

control

Public,protected,private,”friends public,private,package,protected private,public,protected

C++

Java

Ruby