Posts

Showing posts with the label oop;dart;programming;flutter;lego;abstraction;encapsulation;inheritance;polymorphism;

What is LEGO, and How Does It Relate to OOP?

Image
LEGO is a famous toy system where you build things using small, reusable building blocks . Just like you can combine different LEGO pieces to make a car, house, or spaceship, in OOP , you combine objects (small reusable code blocks) to build apps. How LEGO Relates to OOP Concepts 1️⃣ Encapsulation → Hiding Details In LEGO, some pieces have internal mechanisms (like gears inside a LEGO car), but you only interact with the outside (wheels, doors, etc.). In OOP , objects hide internal logic and only expose necessary functionality . Example: class Car { // Private property (hidden from the outside) int _enginePower = 100; // Public method (exposed to users) void drive() { print("Car is driving with $_enginePower horsepower."); } } void main() { Car myCar = Car(); myCar.drive(); // ✅ Allowed // myCar._enginePower = 200; ❌ Not allowed (encapsulated) } 2️⃣ Abstraction → Hiding Complexity When you build a LEGO car , you don’t worry about how...