The room has four walls. Probably, if we assume a rectangular room, otherwise things get more complicated.
The most general approach is to not assume four walls, and just say that the room has a list of walls.
class Wall {
final double height;
final double width;
Wall({required this.height, required this.width});
double get totalArea => height * width;
}
class Room {
final List<Wall> walls;
Room(Iterable<Wall> walls) : walls = List.unmodifable(walls);
}
void main() {
var room = Room([
Wall(width: 4, height: 4),
Wall(width: 2, height: 4),
Wall(width: 4, height: 4),
Wall(width: 2, height: 4),
]);
var wallArea = 0.0;
for (var wall in room.walls) wallArea += totalArea;
}
That allows any combination of walls, for your basic L-shaped rooms with six walls, or heptagonal rooms for style.
In some cases, you can make things easier by making assumptions.
Like a rectangular room always have identical opposing walls, and same height everywhere.
Then you can do:
class RectangularRoom implements Room {
final double length1;
final double length2;
final double height;
final List<Room> rooms;
RectangularRoom({
required this.length1,
required this.length2,
required this.height})
: rooms = _createWalls(length1, length2, height);
static List<Room> _createWalls(
double length1, double length2, double height) {
var wall1 = Wall(length: length1, height: height);
var wall2 = Wall(length: length2, height: height);
return List.unmodifiable([wall1, wall2, wall1, wall2]);
}
}
Or you can assume the room is oriented in some way:
// Also assumed rectangular.
class OrientedRoom extends Room {
final Wall northWall;
final Wall westWall;
final Wall southWall => northWall;
final Wall eastWall => westWall;
OrientedRoom({
required double length1,
required double length2,
required double height
}) : this._(Wall(length: length1, height: height),
Wall(length: length2, height: height));
OrientedRoom._(this.northWall, this.westWall)
: super([northWall, westWall, northWall, westWall]);
}
That allows you to name the individual walls, and have a class field for each.
So many options. What is right for you depends on your use-case, what you will use the objects for.