[macker-user] factory pattern violation recognition
Brought to you by:
barredijkstra,
melquiades
From: Alex G. <ale...@gm...> - 2006-03-21 08:30:10
|
Hi, first of all, thanks for "macker"! We use it and it hels a lot! now to my question: beside checking architecture layer violations we want to use macker to check factory pattern violations. In out persistence layer we want that everybody gets a dao instance through the DAOFactory and nobody should create a new DAO Instance with "new". In other words, inside a dao class it is allowed to access the DAOFactory and dao interfaces but not to instanciate and directly access dao classes. beneath is my rule declaration. I made these patterns: - dao classes - daoFactory - dao interfaces Then I prohibit to access dao classes and exclude the factory and the interfaces. My problem is that dao classes which are "OK", and follow the rules are still reported from macker. I disassambled the class file of this "fine" dao, and saw that there is still an import statement, that imports the other dao. Does that mean that the line OtherDAO otherdao =3D DAOFactory.getInstance().getOtherDAO(); has the class declaration of OtherDAO in the constant pool, so that macker reports it as a violation? Is there a way to check this factory pattern violation with macker? thanks, ALex =09<pattern name=3D"pt_server_persistenz_dao_class"> =09=09<include class=3D"${star_server_persistenz}.dao.**.DAO*" /> =09=09<exclude class=3D"${star_server_persistenz}.dao.DAOFactory" /> =09</pattern> =09<pattern name=3D"pt_server_persistenz_daoFactory" class=3D"${star_server_persistenz}.dao.DAOFactory" /> =09<pattern name=3D"pt_server_persistenz_dao_ifc" class=3D"${star_server_persistenz}.dao.*Interface" /> <access-rule> =09<message>DAOs d=FCrfen DAOs nicht direkt aufrufen, sondern nur =FCber DAOFactory</message> <deny> =09<from pattern=3D"pt_server_persistenz_dao_class"/> =09<to> =09=09<include pattern=3D"pt_server_persistenz_dao_class"/> =09=09<exclude pattern=3D"pt_server_persistenz_daoFactory"/> =09=09<exclude pattern=3D"pt_server_persistenz_dao_ifc"/> </to> </deny> </access-rule> |