Redian新闻
>
其实有很多概念都是误导性的
avatar
其实有很多概念都是误导性的# Java - 爪哇娇娃
z*3
1
举个例子
比如oo,oo讲究你要把现实中的所有的实体全部包装成对象
这个是没错
但是j2ee并不是完全的oo
或者这么说,它的oo,是建立在某些并不是你想的那种情况基础之上的
比如你这么理解oo,现实中的每一个人
你要写程序建立一个object去映射它
然后这个人应该要有自己的思想吧?
要有行为吧?这没错
那既然如此,那这个对象的行为是不是它的方法啊?
对啊,是啊
但是你这么做j2ee你就等死吧
没有人这么做
因为当你把对象行为封装到对象本身中去的时候
你就在创造一个controller
而controller是要集中管理的
如果打散到各个实体中去的话
是错误的
所以要想理解j2ee,要先理解mvc
j2ee三个层面分别代表着mvc的三个部分
web就是viewer
db就是model
中间就是controller
但是mvc也有自己的问题
最典型的就是当你要建立ai的时候
理论上应该是单独跑一个线程吧?
比如游戏中一个角色,你要封装它,那应该至少单独给它跑一个ai的thread吧?
然后这个thread跟其他的m也就是游戏的model做通信
对吧?
但是这个是错误的,错误的主要原因是并发的操作的问题
各种狗血,所以swing是单线程的,尼玛
实际上大多数时候,controller都是假的面向对象
controller是面向上帝
什么意思呢?也就是假设这个世界的一切都是上帝在背后操纵
而具体的每一个生命是没有自己思想的
所以每一个实体只需要对上帝负责就是了
然后由上帝来集中控制所有的行为
用这种方式来设计代码
可以解释几乎所有的程序
所以软件工程的程序里面每一个实体是没有思想的
可以认为不是真正意义上的面向对象
如果你用这种方式去思考j2ee,那么就很容易理解aspectj和spring的aop了
也就是面向切面的编程
这是一个很好的对于jar的补充
尤其是当你手头上需要用到同一个jar的不同版本的时候
avatar
z*3
2
当然我的意思不是说oo没用
是oo的出现是某一个历史阶段的产物
不经过这个历史阶段
后面的事情没有办法去做
但是你不能把思想停留在那个阶段
就像c的出现是一个必然
没有c就没有java
但是有了java之后,很多东西就可以不用c去写了
就这么简单的一个道理
唯一的问题就在于,很多人总是盲目地否定历史的趋势
就像当年c跟汇编,后来的java和c++之争一样
要说还有用很容易,要说一个东西不行了
那需要勇气,因为哪怕你说得再对,都会有人否定你
avatar
p*2
3
说的很好。学习了。
avatar
b*e
4
所以现在大多数基于Spring 的项目都是Anemic Design Pattern, 很少能做到Domain
Driven Design 。
avatar
l*G
5
OO 的另外一个大问题是 程序hierarchy 太多,引用变量时需要用 objectname.
varname ,很容易把人搞得晕头转向。
读程序的时候,人的眼睛首先扫过objectname 然后才看到varname,这个过程一点也不
自然。人们更习惯于先看到varname然后马上知道变量是干什么用的了。如同我们平时
更多用First name称呼别人。这个对于数学物理来说是disaster,没有人用object.
velocity 表示物体的速度,而是直接用v_m 简单明了。我建议以后变量和object引用
的时候反过来!比如说Varname<--objectname
avatar
g*g
6
I can't agree with your approach. The relevant characteristics of OOP here
is encapsulation. Encapsulation means the class maintains some states, and
define some behaviors to operate on these states, it doesn't have
intelligence, that's not part of OOP.
J2EE deals with complicate problem. And it typically has layered structure.
Most complicate systems in the world are using a service-oriented
architecture. But that still doesn't deviate from what OO is about. Every
single service maintains states, and defines what behaviors can be applied
to these states. The presentation layer, or the client, is the consumer of
these services. The service layer can be loosely coupled, it's not unusually
to see a service call going to 10 different services that run on different
JVM and aggregate the data. It doesn't have to be centralized as you say.
And the persistence layer, is just a layer that helps service layer to
decouple from specific storage implementation.
J2EE is very OO. AOP is just a way to abstract some common code in this
practice.
e.g. logging, exception handling. It's like saying we have 10 services that
needs to be audited in the same way. Let's abstract the auditing code
without explicitly making the code
intrusive. It's done by the magic of dynamically creating a proxy object to
the service and it's a clean approach. But when you look at the execution
path, it's no different from making the call every time you need it.
avatar
F*n
7
OO is an abstraction tool by design and encapsulation tool by implementation
. It's engineering, not science.

.
of
unusually

【在 g*****g 的大作中提到】
: I can't agree with your approach. The relevant characteristics of OOP here
: is encapsulation. Encapsulation means the class maintains some states, and
: define some behaviors to operate on these states, it doesn't have
: intelligence, that's not part of OOP.
: J2EE deals with complicate problem. And it typically has layered structure.
: Most complicate systems in the world are using a service-oriented
: architecture. But that still doesn't deviate from what OO is about. Every
: single service maintains states, and defines what behaviors can be applied
: to these states. The presentation layer, or the client, is the consumer of
: these services. The service layer can be loosely coupled, it's not unusually

avatar
c*e
8
恩,面向整个对象非常不方便,现在的ajax,就是只更新网页的一部分,而不是全部。
web services里面的dto,你可以只选择你想处理的那几个properties。很多时候,只是
改变一个instance里的某个property,而不是整个instance. spring比ejb简单。

【在 z*******3 的大作中提到】
: 举个例子
: 比如oo,oo讲究你要把现实中的所有的实体全部包装成对象
: 这个是没错
: 但是j2ee并不是完全的oo
: 或者这么说,它的oo,是建立在某些并不是你想的那种情况基础之上的
: 比如你这么理解oo,现实中的每一个人
: 你要写程序建立一个object去映射它
: 然后这个人应该要有自己的思想吧?
: 要有行为吧?这没错
: 那既然如此,那这个对象的行为是不是它的方法啊?

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。