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

Ask A Question

Stats

  • Questions 518k
  • Answers 518k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer using (SqlConnection conn = new SqlConnection("connection string goes here")) using… May 16, 2026 at 8:06 pm
  • Editorial Team
    Editorial Team added an answer When you create through virtualenv python3.0 It creates a symlink… May 16, 2026 at 8:06 pm
  • Editorial Team
    Editorial Team added an answer In this case, it's probably because you are using the… May 16, 2026 at 8:06 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm writing two classes to handle simple auctions. I have a class ready and
After finishing two cs classes, I've started working on a personal project in Java.
I have a Java application I've been working on for a year or two
What I have here real simple activity with two buttons. When you press each
I have been working for two years in software industry. Some things that have
Good evening everyone! I am working on learning some java and I have made
I have a problem with a makefile. I have three classes. They do pretty
I am using xjc to generate Java classes from the XML schema and the
I have created a rather complicated piece of (Java) code for a game I
I'm currently working on a small 2D game-engine in C++, but I am now

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.