继承或封装或委派?我应该学习什么来理解下面的代码? [英] Inheritance or encapsulation or delegation ? what should I learn to understand the below code?

查看:67
本文介绍了继承或封装或委派?我应该学习什么来理解下面的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下面的方式编写代码有什么好处:或者我应该学习什么来理解它?给我一些教程plz的链接。 thx)))



What`s the benefit of writing the code in a way below: or what should i learn to understand it? give me some link to some tutorials plz. thx)))

class ClassOne implements SomeInterface {
   ClassTwo  ct = new ClassTwo ();
   public boolean someMethod(){
         return ct.someMethod();
   }

    public static void main(String[] args) {
    }
}


interface SomeInterface {
	boolean someMethod();
}


class ClassTwo implements SomeInterface {
	public boolean someMethod()	{
	    return true;
	}
}





我的尝试:



了解委托继承封装



What I have tried:

read about delegation inheritance encapsulation

推荐答案

好吧,为了理解上面代码中发生了什么,只需花一些钱关于OOP基础知识的时间,或者如果你有一些背景知识并且仍然无法掌握它,我建议你得到Kathy Sierra的SCJP完整指南,最好是获得java se 8。但是,如果你不愿意花钱来获取它,请参阅java se 6 https://iamgodsom.files.wordpress.com/2014/08/scjp-sun-certified-programmer-对于-Java的6-0071591060.pdf PDF格式。

花一些时间正确阅读它,你的大部分怀疑都会在1或2次读数后被清除。

希望这会有所帮助。
Well, in order to understand as to what's happening in the above code just spend some time on the basics of OOP first or if you have a bit of background of it and are still not able to grasp it then, I'd recommend that you get Kathy Sierra's SCJP complete guide the best would be to get of java se 8. But if you're not willing to spend to get it here's a reference for java se 6 https://iamgodsom.files.wordpress.com/2014/08/scjp-sun-certified-programmer-for-java-6-0071591060.pdfpdf.
Spend some time reading it properly and most of your doubts would get cleared after 1 or 2 readings.
Hope this helps.


上面的代码显示了你提到的所有概念。

你必须掌握 OOP 原则和 Java 编程语言以了解代码。
The above code shows all the concepts you mentioned.
You have to grasp both the OOP principles and the Java programming language in order to understand the code.


转到 Java™教程 [ ^ ],其中清楚地解释了所有这些概念。
Go to The Java™ Tutorials[^], where all these concepts are clearly explained.


这篇关于继承或封装或委派?我应该学习什么来理解下面的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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