Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
The introduction
In team development, we often document and ask for a uniform specification. There are all sorts of complicated specification requirements that must include parent inheritance constraints.
Parent class inheritance constraint: The creation of a custom class of a type must inherit or implement a specified superclass (parent class).
Here’s an example:
Creating a custom Provider must inherit BaseProvider and implement its methods
abstract class BaseProvider{
String get moduleName;
}
Copy the code
- Method 1: Require developers to consciously check and follow inheritance specifications when creating
- Method 2: Define public
Live template
Constraint development, convenient and quick
Start the Live module:
Add shortcuts to reduce manual input, using AndroidStudio as an example. Open Preferences and search for Live Templates. Find Flutter and click the plus sign to add a Live Templates
For example, let’s add a standard template to create A PRV. In Abbreviation, the name is defined as PRV
Template text insert this:
import 'package:pos/test/provider_restrain.dart';
class $CLASS_NAME$Provider extends BaseProvider {
@override
String get moduleName => "";
}
Copy the code
Applicable to all parts of the product; Applicable to all parts of the product; Applicable to all parts of the product Done, ready to use.
Edit area inputprv
Directly enter
The necessary specification code is automatically filled in, and you just need to add code based on the business.