Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 02-16-2005
Venkat Seeth Venkat Seeth is offline
Registered User
 
 
Join Date: Feb 2005
Posts: 32
Limitations of Overloading operations

Hi there,

Howdy. I'm a newbie to ICE. I'd like to know how to overcome the limitations of overloading operations?

I'm implementing a VISITOR pattern and all the method names happen to have the same name. What are the suggested alternatives avaliable to me.

Thanks,
Venkat
Reply With Quote
  #2 (permalink)  
Old 02-16-2005
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 907
I'm not sure exactly what you are trying to do. For the visitor pattern, you normally don't need to overload operations. For example:

Code:
interface VisitorBase {
    void visit();
};

interface SomeType extends VisitorBase {
    // whatever operations you like; the
    // servant of SomeType implements
    // visit() for that type.
};

interface SomeOtherType extends VisitorBase {
    // whatever operations you like; the
    // servant of SomeOtherType implements
    // visit() for that type.
};
Slice does not allow you to overload operations. For example, the following is illegal:

Code:
interface Foo {
    void op(int param);
    void op(string param); // Redefinition error
};
But overloading really is only syntactic sugar -- you can achieve the same things as:

Code:
interface Foo {
    void opInt(int param);
    void opString(string param);
};
Cheers,

Michi.
Reply With Quote
  #3 (permalink)  
Old 02-16-2005
Venkat Seeth Venkat Seeth is offline
Registered User
 
 
Join Date: Feb 2005
Posts: 32
Hi Michi,

Thanks for the quick response.

I know its only syntactic sugar but it makes it a little easier when the class hierarchy keeps growing and I need to call only one method on the visitor by passing the current instance.

There are 2 flavors:

Code:
interface Shape {
	void accept(ShapeVisitor visitor);
}


class Circle implements Shape {
	void accept(ShapeVisitor visitor) {
		visitor.visit(this);
	}
}

class Square implements Shape {
	void accept(ShapeVisitor visitor) {
		visitor.visit(this);
	}
}

interface ShapeVisitor {
        void visit(Circle circle);
        void visit(Square square);
}
Here, I can eliminate coding the same thing by introducing a base implementation.

Code:
interface Shape {
	void accept(ShapeVisitor visitor);
}


abstract class CommonShape implements Shape {
	void accept(ShapeVisitor visitor) {
		visitor.visit(this);
	}
}

class Circle extends CommonShape {
	// no need to extend accept.
}

class Square extends CommonShape {
	// no need to extend accept.
}

interface ShapeVisitor {
        void visit(Circle circle);
        void visit(Square square);
}
Thanks again,
Venkat
Reply With Quote
  #4 (permalink)  
Old 02-17-2005
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 907
I'm sorry, but there is no way to do this. Slice does not allow overloading of operations because that would make it pretty much impossible to map Slice to languages that do not support this feature. I'm afraid you will have to use visitCircle() and visitSquare() operations.

Cheers,

Michi.
Reply With Quote
  #5 (permalink)  
Old 02-18-2005
Venkat Seeth Venkat Seeth is offline
Registered User
 
 
Join Date: Feb 2005
Posts: 32
Thanks again for your message.

On a related topic, I've been struggling with the architectural implications of Classes With Operations.

Say, with the example, I've a tree of Shape objects and I pass around this tree to various servers, which could interpret it in different ways. Also, add to the fact that each node has some behavior for the Visitor pattern. I'm now struck with providing client-side native code.

Can I just define Shape interface, its container and the Visitor interface in Slice and provide implementations in my choice of PL.

What’s the best/suggested way to solve this kind of a problem?

Any thoughts are appreciated.
Thanks,
Venkat
Reply With Quote
  #6 (permalink)  
Old 02-18-2005
marc's Avatar
marc marc is offline
ZeroC Staff
 
Name: Marc Laukien
Organization: ZeroC, Inc.
Project: The Internet Communications Engine
 
Join Date: Feb 2003
Location: Florida
Posts: 1,781
I'm afraid I don't understand the question. What exactly is the problem? Yes, you must provide the implementation code in your client. Objects by value means that you transfer the type and state of objects, but of course you cannot transfer behavior. This is outside of the scope of the contract specified by Slice, as Slice is not a programming language, but only an interface and state description language. Your application code must make sure that the instances of objects received by value exhibit the appropriate behavior.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Overloading functions in slice Sameerrele Help Center 3 09-05-2006 04:10 PM
Performance in local operations wolfram Comments 4 08-26-2004 07:47 PM
Operations in Class yomi Help Center 2 04-10-2004 10:39 PM
class with operations, Initialization StuartA Help Center 6 02-22-2004 07:58 PM
Why operations on classes? bernard Comments 1 02-21-2003 11:36 AM


All times are GMT -4. The time now is 07:47 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.