Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Basic concept of delegates in java

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 17-11-2009
Member
 
Join Date: May 2008
Posts: 72
Basic concept of delegates in java
  

Hi Guys,

I have sound knowledge about java programming. But the one concept of java I am not able to understand i.e delegates. Is delegated in java is similar as compare to C#?

I read lots of book for this topics but it was too complicated.
Can anybody able to sort-out this problem?...

Reply With Quote
  #2  
Old 17-11-2009
Member
 
Join Date: May 2008
Posts: 2,283
Re: Basic concept of delegates in java

When an object receives a request, the object can handle the request itself or forward the request to next object . If the object forward the request to next object, It means that the object has passed responsibility for handling the request to the another object.


See the below example of stack composition:


Quote:
public class Stack {
private java.util.ArrayList list;

public Stack() {
list = new java.util.ArrayList();
}

public boolean empty() {
return list.isEmpty();
}

public Object peek() {
if( !empty() ) {
return list.get( 0 );
}
return null;
}

public Object pop() {
if( !empty() ) {
return list.remove( 0 );
}
return null;
}

public Object push( Object item ) {
list.add( 0, item );
return item;
}

}
In above example ,Stack holds on to an instance of ArrayList . Stack then passes the requests to the ArrayList instance. Simple composition and request forwarding is called as delegation.
Reply With Quote
  #3  
Old 17-11-2009
Member
 
Join Date: Oct 2005
Posts: 2,385
Re: Basic concept of delegates in java

Hi Friends
I am also have difficulties to understand the delegates concept in the java. I think this is because it is very complicated.
But the only thing which I know is basic concepts of delegate in java and C# is same, but the way of implementing delegates is different. If you know more than this please let me know.
Reply With Quote
  #4  
Old 17-11-2009
Member
 
Join Date: May 2008
Posts: 2,373
Re: Basic concept of delegates in java

In JAVA , delegate is like to a listener . A delegate is one class which is referenced by another class. A class that has a delegate will call methods on the delegate to identify how and when to do certain task. see following example:

Quote:
- (void)tableView: (NSTableView *)tv shouldSelectRow: (int)row
- (void)tableView: (NSTableView *)tv shouldSelectTableColumn: (NSTableColumn *)tc
- (BOOL)tableView: (NSTableView *)tv shouldEditTableColumn: (NStableColumn *)tc row: (int)row
- (void)tableViewSelectionDidChange: (NSNotification *)notification
__________________
The FIFA Manager 2009 PC Game

Last edited by opaper : 17-11-2009 at 08:14 AM.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Basic concept of delegates in java"
Thread Thread Starter Forum Replies Last Post
Basic Java question colby02184 Software Development 2 11-11-2011 04:08 PM
Use of delegates in C sharp opaper Software Development 5 25-01-2010 12:44 PM
Concept of Scrollpane Container in Java Adrina_g Software Development 3 10-12-2009 08:23 AM
Concept of java beans Jabeen Software Development 4 01-12-2009 09:59 AM
threads concept in java vijji191 Software Development 2 30-11-2009 02:44 PM


All times are GMT +5.5. The time now is 02:50 AM.