一种在java中实现部分类的方法 [英] A way to implement partial classes in java

查看:110
本文介绍了一种在java中实现部分类的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个界面,我想在快速谷歌搜索后在不同的类中实现,显然,
Java没有部分类。有没有办法可以做到这一点,还是我把所有代码都扔进了一个类?

I have an interface that I want to implement in separate classes after doing a quick google search apparently, Java doesn't have partial classes. Is there a way that I can do this or am I stuck throwing all of my code into one class?

基本上,我正在尝试编写服务。
有些服务方法确实属于他们自己的类,在同一个类中看起来有点不合逻辑。这是我想要做的一个例子。

Basically, I am trying to write a service. Some of the service methods really belong in their own class and seem kind of illogical in the same class. Here is an example of what I am trying to do.

package com.upmc.esdm.messaging.epcd.service;
import java.util.List;

import javax.ejb.Remote;

import com.upmc.esdm.messaging.epcd13jpa.entities.EmailDomainTrust;


@Remote
public interface MessagingInterfaceRemote {
public List<EmailDomainTrust> getEmailDomains();

    public int upDateQualityTable();

    public string isLogial();

    public byte[] ToWritePartialClassesInJava();
}

我通常会在C#中使用部分类,我会使用类似的方法返回类似的值分成一个部分类(或者更新一个类中的记录的类)。我该如何实现?或者我应该将所有方法实现放在一个类中?

I would normally have partial classes in C# and I would put similar methods that return similar values into one partial class (or maybe classes that update a record in one class). How would I implement this? Or should I just put all the method implementations into one class?

谢谢。

推荐答案

Java中没有类似于部分类的东西。您可以使用聚合,委派和抽象基类来实现许多相同的好处。

There is nothing like partial classes in Java. You can achieve many of the same benefits using aggregation, delegation, and abstract base classes.

(我已经屈服于同伴压力并消除了谢天谢地;在评论中产生了如此多的热量的评论。显然,尽管与答案无关,但小的旁边似乎已经为我赢得了四次投票。)

这篇关于一种在java中实现部分类的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆