是否可以开设私人班级?

编程入门 行业动态 更新时间:2024-10-25 00:37:05
本文介绍了是否可以开设私人班级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我总是想知道是否可以开设私人课程?而且,上这样的课有什么意义呢?

I always wonder if it is possible to have a private class? And, what would be the point of having such class?

感谢您的帮助.

推荐答案

是的,可以有一个私有类,但只能作为另一个类的内部类:

Yes it is possible to have a private class, but only as an inner class of another class:

public class Outer { private class Inner {} }

当您想将某个逻辑封装在一个类(外部的)中,但是需要更结构化/OO设计的代码来实现它时,这通常很有用.过去,当我需要一个容器类来处理某个类的方法中的某些信息时,我就使用了这种模式,但是容器类在此逻辑之外没有任何意义.将容器类设为私有内部类意味着将其使用本地化为使用它的外部类.

This is usually useful when you want to encapsulate some logic inside of a class (the outer one), but need a more structured/OO design of code to implement it. I have used this pattern in the past when I need a container class to process some information within a method of a class, but the container class has no meaning outside of this logic. Making the container class a private inner class means that its use is localised to the outer class that utilises it.

值得注意的是,通过这种结构,内部类可以访问外部类的私有成员,但反之则不行.

It is worth noting that with this structure, the inner class has access to the private members of the outer class, but not the other way around.

更多推荐

是否可以开设私人班级?

本文发布于:2023-10-31 05:55:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545205.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:班级   私人

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!