ResoCoder / flutter-tdd-clean-architecture-course

https://resocoder.com/flutter-clean-architecture-tdd/
1.99k stars 623 forks source link

About entity issues #53

Open Jay-57blocks opened 1 year ago

Jay-57blocks commented 1 year ago

I read your article Entity: The business objects of the application, they are the least likely to change when external things change Model: Inherit and extend Domain layer Entity, realize json conversion and more needs

Generally speaking, business requirements have some additional fields, such as isSelected and isComplete, which are related to UI state I don't know whether these attributes are placed in the Domain layer or in the Presentation layer to create a new model

I am very confused and hope to wait for your reply

Thanks

Domain:

class QuestionEntitie {
  final int id;
  final String category;
  final String question;

 /// Should it be declared here?
  final bool isSelected;
  final bool isComplete;
}

OR Presentation:

class QuestionItem {
  final QuestionEntitie item
  /// or declare here ?
  final bool isSelected;
  final bool isComplete;
}

Data:

class QuestionModel extends QuestionEntitie {
  QuestionModel({
    required super.id,
    required super.category,
    required super.question,
  });

  factory QuestionModel.fromJson(Map<String, dynamic> json) {
    return QuestionModel(
      id: json['id'],
      category: json['category'],
      question: json['question'],
    );
  }
}