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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:12:29+00:00 2026-06-14T14:12:29+00:00

I have the following objects: L1User , L2User , L3User (all inherits from User

  • 0

I have the following objects: L1User, L2User, L3User (all inherits from User) and Document.
Every user can create the document but depending on the user type, the document will have a different status. So in case it’s L1User, the document will be created with L1 status and so on:

enter image description here

Solution 1
Please note that after document is created, it will be saved in the database, so it should be natural to have a method create_document(User user) in Document object. In the method body I could check which type is the user and set manually appropriate status. Such approach seems rather not OOP to me.

Solution 2
Ok, so the next approach would be to have all users implement a common method (say create_document(Document doc)) which will set a status associated with the user and save the document in the database. My doubt here is that the document should be saved in it’s own class, not the user.

Solution 3
So the final approach would similar to the above, except that the user will return modified document object to it’s create_document(User user) method and save will be performed there. The definition of the method would be like this:

create_document(User user)
{
   this = user.create_document(this);
   this->save();
}  

It also doesn’t seems right to me…

Can anyone suggest a better approach?

  • 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-06-14T14:12:30+00:00Added an answer on June 14, 2026 at 2:12 pm

    I think that both Solutions 2 and 3 are ok from the OO point of view, since you are properly delegating the status assignment to the user object (contrary to solution 1, whare you are basically doing a switch based on the user type). Whether to choose 2 or 3 is more a matter of personal tastes.

    However, I have a doubt: why do you pass a document to a create_document() method? I would go for a message name that best describes what it does. For example, in solution 3 (the one I like the most) I would go for:

    Document>>create_document(User user)
    {
       this = user.create_document();
       this->save();
    }  
    

    and then

    L1User>>create_document()
    {
    return new Document('L1');
    }
    

    or

    Document>>create_document(User user)
    {
       this = new Document()
       this = user.set_document_type(this);
       this->save();
    }  
    

    and then

    L1User>>set_document_type(document)
    {
    document.setType('L1');
    }
    

    Edit: I kept thinking about this and there is actually a fourth solution. However the following approach works only if the status of a document doesn’t change through its lifetime and you can map the DB field with a getter instead of a property. Since the document already knows the user and the status depends on the user, you can just delegate:

    Document>>getStatus()
    {
       return this.user.getDocumentStatus();
    }  
    

    HTH

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

Sidebar

Related Questions

I have the following user resource: class UserResource(ModelResource): class Meta: queryset = User.objects.all() resource_name
I have the two following datepicker objects but I can't get what I want
I have the following 2 objects: User and DomainUser User.java: package com.domain; import java.io.Serializable;
I have the following class objects in Google App Engine's dadastore, I can see
Suppose I have the following two objects: first_name_relation = User.where(:first_name => 'Tobias') # ActiveRecord::Relation
I have the following objects: public class User { int Id { get; set;
I have following nested objects. I am using @Valid for validation in my controller.
I have the following objects: @JsonFilter(myFilter) public class Person { private Name name; private
I have the following objects. An IEnumerable <Agency > Agencies, which then contains BusinessUnits
I currently have the following objects persisting successfully: Person first name, etc. Exams title,

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.