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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:38:22+00:00 2026-05-23T16:38:22+00:00

Aggregation is a whole/part relationship. If whole does not exist no longer, but part

  • 0

Aggregation is a whole/part relationship. If whole does not exist no longer, but part will still exist

But in composition If whole does not exist no longer, but part will no longer exist

For example, a university owns various departments (e.g., chemistry), and each department has a number of professors. If the university closes, the departments will no longer exist, but the professors in those departments will continue to exist. Therefore, a University can be seen as a composition of departments, whereas departments have an aggregation of professors.

My question here how we will actually define the class definition of University,Department and Professors in java which also depicts above aggregation and composition behavior?

  • 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-23T16:38:22+00:00Added an answer on May 23, 2026 at 4:38 pm

    The concepts of composition and aggregation are displayed with arrows with diamonds in UML, but when those concepts are implemented in a programming language, may change from one programing language to another.

    Generally speaking, in programming languages, like Java, C# or Delphi, both cases are represented by object references. Each object has a “life cycle” (“created”, “do stuff”, “destroyed”).

    package Universities;
    
    class ProfessorClass {
      string FirstName;
      string LastName;
    
      // constructor
      public ProfessorClass(string AFirstName, string ALastName) {
        FirstName = AFirstName;
        LastName = ALastName;
      } 
    } // class ProfessorClass
    
    class DepartmentClass {
      string Name;
      string Description;
    
      // constructor
      public DepartmentClass(string AName, string ADescription) {
        Name = AName;
        Description = ADescription;
      } 
    } // class DepartmentClass
    
    class UniversityClass {
      // here doesn't look different:
    
      // aggregation
      ProfessorClass[] Professors;
      // composition
      DepartmentsClass[] Departments;
    
      // constructor
      public UniversityClass() {
        // "UniversityClass" is in charge of creating parts
    
        // here doesn't look different:
    
        DepartmentsClass = new DepartmentsClass[]();
    
        ProfessorClass = new ProfessorClass[]();
      } 
    
      public addDepartment(string AName, string ADescription)
      {
      // composition, whole class is in charge of adding parts:
        DepartmentClass Dept = new DepartmentClass(AName, ADescription);
        DepartmentsClass.add(Dept);
      }
    
      public deleteDepartment(string AName)
      {
      // composition, whole class is in charge of deleting parts:
        DepartmentsClass.delete(AName);
      }
    
      public addProfessor(ProfessorClass AProfessor)
      {
        // aggregation, whole class only reference other objects,
        // but, may look like they where parts
        ProfessorClass.add(AProfessor);
      }
    
      public static void main(String[] args) {
        UniversityClass MyUniversity = new UniversityClass();
    
        // composition, internal, maintained by main class
        MyUniversity.addDepartment("History", "Very Boring");
        MyUniversity.addDepartment("Music", "Only if you like it");
        MyUniversity.addDepartment("Astronomy", "night living people");
    
        // aggregation, external, referenced by main class,
        // maintained independently
        ProfessorClass Professor1 = new ProfessorClass("Jane", "Doe");
        ProfessorClass Professor2 = new ProfessorClass("Mike", "Smith");
        ProfessorClass Professor3 = new ProfessorClass("Louise", "Kent");
    
        MyUniversity.addProfessor(Professor1);
        MyUniversity.addProfessor(Professor2);
        MyUniversity.addProfessor(Professor3);  
      } // static void main(...)
    
    } // class UniversityClass
    

    In composition, “whole” objects that are composed by other objects (“parts”), are in charge of creating, using & destroying its parts. The “whole” object its responsible for the “life cycle” of each of its “parts”.

    In aggregation, “whole” objects that reference other objects (“aggregation”), that may look similar to “parts” (composition), usually, are not created or destroyed by the main object, just assigned or deassigned. The main object doesn’t control directly the other objects, just add or remove references.

    There are some times you may pick code alredy done from other developers, and may see both ideas, mixup, and cannot difference which concept is been used.

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

Sidebar

Related Questions

What is the difference between composition and aggregation? can anybody give me a sample
i came across this definition Aggregation has two properties: antisymmetry, transitivity What does it
The new aggregation framework will come with the 2.2 version. They made some presentations
I know about Association and Aggregation and Composition and Generalization what they are by
I've created a MongoDB aggregation query that will give me the sum of data
I have an aggregation project with a half-dozen submodules. The builds all work but
Does MEF has Event Aggregation like feature builtin (I don't want Prism etc)
I'm asking and answering my own question , but i'm not assuming i have
Let's imagine app which is not just another way to post tweets, but something
Given an aggregation of class instances which refer to each other in a complex,

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.