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

  • SEARCH
  • Home
  • 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 1011045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:10:33+00:00 2026-05-16T09:10:33+00:00

I have a simple question (working with Java). I have two classes, one represents

  • 0

I have a simple question (working with Java). I have two classes, one represents a Document, a second represents a Word.

The Document class needs to know some info about the words that is kept in Word. My question is, what’s the best way to decouple the two classes? I have 2 options in mind:

  1. Have no connection between the classes, and each time I call a method in Document, I pass it an object of Word (so I have a third class with a main method that initiates
    both Document and Word).

  2. Declare a private object of Word inside Document.

One thing to note, I only have one object for Word and one for Document. I don’t create a new object for every new document or word. I store a list of the entire documents in Document, and a list pf the entire words in Word.

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-16T09:10:34+00:00Added an answer on May 16, 2026 at 9:10 am

    I don’t agree with your understanding of Decoupling. Decoupling is not just about which objects create other objects, it’s also about which objects know about the behaviour of other objects and (crucially) what needs to change in (your example) Document if Word changes.

    However, also I really don’t understand what your mean by these two phrases:

    I only have one object for Word and
    one for Document. I don’t create a new
    object for every new document or word.
    I store a list of the entire documents
    in Document, and a list pf the entire
    words in Word

    Start from Document. What can objects of this class do? You seem to be saying that

    class Document {
    
         private List<??OfWhat??> allDocuments;
    }
    

    If class Document contains a List, what’s it a List of? I think you need:

    class Shelf {
          private List<Document> allDocuments;
    }
    
    class Document{
          private List<Word> wordInOneDocument;
    }
    
    class Word {
          private String wordContents;
    }
    

    Now a Shelf could offer methods such as getRecentDocumets() findDocumentsContaining(String text)
    and Document could contain getWordCount() and insertParagraph(List, START); and so on.

    To have a better discussion we need to see a bit more of what you had in mind, a bit more about behaviour.

    I do agree with your general thought that there is Something other than Document and Word out there. Something that can reasonably invoke methods such as createDocument() and insertParagraph()

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

Sidebar

Related Questions

I have simple type Question : public class Question { public string[] Tags {
After finishing two cs classes, I've started working on a personal project in Java.
I have simple question. User supplies URL to my PHP script where I fetch
i have a simple question: i have this var: $v = 24000,1500,1500,1500,1500,1500,; i would
i have a simple question, there is a function with parameter emp_id that opens
I have a simple question: how exactly are array variables such as $_SESSION and
I have a simple question and that is how do you check if an
I have a simple question. I'm trying to get a list of the indicators
I have another simple question about Node. I'm trying to make a simple http
I have a simple question whose answer seems not to be in the official

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.