Sobes.tech
Junior — Middle

Can you give an example of when you applied the DRY principle in your project?

sobes.tech AI

Answer from AI

In one of my Flutter projects, I had repetitive logic for displaying information cards, where only the data and some styles changed. Instead of copying code, I created a universal widget with parameters for data and styles. This allowed me to avoid duplication, simplify maintenance, and quickly change the design in one place.

Example:

class InfoCard extends StatelessWidget {
  final String title;
  final String description;

  const InfoCard({required this.title, required this.description});

  @override
  Widget build(BuildContext context) {
    return Card(
      child: Padding(
        padding: EdgeInsets.all(16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(title, style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
            SizedBox(height: 8),
            Text(description),
          ],
        ),
      ),
    );
  }
}

This approach aligns with the DRY (Don't Repeat Yourself) principle, reducing code duplication.

Can you give an example of when you applied the DRY… - sobes.tech