-
What is delegation?
What is delegation? Could give an example in coding. The following is i found on java glossary.
delegation
An act whereby one principal authorizes another principal to use its identity or privileges with some restrictions.
-
example for delegation
A good example is found at
Javaworld
Look at real life : when your boss gives you a job, you can do it yourself or you can give it to someone else, so delegate it.
It's the same in the next example (found at Javaworld and in the book of Deitel on Java). Here's a piece of the code :
Code:
public class Stack {
private java.util.ArrayList list;
public Stack() {
list = new java.util.ArrayList();
}
public boolean empty() {
return list.isEmpty();
}
You're implementing a Stack but this Stack contains an ArrayList.
If you create a Stack, in fact this Stack asks an ArrayList to be created. If you ask the Stack if it is empty, the Stack asks the ArrayList if it's empty.
So, the work is done by ArrayList after this work is delegated by Stack.
-
Simple composition??
What is the Simple composition means?
Through composition, Stack holds on to an ArrayList instance. As you can see, Stack then forwards the requests to the ArrayList instance. Simple composition and request forwarding (such as that of the Stack class presented above) is often mistakenly referred to as delegation.
-
The idea of delegation is the basis of event-based programming. It allows you to separate logic from presentation. A user clicks his mouse pointer on a component in your GUI, or your user types some text into a TextField, or some other action occurs. That component generates a MouseEvent or a TextEvent or an ActionEvent. That event is dispatched to a listener - you have told the component who to send the event to in your code. The listener knows what to do if an event it is listening for arrives, and does its work. The component does not execute the code - it delegates the handling of the event to the listener.
-
delegation or not
Simple composition and request forwarding (such as that of the Stack class presented above) is often mistakenly referred to as delegation.
Mind you, these examples are found at a website and in a book. It's by no means a self invented example.
It's a bit disappointing if you hear you cannot trust any longer the sources on Java you were sure of.
-
Javaworld is just people like us writing articles.
Yes, in a sense, the work performed by a contained class is a "delegation" of work - using commonly used connotation of the English word - but is it what the "language masters" refer to as "delegation"? It's not for me to say.
I've never read nor used any of Deitel's books but I have read many reviews which trash his (what the reviewers call) lack of technical knowledge.
Similar Threads
-
Replies: 1
Last Post: 04-19-2002, 11:15 AM
-
By Alex L in forum VB Classic
Replies: 8
Last Post: 09-15-2000, 01:13 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks