• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding function and process objects

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,

can you explain to me, What is the difference between function objects and process objects?
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know. I'm not aware that those terms are in common use in ordinary Java.
 
Raj chiru
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Campbell,
Thanks For Your Reply.

Actually,I saw those terms in Effective Java,Item 21.But I'm not getting the concept.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Effective Java? I shall look and see whether I can understand that section.
 
Raj chiru
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Effective Java?


YES
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Effective Java section you quoted appears to be page 103-105 in my copy (2nd edition).

It doesn't say anything about process objects that I can see. The function object appears to be an object of a class with no fields; it is passed as a reference to an object only so its methods can be called. Note that Bloch recommends we implement such a class as a Singleton.
You know classes like java.lang.Math have no fields, and you use them only to get access to their methods? Well, these "strategy objects" are rather similar, only instead of their methods all being static, they have instance methods only. Note they usually implement an interface, which means they have to use instance methods.

I think this is too difficult for "beginning" so I shall move the thread.
 
Raj chiru
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:It doesn't say anything about process objects that I can see.


Campbell, see Item 22 in Effective java,Page 108.

One common use of anonymous classes is to create function objects (Item 21)
on the fly. For example, the sort method invocation on page 104 sorts an array of
strings according to their length using an anonymous Comparator instance.
Another common use of anonymous classes is to create process objects, such as
Runnable, Thread, or TimerTask instances.
A third common use is within static
factory methods (see the intArrayAsList method in Item 18).

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the obvious difference is that what he's calling "function objects" are stateless -- they don't contain any data that can change. Whereas the "process objects" are typically (in the case of Thread, always) stateful -- they do contain data that changes over time. Stateless objects can be reused in many contexts simultaneously (and so make good singletons) while stateful objects can't be used this way.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't read as far as section 22 or page 108
 
reply
    Bookmark Topic Watch Topic
  • New Topic