首页 \ 问答 \ java 接口

java 接口

java接口是这样定义的,,接口是一个特殊的抽象类,定义一系列的方法但是没有方法的实现,,方法的实现放的接口的实现中,,,,请问:为什么要这样啊, 要什么好处啊,,(有例子最好) 每次在使用接口的时候都要进行接口的一 一实现感觉很麻烦啊,但是又说接口是java必不可少的,实现多继承的,,,,,,晕了,,,
更新时间:2022-10-23 11:10

最满意答案

你说的是单例模式阿
public class GlobalConfig {   
     private static GlobalConfig instance = null;   
     private Vector properties = null;   
     private GlobalConfig() {      //Load configuration information from DB or file      //Set values for properties    }    
public static GlobalConfig getInstance() {      i
f (instance == null) {       
 instance = new GlobalConfig();    
  }    
  return instance;   
 }   
 public Vector getProperties() {      return properties;    }  }

其他回答

单列模式的构造方法是private的,也就是私有的,通过在这个单列里另外写一个public 方法来生成这个单利的实例,以供外部调用

相关问答

更多
  • 建议你看一下大话设计模式这本书,不错的
  • 你说的是单例模式阿 public class GlobalConfig { private static GlobalConfig instance = null; private Vector properties = null; private GlobalConfig() { //Load configuration information from DB or file //Set values for properties } public static GlobalConfig getInsta ...
  • 一些小职责可以用内部类,static class A{} ,源文件不须太多 设计也是对已经存在的问题进行分类,而不在抽象上做不实际的细分吧.. 至于类多,可以参考一派的观点OOP是有残疾的,纯OO经常导致画蛇添足...代码量翻倍 退回到过程和对象混用...尽量少分类,多用函数式纯函数, 现在的python就持这类理念
  • 在嵌入式模式下,Neo4J可以在另一个不是独立的Neo4J的应用程序中调用或运行。 例如,如果你有一个Python / Django应用程序,你可以“嵌入”Neo4J,但需要调用Neo4J库。 在单服务器模式下,Neo4J及其应用程序可以单独工作,例如推荐系统或异常检测。 在这种情况下,Neo4J可能不依赖于其他应用程序。 In the Embedded mode, Neo4J can be invoked or run in another application which is not standal ...
  • 一个静态成员(作为单例)在给定的应用程序中将是唯一的。 但是由于BlackBerry Java实现“特别”(至少可以说),对于每个备用入口点,您将拥有不同的“应用程序实例”,因此将创建多个单例实例。 如果您想在多个应用程序之间的运行时共享一个对象,则必须将其发布到RuntimeStore 。 如果您还需要持久性,那么在较新的操作系统中使用PersistentStore或纯文件或sqlite数据库。 现在关于模拟器: 不要相信模拟器 。 一旦你关闭你的应用程序,你的变量就会消失。 即使您有后台进程,当您关闭设 ...
  • 在O(n)中完成,而不是O(n ^ 2)。 需要长度> 0的数组。 public static int getMode(int[] values) { HashMap freqs = new HashMap(); for (int val : values) { Integer freq = freqs.get(val); freqs.put(val, (freq == null ? 1 : freq+1)); ...
  • SureLock iOS应用程序不执行任何操作,只是告知用户如何在系统首选项中执行此操作。 如果您违反有关私有框架的规则,则只能从应用程序本身执行此操作。 并且努力打破它。 我很遗憾地告诉您,您提出想法的方式永远不会被批准用于AppStore。 The SureLock iOS app does nothing but inform the user how to do it in your system preferences. Doing it from the app itself is only p ...
  • 您只能通过Model_Acl :: getinstance()初始化它。 但是,它会起作用。 单身人士不被认为是一种好习惯,你应该考虑依赖注射。 http://fabien.potencier.org/article/11/what-is-dependency-injection 。 有关php Singletons的更多信息 PHP单例类的最佳实践 You can only initialize it thru Model_Acl::getinstance(). But yes, it will work ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。