GithubHelp home page GithubHelp logo

abstract class override fields about dart-lint HOT 1 OPEN

passsy avatar passsy commented on August 17, 2024
abstract class override fields

from dart-lint.

Comments (1)

minhqdao avatar minhqdao commented on August 17, 2024

The errors seem to contradict, but in fact they don't. 😉

The first one states that anything carrying the same name as a counterpart in its super class should be annotated with @override. That is typically the case if you define a static method in an abstract class that another class implements/extends. You could also do that here to resolve the first error. But then there is the second error stating that, no matter if @override is added or not, you shouldn't do it in the first place because fields aren't meant to be overridden.

See, if IContent had a field called name and Content had firstName, you could access both through:

final content = Content();
final name = content.name;
final firstName = content.firstName;

because Content extends IContent with its inherited name field. If you override a field with another, you loose that functionality, which, however, is the entire purpose of extending it. It is therefore bad practice to do so. 😔

If you really want to enforce the override, you can achieve that with an // ignore ..., but maybe you want to reevaluate whether you want to do that in the first place. 🤔

from dart-lint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.