Skip to content

Introduce abstract base class for C# service implementations #5751

Closed
jtattermusch wants to merge 4 commits intogrpc:masterfrom
jtattermusch:csharp_serverside_abstractclass
Closed

Introduce abstract base class for C# service implementations #5751
jtattermusch wants to merge 4 commits intogrpc:masterfrom
jtattermusch:csharp_serverside_abstractclass

Conversation

@jtattermusch
Copy link
Copy Markdown
Contributor

Fixes #5371.

-- introduce an abstract base class that returns NotImplemented status code for all methods
-- mark server-side interface as obsolete
-- change existing service implementations to inherit from the new base class

@jtattermusch
Copy link
Copy Markdown
Contributor Author

I am not sure about the naming of the generated abstract class. Currently it's "MathBase" for service called Math.

@jtattermusch
Copy link
Copy Markdown
Contributor Author

@jskeet @chrisdunelm I still need to add some tests, but I think otherwise this is ready for review.

@jskeet
Copy link
Copy Markdown
Contributor

jskeet commented Mar 15, 2016

Presumably you're most interested in us reviewing the C# output? And the plan is to remove the obsolete interface before GA, so basically acting as a transition between betas?

}

// server-side abstract class
public abstract class BenchmarkServiceBase
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be clearer to generate this without the "Base" part, given that this is the level of inheritance that most clients will actually want to deal with. So just "BenchmarkService" in this case, and "Health" above. I think the "Impl" suffix for the concrete implementation is okay though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't use just "Health" because I think for many services the class name might collide with the namespace name (e.g. service math.Math which i think a pretty common pattern in .proto files). We didn't have this problem with the interface that has the "I" prefix.
Do you see an issue with class name being the same as the package name?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Urgh - yes, that would be nasty. See https://blogs.msdn.microsoft.com/ericlippert/2010/03/09/do-not-name-a-class-the-same-as-its-namespace-part-one

Thinking about this further, for the server-side, this is probably okay - because we genuinely expect users to derive from it in order to implement the service. For the client side, we've already got the Client suffix, so we can presumably have an abstract HealthClient and an implementation of HealthClientImpl.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make this even more complicated, the name of the abstract class cannot be just Health because it is enclosed in an "umbrella" static class called "Health" (and member names cannot be same as their enclosing types).

So basically have these options:

  1. leave HealthBase as is
  2. rename the umbrella class from "Health" to "HeathGrpc". I think that would actually look good in the code (you'd do things like class HealthImpl : HealthGrpc.Health {} and HealthGrpc.BindService(...)). The problem is that all the code using the grpc stubs would need to be updated. We might be able to afford this if we actually removed the client-side interfaces and figured out the ClientBase at the same time - because these would be breaking changes anyway.
  3. come up with some other name of the class than "Health" or "HealthBase".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #5813 to see how would option 2 look like.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having got my head round "this is the server side base, we're not providing an implementation" I'm in favour of it being called HealthBase, and I apologise for previous confusion.

That doesn't mean the change from Health to HealthGrpc is a bad idea - I quite like that.

@jskeet
Copy link
Copy Markdown
Contributor

jskeet commented Mar 15, 2016

Other than the two comments, looks fine to me. Thanks so much for putting the time into this :)

@jtattermusch
Copy link
Copy Markdown
Contributor Author

On Tue, Mar 15, 2016 at 2:27 AM, Jon Skeet [email protected] wrote:

Presumably you're most interested in us reviewing the C# output?

Yes, I should have made that clear.

And the plan is to remove the obsolete interface before GA, so basically
acting as a transition between betas?

The exact timing of removing the interface is TBD (and we probably want to
make this breaking change for all the languages in the same release). We
don't plan to keep the interface around longer than necessary. Is having
the interface not removed by GA problematic for you (the interface is
marked as obsolete)?


You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub:
#5751 (comment)

@jskeet
Copy link
Copy Markdown
Contributor

jskeet commented Mar 16, 2016

Is having the interface not removed by GA problematic for you (the interface is
marked as obsolete)?

Well, if it's in 1.0 then it needs to be in the whole of 1.x, as removing it would be a breaking change. Anything "obsolete on launch" feels odd to me - I would definitely be happier with it being gone by 1.0. Personally I'd prefer it to just be dropped immediately - especially as the later it gets, the more people will be generating code and thus see a breakage when it is removed.

@jtattermusch
Copy link
Copy Markdown
Contributor Author

Closing this as it is superseded by #5928.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants