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 7626415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:19:19+00:00 2026-05-31T05:19:19+00:00

Problem Description I have an abstract Paper class that contains common properties of all

  • 0

Problem Description

I have an abstract Paper class that contains common properties of all papers and one or more child classes of paper that add additional information for that type of paper. I then have a HashMap<String, Paper> to store multiple papers.

My application allows the user to update a paper by providing a the pid and then supplying the attributes and values to update. The issue I am having is how do I update the properties on the sub classes when all I have is the super class.

What is the best way/practice to handle this situation?

Class Structure

public abstract class Paper {
    String pid;
    String title;
    String author;
}


public class Publication extends Paper {
    int pages;
}

public class PHDThesis extends Paper {
    String supervisor;
}

My Current Attempt

This is what I currently have** and it works by using instance of; but I feel there should be a better way to do this.

import java.util.*;

public class App {
    public static abstract class Paper {

        private String title;
        private String author;

        public Paper(String title, String author) {
            this.title = title;
            this.author = author;
        }

        public void update(String title, String author) {
            this.title = title;
            this.author = author;
        }
    }


    public static class Publication extends Paper {

        private int pages;

        public Publication(int pages, String title, String author) {
            super(title, author);
            this.pages = pages;
        }

        public void update(String title, String author, int pages) {
            super.update(title, author);
            this.pages = pages;
        }

    }

    public static class PHDThesis extends Paper {

        private String supervisor;

        public PHDThesis(String supervisor, String title, String author) {
            super(title, author);
            this.supervisor = supervisor;
        }

        public void update(String title, String author, String supervisor) {
            super.update(title, author);
            this.supervisor = supervisor;
        }
    }

    public static void main(String[] args) {
        HashMap<String, Paper> papers = new HashMap<String, Paper>();

        papers.put("P001", new PHDThesis("My Super", "My PHD Title", "My Author"));
        papers.put("P002", new Publication(22, "My Pub Title", "My Author"));

        Paper p = papers.get("P001");

        if (p instanceof PHDThesis) {
            ((PHDThesis)p).update("New Title", "New author", "New Super");
        } else if (p instanceof Publication) {
            ((Publication)p).update("New Title", "New author", 33);
        }
    }
}

** reduced test code, actual code is much more complex and better laid out.

  • 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-31T05:19:20+00:00Added an answer on May 31, 2026 at 5:19 am

    You can create an object called UpdateBundle with getters for each attribute.

    Then the Paper class will have a method update(UpdateBundle) which each child will implement differently.

    All you have to do is call that method for each child and they will know how to handle it.

    On a separate note, i don’t see why the paper class is abstract. You seem to have no abstract methods in it.

    public abstract class Paper {
        String pid;
        String title;
        String author;
    
        public void update(PaperUpdateBundle bundle)
        {
            pid = bundle.getPID();
            title = budnle.getTitle();
            author = bundle.getAuthor();
        }
    }
    
    
    public class Publication extends Paper {
        int pages;
    
        public void update(PaperUpdateBundle bundle)
        {
           super.update(bundle);
           pages = bundle.getPages();
        }
    }
    
    public class PHDThesis {
        String supervisor;
    
    
        public void update(PaperUpdateBundle bundle)
        {
           super.update(bundle);
           supervisor = bundle.getSupervisor();
        }
    }
    
    public interface PaperUpdateBundle
    {
        String getPID();
        String getTitle();
        String getAuthor();
        int getPages();
        String getSupervisor();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem description I have 6 databases from 6 different machines, and having one cloud
I have an abstract class Employee , and based on that, I created the
I have a model called PageMetaData that contains a title and a description .
This is my homework, but please read my problem description first. I have to
Description: I have a problem regarding DataGridView . I need to show a Client_Name
I have a problem with the query below in postgres SELECT u.username,l.description,l.ip,SUBSTRING(l.createdate,0,11) as createdate,l.action
I have a homework problem here I've been working on; here is the description:
I have a product table where the description column is fulltext indexed. The problem
Problem Description: We have a service which has applications for main mobile OS’s. We
I have a homework problem where I have to make an inheritance program that

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.