开发者

Understanding this architecture

I have inherited a massive system from my predecessor and I am beginning to understand how it works but I cant fathom why.

It's in java and uses interfaces which, should add an extra layer, but they add 5 or 6.

Here's how it goes when the user interface button is pressed and that calls a function which looks like this

foo.create(stuff...)
{
    bar.create;
}

bar.create is exactly the same except it calls foobar.creat and that in turn calls barfoo.create. this goes on through 9 classes before it finds a function that accessed the database.

as far as I know each extra function call incurs more performance cost so this seems stupid to me.

also in the foo.create all the variables are error checked, this makes sense but in every other call the error checks happen again, it looks lik开发者_如何学运维e cut and paste code. This seems like madness as once the variables are checked once they should not need to be re checked as this is just wastinh processor cycles in my opinion.

This is my first project using java and interfaces so im just confused as to whats going on.

can anyone explain why the system was designed like this, what benefits/drawbacks it has and what I can do to improve it if it is bad ?

Thank you.


I suggest you look at design patterns, and see if they are being used in the project. Search for words like factory and abstract factory initially. Only then will the intentions of the previous developer be understood correctly.

Also, in general, unless you are running on a resource constrained device, don't worry about the cost of an extra call or level of indirection. If it helps your design, makes it easier to understand or open to extension, then the extra calls are worth making.

However, if there is copy-paste in the code, then that is not a good sign, and the developer probably did not know what he was doing.


It is very hard to understand what exactly is done in your software. Maybe it even makes sense. But I've seen couple of projects done by some "design pattern maniacs". It looked like they wanted to demonstrate their knowledge of all sorts of delegates, indirections, etc. Maybe it is your case.


I cannot comment on the architecture without carefully examining it, but generally speaking separation of services across different layers is a good idea. That way if you change implementation of one service, other service remains unchanged. However this will be true only if there is loose coupling between different layers.

In addition, it is generally the norm that each service handles exceptions that specifically pertains to the kind of service it provides leaving the rest to others. This also allows us to reduce the coupling between service layers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜