Skip to content

Add syntax to support object protected inheritance #3193

Closed
@DartBot

Description

@DartBot

This issue was originally filed by [email protected]


From discussion thread: https://groups.google.com/a/dartlang.org/group/misc/browse_thread/thread/6fd72014c119934d/6bed87932b58b762?lnk=raot#­6bed87932b58b762

Some variant of protected inheritance would be useful, and a protected by object sort of inheritance would likely be better than protected by class, because class based protection leads to any subclass being able to mess with any other subclass in unexpected ways. Because object protected methods could be statically bound, there is no need to require a prefix to identify them, so the concept could be orthogonal to library privacy. Here is a proposed syntax:

class c {
  // This is publicly visible
  var publicFunc() {}

  // This can be accessed by any code in this library
  var _privateFunc() {}

  // This can only be invoked on this
  var this.protectedFunc() {}

  // This can only be invoked on this by code in this library
  var this._privateProtectedFunc() {}
}

Metadata

Metadata

Assignees

Labels

area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions