Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #39204 > unrolled thread

How to handle methods in a common interface that supports different versions of a message format

Started bymike <mikaelpetterson@hotmail.com>
First post2019-12-05 23:55 -0800
Last post2019-12-10 16:41 +0000
Articles 6 — 4 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  How to handle methods in a common interface that supports different versions of a message format mike <mikaelpetterson@hotmail.com> - 2019-12-05 23:55 -0800
    How to handle methods in a common interface that supports different versions of a message format javaXp <n.sharir@gmail.com> - 2019-12-06 04:27 -0800
    Re: How to handle methods in a common interface that supports different versions of a message format Arne Vajhøj <arne@vajhoej.dk> - 2019-12-06 21:49 -0500
      Re: How to handle methods in a common interface that supports different versions of a message format mike <mikaelpetterson@hotmail.com> - 2019-12-08 23:51 -0800
        Re: How to handle methods in a common interface that supports different versions of a message format Arne Vajhøj <arne@vajhoej.dk> - 2019-12-09 21:24 -0500
        Re: How to handle methods in a common interface that supports different versions of a message format Andreas Leitgeb <avl@logic.at> - 2019-12-10 16:41 +0000

#39204 — How to handle methods in a common interface that supports different versions of a message format

Frommike <mikaelpetterson@hotmail.com>
Date2019-12-05 23:55 -0800
SubjectHow to handle methods in a common interface that supports different versions of a message format
Message-ID<2adff0bf-b579-4a12-87bc-70e1fe90a829@googlegroups.com>
Hi,

I would need some advice in the following issue:


public interface Netconf {


void methodA();

void methodB();


}

The issue I have is that methodA() only supports NETCONF message 1.0 and methodB() only supports NETCONF message 1.1

1. Is it better to have separate interfaces like: Netconf and Netconf_1.1 ( better naming?)
2. If we use one interface, Netconf, and in the implementation we have a property for netconfVersion should I just throw exception if methodA() is called and we have set netconfVersion 1.1?

Any other considerations I need to do when supporting multiple versions of a message like NETCONF?

br,

//mike

[toc] | [next] | [standalone]


#39205

FromjavaXp <n.sharir@gmail.com>
Date2019-12-06 04:27 -0800
Message-ID<49ff8821-105d-4073-b076-dd360c078544@googlegroups.com>
In reply to#39204
What's the actual action of A and B? Is it the same action but only for the two different versions?

[toc] | [prev] | [next] | [standalone]


#39209

FromArne Vajhøj <arne@vajhoej.dk>
Date2019-12-06 21:49 -0500
Message-ID<qsf3v9$1rqj$1@gioia.aioe.org>
In reply to#39204
On 12/6/2019 2:55 AM, mike wrote:
> I would need some advice in the following issue:
> 
> public interface Netconf {
> 
> void methodA();
> 
> void methodB();
> 
> }
> 
> The issue I have is that methodA() only supports NETCONF message 1.0 and methodB() only supports NETCONF message 1.1
> 
> 1. Is it better to have separate interfaces like: Netconf and Netconf_1.1 ( better naming?)
> 2. If we use one interface, Netconf, and in the implementation we have a property for netconfVersion should I just throw exception if methodA() is called and we have set netconfVersion 1.1?
> 
> Any other considerations I need to do when supporting multiple versions of a message like NETCONF?

If you want to use proper typing then I like:

public interface Netconf {
     NetconfVersion getVersion();
}

public interface Netconf10 extends Netconf {
     void methodA();
}

public interface Netconf11 extends Netconf {
     void methodB();
}

Having methods that should not be there and that throws an exception
is not good IMHO.

Arne


[toc] | [prev] | [next] | [standalone]


#39210

Frommike <mikaelpetterson@hotmail.com>
Date2019-12-08 23:51 -0800
Message-ID<42878753-3e34-4b35-8829-a11f990485d9@googlegroups.com>
In reply to#39209
Den lördag 7 december 2019 kl. 03:49:27 UTC+1 skrev Arne Vajhøj:
> On 12/6/2019 2:55 AM, mike wrote:
> > I would need some advice in the following issue:
> > 
> > public interface Netconf {
> > 
> > void methodA();
> > 
> > void methodB();
> > 
> > }
> > 
> > The issue I have is that methodA() only supports NETCONF message 1.0 and methodB() only supports NETCONF message 1.1
> > 
> > 1. Is it better to have separate interfaces like: Netconf and Netconf_1.1 ( better naming?)
> > 2. If we use one interface, Netconf, and in the implementation we have a property for netconfVersion should I just throw exception if methodA() is called and we have set netconfVersion 1.1?
> > 
> > Any other considerations I need to do when supporting multiple versions of a message like NETCONF?
> 
> If you want to use proper typing then I like:
> 
> public interface Netconf {
>      NetconfVersion getVersion();
> }
> 
> public interface Netconf10 extends Netconf {
>      void methodA();
> }
> 
> public interface Netconf11 extends Netconf {
>      void methodB();
> }
> 
> Having methods that should not be there and that throws an exception
> is not good IMHO.
> 
> Arne

Hi Arne,

Thanks for the reply. I like the idea. I have a follow-up question:

Since we only had support for 1.0 user only used Netconf interface. Now we will return two types of interfaces Netconf10 or Netconf11. This would mean that users using 1.0 (Netconf) now need to use Netconf10 in those cases they need Netconf 1.0 specific methods.Correct?

Thanks again Arne for your valuable input.

//mikael

[toc] | [prev] | [next] | [standalone]


#39211

FromArne Vajhøj <arne@vajhoej.dk>
Date2019-12-09 21:24 -0500
Message-ID<qsmvks$deb$1@gioia.aioe.org>
In reply to#39210
On 12/9/2019 2:51 AM, mike wrote:
> Den lördag 7 december 2019 kl. 03:49:27 UTC+1 skrev Arne Vajhøj:
>> On 12/6/2019 2:55 AM, mike wrote:
>>> I would need some advice in the following issue:
>>> 
>>> public interface Netconf {
>>> 
>>> void methodA();
>>> 
>>> void methodB();
>>> 
>>> }
>>> 
>>> The issue I have is that methodA() only supports NETCONF message
>>> 1.0 and methodB() only supports NETCONF message 1.1
>>> 
>>> 1. Is it better to have separate interfaces like: Netconf and
>>> Netconf_1.1 ( better naming?) 2. If we use one interface,
>>> Netconf, and in the implementation we have a property for
>>> netconfVersion should I just throw exception if methodA() is
>>> called and we have set netconfVersion 1.1?
>>> 
>>> Any other considerations I need to do when supporting multiple
>>> versions of a message like NETCONF?
>> 
>> If you want to use proper typing then I like:
>> 
>> public interface Netconf { NetconfVersion getVersion(); }
>> 
>> public interface Netconf10 extends Netconf { void methodA(); }
>> 
>> public interface Netconf11 extends Netconf { void methodB(); }
>> 
>> Having methods that should not be there and that throws an
>> exception is not good IMHO.

> Thanks for the reply. I like the idea. I have a follow-up question:
> 
> Since we only had support for 1.0 user only used Netconf interface.
> Now we will return two types of interfaces Netconf10 or Netconf11.
> This would mean that users using 1.0 (Netconf) now need to use
> Netconf10 in those cases they need Netconf 1.0 specific
> methods.Correct?

If I understand you correctly then your concern is backwards
compatibility.

So if you today have:

public interface Netconf {
     void methodA();
}

public class NetconfFactory {
     public static Netconf getOne() {
         ...
     }
}

and client code:

Netconf nc = NetconfFactory.getOne();
nc.methodA();

Then you will need to either change client code to ref Netconf10 or
use different namings:

interface NetconfBase
interface Netconf extends NetconfBase
interface Netconf11 extends NetconfBase

Arne


[toc] | [prev] | [next] | [standalone]


#39212

FromAndreas Leitgeb <avl@logic.at>
Date2019-12-10 16:41 +0000
Message-ID<slrnquvil1.mp5.avl@logic.at>
In reply to#39210
mike <mikaelpetterson@hotmail.com> wrote:
> Since we only had support for 1.0 user only used Netconf interface. Now
> we will return two types of interfaces Netconf10 or Netconf11. This
> would mean that users using 1.0 (Netconf) now need to use Netconf10 in
> those cases they need Netconf 1.0 specific methods.Correct?

If you had a time of just "NetConf" released to the world, and still need
to support old code using it, then you're bound to leaving the name "NetConf"
there, meaning "NetConf10".

If later versions of that interface can also lose methods, then you might
need to have a set of methods to return each of the set of NetConf##-Interfaces.
  NetConf getNetConf() { ... }  // Version 1.0
  Netconf_1_1 getNetConf_1_1() { ... }  // Version 1.1

If instead you only added methods, the interfaces could inherit the lower-
version interfaces, and your code would just return the latest Interface
version and that would painlessly cast to whatever older interface version
the user is using.  I'd try hard to get on this track.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web