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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:29:42+00:00 2026-05-16T02:29:42+00:00

Writing another question for SO, I came to a pattern that I use very

  • 0

Writing another question for SO, I came to a pattern that I use very often and I never really reflected about. But now, I’m no longer sure if this is the right way:

If I have collections that my WPF-controls will bind to, I returned almost always IEnumerable<SomeType>. However internally , this is in most cases an ReadOnlyObservableCollection<SomeType>. I never had a problem with this and all consuming controls always updated correctly, what is not astonishing because they check for the INotifyCollectionChanged-interface.

But my question is now, if this is bad practice to declare in the signature only the IEnumerable<SomeType> but to return (and also depend on) something much more powerful (INotifyCollectionChanged).

Update:

I try to clarify:

My main intention is to return an IEnumerable<SomeType>. But most of the time, the returned IEnumerable<SomeType> implements also INotifyCollectionChanged such as ReadOnlyObservableCollection<SomeType> does. The consuming controls bind accordingly (what my second intention is).

Maybe I should have asked: Is there an interface that exactly contains IEnumerable and INotifyPropertyChanged.

  • 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-16T02:29:43+00:00Added an answer on May 16, 2026 at 2:29 am

    Remember, IEnumerable<T> and INotifyCollectionChanged are both interfaces – they aren’t a definitive type. You can design your concrete class to implement both, with no problems. Your API can return the appropriate interface for the method call. This is, in fact, a good design – not something to avoid.

    ObservableCollection<T> does this (indirectly via Collection<T>), and also implements IList<T> as well as other interfaces.

    If you are making your own custom collection, and plan to use it with data binding, I would make it implement IEnumerable<T> (or potentially IList<T>, if appropriate) and INotifyCollectionChanged. This will give it the best usability, both from code, but also for efficient binding.


    (and also depend on)

    However, depending on an interface to exist that isn’t part of the API is bad practice. This is dangerous, and part of the reason to return an interface instead of a concrete type is to allow the implementation to change later. By putting a dependency on an interface that isn’t declared, you’re making your code fragile.

    That being said, I often do what you’re attempting, but it’s not a “hard” dependency. Rather, I use IEnumerable<T>, and check for INotifyCollectionChanged – taking advantage of it if it is implemented. I do, however, allow the code to work if the “secondary” interface doesn’t exist.

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

Sidebar

Related Questions

Yet another simple question about unit testing model objects that uses data access layer.
I have a method that I'm writing that is calling another overloaded method inside
Programming is learned by writing programs. But code reading is said to be another
I'm sorry if this is a very simplistic question but I'm still learning the
I'm a bit confused on url writing in .htaccess and have a question about
I'm kind of new to writing sql and I have a question about joins.
I'm writing a programmer's text editor (yes another one) in Perl called Kephra ,
I am writing a windows service. This service runs another process I've developed through
Writing a JSP page, what exactly does the <c:out> do? I've noticed that the
In another question, other users offered some help if I could supply the array

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.