design - Is every cyclic references between Java packages bad? -


i've been using sonar code quality management platform time, , cases find helpful in revealing hidden design flaws of code base.

however, there's 1 rule gives me more annoyance , check 'cyclic package reference' violations.

i guess understand such depedency between pacakges bad thing. example, in typical 3-tier presentation/service/persistence layered design, it's bad idea let database handling code have reference ui related classes. have no problem calling 'violation'.

but let's consider other cases, i.e. designing ide application. say, have main package contains application interface, defines list application.getviews() method reference application's views.

however, when view interface has application getapplication() method refer parent application, believe quite common design, introduce cyclic reference, provided each of interfaces separated in com.myapp.ui, , com.myapp.ui.view respectively.

of course, can put view interface com.myapp.ui break cycle. when have various other view related apis in com.myapp.ui.view, many of them abstract apis abstractview, contentview, abstractcontentview, etc, wonder if it's more advisable keep them in separate packages management purpose.

and consider said application has many other similar cases com.myapp.ui.action, com.myapp.ui.perspective, etc, make com.myapp.ui pacakge crowded if put them in there.

so, approach suggest handle such situation? every cyclic package references bad thing? or if have live them, how configure sonar check real, problematic cycles?

thanks!

every absolute -- except 1 ;) -- going wrong of time. so, every cyclic reference bad? no. have use judgement.

but if introduce cyclic dependency, it's worth asking if need it, , why. tl;dr more not, may find breaking cycle can improve modularity, , in particular ability test components separately.

to use example, view need getapplication(), presumably returns relatively "heavy" object (ie, 1 needs database, network, etc etc)? maybe... maybe not. if need getapplication few callbacks (such when user initiates action), useful create interface in common package callback. so, rather than:

com.foo.app.application com.foo.view.view     application getapplication() 

you'd have:

com.foo.common.callback // maybe callable, runnable, etc? com.foo.app.application     provides callback action foo com.foo.view.view     callback getfoocallback() 

the question should asking is: give me? have stub out doesn't give -- though may suggest can break apart classes some. makes easier test view, because unit test can (1) test view without spinning whole application, , (b) provide "dummy" callback saving string describes action, , unit test asserts saved right string.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -