Grouping classes by subject or dependencies?

Our project consists of user application and server application. The server application prepares data files that the user application consumes. Because the data is huge, it is stored in custom format. So the project includes many classes related to reading and writing the data. The user application does not need the writing side, so we don’t want to have the code there both because it might run on resource-limited devices and because it prolongs compilation (C++ is not known for having fast compilers).

So say I have two classes (I have tens of such pairs):

  • DataReader
  • DataWriter

These classes both operate on the same thing, the serialized data. But the first is only needed in the user application and the second is only needed in the server application. Would you suggest keeping such classes

  • Together; in say
    • common/data/DataReader
    • common/data/DataWriter
  • Separate like
    • userapp/data/DataReader
    • serverapp/data/DataWriter

With this goes the compilation. The common stuff lives in common and is compiled into a library linked to both. So the first option further splits into two:

  • Together in common/data and linked to common.a or
  • Together in common/data directory, but each linked to the target that needs it.

Now each has it’s advantages and disadvantages:

  • They are closely related, so it makes sense to keep them together. But
    • having both in one library makes that library larger and compile longer
    • compiling each separately means directory layout does not correspond to project layout, which is rather confusing and complicates the build scripts
  • Keeping them separate makes the build structure more logical and avoids unnecessary work for the compiler, but when updating them, components far apart need to be modified (both applications are maintained by the same team, so it’s not like someone wouldn’t be aware of the other part)

We currently have mixture between the approaches (some classes are separate, others not and the common library contains a lot of stuff that should be in the individual projects), which I would like to clean up.

Is there any usual recommendation for such situation? Or some useful experience with similar cases?

Keep them together: any format changes will require editing them together, and unit testing the format is easiest done using your existing reader & writer code together.

However, just because the source files are stored together, doesn’t mean they have to compile compile together. You could set it up so that (UNIX filename conventions for illustration only):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>userapp depends on libreader.a depends on DataReader.o
</code>
<code>userapp depends on libreader.a depends on DataReader.o </code>
userapp depends on libreader.a depends on DataReader.o

while

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>serverapp depends on libwriter.a depends on DataWriter.o
</code>
<code>serverapp depends on libwriter.a depends on DataWriter.o </code>
serverapp depends on libwriter.a depends on DataWriter.o

and then there’s no reason to build libwriter at all when you’re only compiling the client.

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật