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

From Expertiza_Wiki
Jump to navigation Jump to search
Line 6: Line 6:


== Why Access Control? ==
== Why Access Control? ==
Access control is a key component of [http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Encapsulation]/[http://en.wikipedia.org/wiki/Information_hiding Information Hiding] principle of object-oriented languages. For example, a class Person may have methods such as name and email, that return the person's name and e-mail address respectively. How these methods work is an implementation detail that should not be available to users of the Person class. These methods may, for example, connect to a database to retrieve the values. The database connection code that is used to do this is not relevant to client code and should not be exposed. Language-enforced access control allows us to enforce this.
== Access control in different o-o languages ==
== Access control in different o-o languages ==
===<b>C++</b>===
===<b>C++</b>===

Revision as of 16:16, 17 September 2011

Access Control in o-o Languages

O-o languages have different approaches to controlling access to variables and methods. Ruby, for example, doesn't allow an object to access the private features of another object, even if the other object is an instance of the same class. Java 1.0 had a "private protected" access specifier that allowed subclasses to access a variable, but not non-subclasses in the same package. It was dropped, probably because it was confusing. Have philosophies about allowing access become more restrictive over the years, as accessor methods have become more prominent?

Introduction

Access control is a feature that is available in many programming languages that allows the programmer to define a set of rules that govern how the elements in a program (for example methods or attributes in a class) can be used from different contexts. While some programming languages like C++, JAVA etc have predefined policies for access control (public/protected/private) allowing structured but limited power in the hands of the programmer, others such as Eiffel provide more flexible access control scheme (selective export). Here, we will look at access control policies of some object-oriented programming languages and how these policies have changed over the years.

Why Access Control?

Access control is a key component of Encapsulation/Information Hiding principle of object-oriented languages. For example, a class Person may have methods such as name and email, that return the person's name and e-mail address respectively. How these methods work is an implementation detail that should not be available to users of the Person class. These methods may, for example, connect to a database to retrieve the values. The database connection code that is used to do this is not relevant to client code and should not be exposed. Language-enforced access control allows us to enforce this.

Access control in different o-o languages

C++

JAVA

Smalltalk

Eiffel

Ruby

What are accessor methods?

Accessor methods in different o-o languages

C++

JAVA

Smalltalk

Eiffel

Ruby

How has access control changed in the recent years?

Conclusion

References