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

  • Home
  • SEARCH
  • 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 9051909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:01:50+00:00 2026-06-16T13:01:50+00:00

I’m currently studying the Observer pattern and I’ve come across some confusion. When I

  • 0

I’m currently studying the Observer pattern and I’ve come across some confusion.

When I read this line of code:

IObserverSubscribe user1= new ConcreteObserverYoutubeUser();

I think the interface IObserverSubscribe user1 is creating and instantiating new ConcreteObserverYoutubeUser(). That is a little confusing to me because usually the same class that is being declared is also instantiating. Should it be like this:

IObserverSubscribe user1= new IObserverSubscribe();

Why is the interface decoration able to instantiate a another class?

Full code below:

Main:

package observerpattern;

public class ObserverPattern {

    /**
     * The observer pattern is a software design pattern in which
     *  an object, called the subject, maintains a list of its dependents,
     *  called observers, and notifies them automatically of any 
     *  state changes, usually by calling one of their methods.
     *  It is mainly used to implement distributed event handling systems.
     *  The Observer pattern is also a key part in the familiar
     *  Model View Controller (MVC) architectural pattern. 
     */
    public static void main(String[] args) {

        SubjectYouTubeChannel sytc= new SubjectYouTubeChannel();// create youtube channel
        IObserverSubscribe user1= new ConcreteObserverYoutubeUser();
        IObserverSubscribe user2= new ConcreteObserverYoutubeUser();
        IObserverSubscribe moderator1= new ConcreteObserverYoutubeModerator();

        sytc.Subscribe(user1);
        sytc.Subscribe(user2);
        sytc.Subscribe(moderator1);
        sytc.Unsubscribe(user2);

        sytc.notifySubscribers();


    }

}

subject:

package observerpattern;

import java.util.ArrayList;
import java.util.List;
import observerpattern.IObserverSubscribe;

public class SubjectYouTubeChannel {    
    private List<IObserverSubscribe> subscribers = new ArrayList<IObserverSubscribe>(); 
    public void Subscribe(IObserverSubscribe ios){
        subscribers.add(ios);       
    }   
    public void Unsubscribe(IObserverSubscribe ios){        
        subscribers.remove(ios);
    }   
    public void notifySubscribers(){        
        for(IObserverSubscribe ios : subscribers ){         
            ios.Notify();           
        }       
    }
}

Interface Observer:

package observerpattern;

public interface IObserverSubscribe {

    void Notify();

}

Concrete Observer:

package observerpattern;

public class ConcreteObserverYoutubeUser implements IObserverSubscribe{

    @Override
    public void Notify() {
        System.out.println("User watches video, comments, ect");

    }

}
  • 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-16T13:01:51+00:00Added an answer on June 16, 2026 at 1:01 pm
    new IObserverSubscribe();
    

    This is illegal because you cannot instantiate an interface – they by definition do not have any … definitions of their methods.

    IObserverSubscribe user1= new ConcreteObserverYoutubeUser();
    

    The left side here says that user1 is of type atleast IObserverSubscribe, i.e points to an instance whose type implements the interface.

    The right side on the other hand actually creates an instance of a concrete type and assigns to user1. This is possible because the concrete type implements the interface.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
This could be a duplicate question, but I have no idea what search terms

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.