Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7521767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:19:25+00:00 2026-05-30T02:19:25+00:00

I never know how to correctly model situations when there’s this data structure that

  • 0

I never know how to correctly model situations when there’s this data structure that I’ll want to later save on disk.

For instance, I’m currently working on a small code-generator. The general idea is that I’ll somewhere want to store both a class’ qualified name as well as its related contents, and I’ll later want to save the .java file to disk and to compile it via javac. It’s not entirely clear that I’ll want to do both actions, that is, saving to disk as .java and compiling via javac as just one action. I guess sometimes I might want to just write the .java file to disk without compiling.

class CompilationUnit {
    String qualifiedName;
    String contents;
}

Now, my question is on how to model this. Should I have a CompilationUnit that takes as arguments both an IFileSystem and IJavaCompiler, so every time I have “in my hand” a CompilationUnit I have everything needed to do both actions, or should I try to keep that compilation logic outside of the class, being a CompilationUnit just a data object?

One one hand, there’s this OO belief one should keep both state and behaviour on the same object, which would favor keeping the qualified name and its contents together with the possibility of writing the compilation unit to disk and compile it.

Despite of that fact, I cannot but feel uncomfortable with the idea of having the CompilationUnit taking both IFileSystem and IJavaCompiler dependencies, although I it’s a bit hard to explain why it is so.

My (idealist?) intuition is that a data object should be easy to instantiate, and in that view it cannot but feel awkward to have to pass in a IFileSystem and IJavaCompiler every time I want to store a qualified name and its contents together. This means that whoever is in charge of generating this data has to also have access to both IFileSystem and IJavaCompiler, which is kind of odd.

I’m not sure I’ve actually answered my own question or not.

This system will be tested, so a correct handling of dependencies issues is paramount.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:19:26+00:00Added an answer on May 30, 2026 at 2:19 am

    If you inject Services into Entities or Value Objects, you are most likely breaking the Single Responsibility Principle. While I don’t know the details of this domain, IFileSystem and IJavaCompiler sounds a lot like Services to me – they’re not really part of the state of the object, but Services it can use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I do not currently have this issue , but you never know, and thought
Anyone know this? I've never been able to find an answer.
I know that #define s, etc. are normally never indented. Why? I'm working in
I know this is quite easy trigonomety, however I was never introducted to vectors
Does anyone know why this yaml is parsed and read correctly by my app
I have a std::vector that I know will never have to grow--it will always
I never really know what order is the best installation or if it even
I know the rule is to NEVER throw one during a destructor, and I
Does somebody know how to recover a never-starting eclipse when the error org.eclipse.swt.SWTError: Item
I know .Net and C# pretty well, but never even looked at VB. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.