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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:57:28+00:00 2026-05-23T01:57:28+00:00

We have been arguing back and forth at my work place about the use

  • 0

We have been arguing back and forth at my work place about the use of the Observer pattern for one of the problems. I somehow smell “overuse” but am open to ideas. So the requirement is

We have a hierarchy of objects -> an order and multiple line items in the order. When the order is cancelled, all the line items need to cancelled.

To do this, we have created a OrderCancel class which is the Subject in the Observer pattern idiom and LineItemCancel class which is the Observer. We also have a OrderManager class with a cancelOrders(List orders) method which instantiates the OrderCancel and the corresponding LineItemCancel objects and then registers them all in the OrderCancel. The code is as follows.

public class OrderManager {
    public void cancelOrders(List<Order> orders){
        for(Order order :orders){
            OrderCancel orderCancel = new OrderCancel(order);
            Listener listener = new LineItemCancel(order);
            orderCancel.addListeners(listener);
            orderCancel.cancel();
        }
    }
}

public class OrderCancel implements Subject {
    private List<Listener> listeners = new ArrayList<Listener>();
    private Order order;

    public OrderCancel(Order order) {
        this.order = order;
    }

    @Override
    public void addListeners(Listener listener) {
        listeners.add(listener);
    }

    @Override
    public void notifyListeners() {
        for(Listener listener : listeners){
            listener.update();
        }
    }

    public void cancel() {
        notifyListeners();
        cancelOrder();
    }

    private void cancelOrder() {
    }
}

public class LineItemCancel implements Listener {

    private Order order;

    public LineItemCancel(Order order) {
        this.order = order;
    }

    @Override
    public void update() {
        cancelLineItem();
    }

    private void cancelLineItem() {
    }
}

I am convinced this is improper usage. But I am not able to convince the designers of this class. I am trying to figure out myself if this is right as the designer is one of the architects at work.

Looking forward to hear your thoughts.

  • 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-23T01:57:29+00:00Added an answer on May 23, 2026 at 1:57 am

    The Observer pattern is only useful when it reduces coupling. I don’t see any reduction of coupling in this example so I would say it is overuse.

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

Sidebar

Related Questions

I have been working on a web services related project for about the last
I have been looking into IKVMing Apache's FOP project to use with our .NET
Have been playing around with linq but there is one thing I cant seem
Have been struggling all day trying to make this simple example work using socket.io.
I have been trying to get this to work. Basically I have a search
Have been scatching my head about this - and I reckon it's simple but
Have been wondering about this for days now: I have a basic wxpython program
Have been trying to find the error in one line of code. Return expected
I have been learning how to use the Python multiprocessing module recently, and reading
Have been looking at the MVC storefront and see that IQueryable is returned from

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.