1

recently i want to implement observer pattern in my angular 4 app, i faced this syntax of code in typescript and i don't know what this means?

the code:

module Patterns.Interfaces {

    export interface IObservable {
        RegisterObserver(Observer: Patterns.Interfaces.IObserver);//Patterns.Interfaces.IObserver type?
        RemoveObserver(Observer: Patterns.Interfaces.IObserver);
        NotifyObservers();
    }
}

thanks for your helps.

3
  • Are you referring to the module declaration or the interface declaration? Or something else? Commented May 1, 2018 at 7:01
  • Start from documentation typescriptlang.org/docs/handbook/interfaces.html Commented May 1, 2018 at 7:03
  • @Sid both module and Patterns.Interfaces.IObserver type. Commented May 1, 2018 at 7:03

1 Answer 1

5

Here's an annotated version:

// There's a namespace named Patterns.Interfaces
module Patterns.Interfaces {
    // It has an interface named IObservable
    // It is visible outside this block ('export')
    export interface IObservable {
        // An IObservable has a function called RegisterObserver.
        // It takes one argument named 'Observer'.
        // 'Observer' is of type Pattern.Interfaces.IObserver.
        // You must pass this argument.
        // Its return type is unspecified, so is assumed to be 'any'
        RegisterObserver(Observer: Patterns.Interfaces.IObserver);//Patterns.Interfaces.IObserver type?
        // Same as above
        RemoveObserver(Observer: Patterns.Interfaces.IObserver);
        // An IObservable has a function called NotifyObservers.
        // It is called with no arguments.
        // Its return type is unspecified, so is assumed to be 'any'
        NotifyObservers();
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your answer,i wasn't any familiar with namespaces in typescript and i didn't know what to search.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.