OOP Notes
Discover where OOP is used in the real world — from game engines and web frameworks to operating systems, mobile apps, and enterprise software.
class Enemy : public GameObject { private: int health; float speed; std::string type; public: Enemy(float x, float y, std::string type, int hp, float spd) : GameObject(x, y), type(type), health(hp), speed(spd) {}
void update(float deltaTime) override { // Move toward player x -= speed * deltaTime; if (health <= 0) active = false; }
void render() override { std::cout << type << " at (" << x << ", " << y << ")" << std::endl; }
void takeDamage(int damage) { health -= damage; std::cout << type << " took " << damage << " damage! HP: " << health << std::endl; } };
class Projectile : public GameObject { private: float speed; int damage; public: Projectile(float x, float y, float spd, int dmg) : GameObject(x, y), speed(spd), damage(dmg) {}
void update(float deltaTime) override { x += speed * deltaTime; if (x > 1000) active = false; // Off screen }
void render() override { std::cout << "Bullet at (" << x << ", " << y << ")" << std::endl; }
int getDamage() { return damage; } };
from datetime import datetime
class BlogPost: def __init__(self, title, content, author): self.title = title self.content = content self.author = author self.created_at = datetime.now() self.comments = [] self.likes = 0
def add_comment(self, comment): self.comments.append(comment)
def like(self): self.likes += 1
def get_summary(self, max_length=200): if len(self.content) <= max_length: return self.content return self.content[:max_length] + "..."
class Comment: def __init__(self, text, author): self.text = text self.author = author self.timestamp = datetime.now() self.replies = []
def reply(self, text, author): reply = Comment(text, author) self.replies.append(reply) return reply
class User: def __init__(self, username, email): self.username = username self.email = email self.posts = []
def create_post(self, title, content): post = BlogPost(title, content, self) self.posts.append(post) return post
// Simplified file system hierarchy abstract class FileSystemObject { protected String name; protected long size; protected String permissions;
public abstract long getSize(); public abstract void display(int indent);
protected void printIndent(int indent) { for (int i = 0; i < indent; i++) System.out.print(" "); } }
class File extends FileSystemObject { private byte[] content;
public File(String name, long size) { this.name = name; this.size = size; }
public long getSize() { return size; }
public void display(int indent) { printIndent(indent); System.out.println("📄 " + name + " (" + size + " bytes)"); } }
class Directory extends FileSystemObject { private List<FileSystemObject> children = new ArrayList<>();
public Directory(String name) { this.name = name; }
public void add(FileSystemObject item) { children.add(item); }
public long getSize() { long total = 0; for (FileSystemObject child : children) { total += child.getSize(); // Polymorphism! } return total; }
public void display(int indent) { printIndent(indent); System.out.println("📁 " + name + "/"); for (FileSystemObject child : children) { child.display(indent + 1); } } }
// Android-style Activity (simplified) public class ShoppingCartActivity extends AppCompatActivity { private List<CartItem> items; private CartAdapter adapter; private TextView totalPrice;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); items = new ArrayList<>(); adapter = new CartAdapter(items); updateTotal(); }
public void addItem(Product product, int quantity) { CartItem item = new CartItem(product, quantity); items.add(item); adapter.notifyDataSetChanged(); updateTotal(); }
private void updateTotal() { double total = 0; for (CartItem item : items) { total += item.getSubtotal(); } totalPrice.setText(String.format("$%.2f", total)); } }
PyTorch-style neural network
class NeuralNetwork: def __init__(self, input_size, hidden_size, output_size): self.layer1 = LinearLayer(input_size, hidden_size) self.layer2 = LinearLayer(hidden_size, output_size) self.activation = ReLU()
def forward(self, x): x = self.layer1.forward(x) x = self.activation.forward(x) x = self.layer2.forward(x) return x
| Industry | OOP Usage | Primary Languages |
|---|---|---|
| Gaming | Game objects, physics, AI | C++, C# |
| Web | MVC frameworks, APIs | Java, Python, C#, PHP |
| Mobile | UI components, data | Kotlin, Swift, Java |
| Finance | Transactions, accounts | Java, C#, C++ |
| Healthcare | Patient records, devices | Java, C#, Python |
| Automotive | ECU software, infotainment | C++, Java |
| Aerospace | Simulation, control | C++, Ada |
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Applications of Object-Oriented Programming.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Object Oriented Programming (OOP) topic.
Search Terms
object-oriented-programming, object oriented programming (oop), object, oriented, programming, introduction, applications, oop
Related Object Oriented Programming (OOP) Topics