0Pricing
Clean Architecture & Design Patterns in Practice · Ders

İş Varlıklarını Tasarlama

Kurumsal genelindeki iş kurallarını kapsülleyen ve kararlılığını koruyan temel iş nesnelerinizi (Varlıkları) tanımlayın.

İş Varlıklarını Tasarlama, CoddyKit'te ücretsiz bir Clean Architecture & Design Patterns in Practice dersidir. Bu, 4 dersinin 1. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Clean Architecture & Design Patterns in Practice öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Clean Architecture & Design Patterns in Practice kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

What are Business Entities?

In Clean Architecture, Entities are the heart of your application. They represent the core business concepts and rules that are crucial to your enterprise.

Think of them as the fundamental building blocks that define "what your business is" and "how it works," independent of how you store or display data.

Core Business Rules

Entities encapsulate enterprise-wide business rules. These are rules that would exist even if there were no software system, like "a product must have a positive price" or "an order must have a customer."

These rules are stable and apply across your entire organization, not just a specific part of your application.

Independent & Stable

A key principle of Entities is their independence. They should not depend on external layers like databases, web frameworks, or UI components.

This makes them the most stable part of your application, changing only when the core business rules themselves change, not when technology does.

Entity vs. DTO

It's important to distinguish an Entity from a simple Data Transfer Object (DTO). A DTO is just a bag of data, often used to move data between layers.

An Entity, however, contains both data and behavior. It actively enforces its own business rules through its methods.

Entity Structure

Typically, an Entity includes:

  • Attributes: The data that describes the business object (e.g., name, ID, price).
  • Methods: The operations that can be performed on the entity, enforcing its business rules and maintaining its integrity.

These methods ensure the entity always remains in a valid state according to your business logic.

Example: `Product` Entity

Let's consider a simple Product entity. What data and rules would it need?

  • A product needs an id, name, and price.
  • A core business rule might be: "A product's price must always be positive."

The entity itself should enforce this rule.

`Product` Entity Code

Here's how a basic Product entity might look in Java, ensuring the price rule:

public class Product {
  private String id;
  private String name;
  private double price;

  public Product(String id, String name, double price) {
    if (price <= 0) {
      throw new IllegalArgumentException("Price must be positive.");
    }
    this.id = id;
    this.name = name;
    this.price = price;
  }

  public String getId() { return id; }
  public String getName() { return name; }
  public double getPrice() { return price; }

  public static void main(String[] args) {
    try {
      Product laptop = new Product("P001", "Laptop", 1200.00);
      System.out.println(laptop.getName() + " costs $" + laptop.getPrice());
      // This would throw an error:
      // Product invalid = new Product("P002", "Free Item", 0.00);
    } catch (IllegalArgumentException e) {
      System.out.println("Error creating product: " + e.getMessage());
    }
  }
}

Entity Behavior & Rules

Entities aren't just data containers; they have methods that encapsulate behavior and enforce rules. For example, applying a discount might have its own business logic.

The entity's methods ensure its internal state remains consistent and valid according to business rules.

`Product` Discount Example

Let's add a method to our Product entity to apply a discount, with a rule that discounts can't make the price negative.

public class Product {
  private String id;
  private String name;
  private double price;

  public Product(String id, String name, double price) {
    if (price <= 0) {
      throw new IllegalArgumentException("Price must be positive.");
    }
    this.id = id;
    this.name = name;
    this.price = price;
  }

  public String getId() { return id; }
  public String getName() { return name; }
  public double getPrice() { return price; }

  // New method to apply discount
  public void applyDiscount(double percentage) {
    if (percentage < 0 || percentage > 100) {
      throw new IllegalArgumentException("Discount must be between 0-100%.");
    }
    double newPrice = this.price * (1 - percentage / 100);
    if (newPrice < 0) { // Ensure price doesn't go negative
      this.price = 0;
    } else {
      this.price = newPrice;
    }
  }

  public static void main(String[] args) {
    Product book = new Product("B001", "Clean Code Book", 40.00);
    System.out.println("Original: " + book.getName() + " $" + book.getPrice());
    book.applyDiscount(25); // 25% discount
    System.out.println("Discounted: " + book.getName() + " $" + book.getPrice());

    try {
      book.applyDiscount(150); // Invalid discount
    } catch (IllegalArgumentException e) {
      System.out.println("Error applying discount: " + e.getMessage());
    }
  }
}

Entity Properties Check

Based on what we've learned, which of the following are true characteristics of a Clean Architecture Entity?

Recap: Designing Entities

Great job! You've learned about Entities in Clean Architecture. Key takeaways:

  • Entities represent your core business concepts.
  • They encapsulate enterprise-wide business rules.
  • Entities contain both data and behavior, actively enforcing their rules.
  • They are independent and stable, not tied to frameworks or external layers.

Next, we'll explore how Use Cases interact with these robust entities to perform application-specific tasks.

Sıkça Sorulan Sorular

“İş Varlıklarını Tasarlama” dersi ücretsiz mi?

Evet — “İş Varlıklarını Tasarlama” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Clean Architecture & Design Patterns in Practice kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Clean Architecture & Design Patterns in Practice kursu toplamda 4 dersten oluşur.

“İş Varlıklarını Tasarlama” dersinde ne öğreneceğim?

Kurumsal genelindeki iş kurallarını kapsülleyen ve kararlılığını koruyan temel iş nesnelerinizi (Varlıkları) tanımlayın. Clean Architecture & Design Patterns in Practice ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Clean Architecture & Design Patterns in Practice öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Clean Architecture & Design Patterns in Practice, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 1. dersidir.

“İş Varlıklarını Tasarlama” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Clean Architecture & Design Patterns in Practice dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Clean Architecture & Design Patterns in Practice dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. İş Varlıklarını Tasarlama
  2. Kullanım Senaryolarını Uygulama (Etkileşimciler)
  3. Girdi ve Çıktı Bağlantı Noktaları
  4. Değişmezlerle İş Kurallarını Uygulama
← Clean Architecture & Design Patterns in Practice Sayfasına Dön