2017-06-21 7 views
-2

「エクスポート」を以下のように構成するのは意味がありますか?それが十分に一般的であるか、推奨されているすべての練習であるかはわかりませんjavaパッケージ - 繰り返し名を扱う方法

org.mycompany.export.generic-export-utilities 
org.mycompany.productA.export.productA-specific-export-logic 
org.mycompany.productB.export.productB-specific-export-logic 
+0

「組織化」とは、あなたがアルファベット順に意味ですか?または、他の何か? –

+0

私は、同じ名前の "export"が上位に表示され、次に名前空間で下に表示されることを意味しました。技術的には問題ありませんが、設計から見通しが直感的ではありません。 – pranay

答えて

1

私はそれは良い質問だと思います。

あなたのパッケージを整理する良い方法は、コードを「ドメイン」で区切ることです。アプリケーションの文脈がなくても良いパッケージ構成を推薦するのは難しいです。しかし、私はあなたを助けようとします。

この例を参照してください。学生と顧客を管理するシステムがあります。整理するための良い方法:

org.mycompany.student 
org.mycompany.student.dto 
org.mycompany.student.service 
org.mycompany.customer.dto 
org.mycompany.customer.service 

悪い方法#1:

org.mycompany.dto.student 
org.mycompany.dto.customer 
org.mycompany.service.student 
org.mycompany.service.customer 

悪い方法#2:私たちはいくつかのパッケージ名の繰り返しを持っている。この2例で

org.mycompany.student.dto-student 
org.mycompany.student.service-student 
org.mycompany.customer.dto-customer 
org.mycompany.customer.service-customer 

だから、戻ってあなたの問題に、多分これはあなたに、より理にかなって:

org.mycompany.export.utils //I'm outside of the products subpackages, so this means that this is the place for generics utilities 
org.mycompany.productA.export //i'm already in the export inside the productA, this organization already show that the classes inside are specific for productA 
org.mycompany.productB.export //i'm already in the export inside the productB, this organization already show that the classes inside are specific for productB 
関連する問題