Summary of "C# Eğitim Kampı Ders 11 - OOP Modülü: C# ile N Katmanlı Mimari Entity Layer"
Summary of “C# Eğitim Kampı Ders 11 - OOP Modülü: C# ile N Katmanlı Mimari Entity Layer”
This lesson introduces and implements a multi-layered (N-layer) architecture in C# with a focus on Object-Oriented Programming (OOP) principles and the Entity Layer. The instructor also covers the “Code First” approach in Entity Framework and explains how to structure a C# project into distinct layers to improve maintainability, modularity, and clarity.
Main Ideas and Concepts
Context and Introduction
- This lesson is the 11th in a training camp series.
- The instructor briefly mentions Republic Day (October 29th) and its 101st anniversary.
- Builds on previous modules (201 module covered lessons 9 and 10) introducing object orientation.
- Starts the 301 module focusing on multi-layered architecture in C# using a console application for explanation.
Multi-layered Architecture Overview
The project is structured into four layers:
-
Entity Layer Contains entity classes representing database tables.
-
Data Access Layer Handles database operations.
-
Business Layer Contains business logic and rules.
-
Presentation Layer (User Interface) Handles user interaction; can be Windows Forms or Console.
Benefits of this architecture:
- Improved maintainability.
- Easier error management.
- Modular development facilitating teamwork and individual work.
Creating the Project Structure
- Start with a Blank Solution in Visual Studio, named appropriately (e.g., “C# Eğitim Kampı 301”).
- Add projects for each layer as Class Libraries (except the presentation layer, which can be a Windows Form or Console App).
- Use naming conventions like
<SolutionName>.EntityLayer,<SolutionName>.DataAccessLayer, etc. - Set the presentation layer as the startup project for debugging.
Entity Layer and Classes
- Contains classes that map to database tables.
- Uses Code First approach: define classes and properties in C# first, then create the database schema from these classes.
- Example entity classes and their properties:
Category:CategoryID,CategoryName,CategoryStatusProduct:ProductID,ProductName,Stock,Price,DescriptionCustomer:CustomerID,Name,Surname,District,CityOrder:OrderID, etc.
- Properties use get and set accessors for Entity Framework compatibility.
- Naming conventions for primary keys are important: property named
<ClassName>ID(e.g.,CategoryID) to be recognized as primary key and auto-incremented.
Access Modifiers
public: accessible from anywhere.private: accessible only within the class.internal: accessible only within the same assembly/layer.protected: accessible in derived classes.
Entities and their properties are usually public to allow access from other layers.
Properties vs Fields vs Variables
- Fields: variables declared directly in a class without get/set.
- Properties: variables declared with get/set accessors, used for data encapsulation.
- Variables: declared inside methods.
Single Responsibility Principle (SRP) from SOLID Principles
- Each class or method should have one responsibility or task.
- Example: Customer information should be separate from Order information.
- Helps organize code better and maintain separation of concerns.
Code First Approach
- Instead of creating tables first in SQL and then coding, create classes first.
- Entity Framework generates tables and columns based on classes and their properties.
- Allows better integration with OOP concepts.
Practical Steps Demonstrated
- Creating a blank solution and adding four projects (layers).
- Adding folders (e.g., “Concrete”) to organize entity classes.
- Creating entity classes with appropriate properties.
- Setting the presentation layer as the startup project.
- Running the project to show a basic Windows Form (UI layer).
- Deleting unnecessary default classes in class libraries.
Future Topics and Additional Notes
- Detailed explanation of Entity Framework will be covered in upcoming lessons.
- Relationships between tables (entities) will be explained later.
- Additional lessons planned beyond usual Tuesday and Saturday sessions.
- Encourages students to comment and like the video to help others find the content.
- Plans to create communication channels (e.g., WhatsApp) for the course community.
Detailed Methodology / Instructions
Setting Up the Solution and Projects
- Open Visual Studio → File → New Project → Select Blank Solution.
- Name the solution (e.g., “C# Eğitim Kampı 301”).
- Add new projects for each layer:
- Entity Layer: Class Library (.NET Framework)
- Data Access Layer: Class Library
- Business Layer: Class Library
- Presentation Layer: Windows Forms Application (or Console App)
- Delete default class files (e.g.,
Class1.cs) in class libraries if not needed. - Set the presentation layer as the startup project.
Creating Entity Classes
- Add a folder named Concrete inside the Entity Layer project.
- Right-click on the folder → Add → Class → Name it (e.g.,
Category.cs). - Define public properties with get and set for each column.
Use Visual Studio shortcut
prop tabto create properties quickly. Example:csharp public int CategoryID { get; set; } public string CategoryName { get; set; } public bool CategoryStatus { get; set; } - Follow naming conventions for primary keys (
ClassNameID). - Repeat for other entities:
Product,Customer,Order.
Understanding Access Modifiers
- Use
publicfor entity properties to allow access across layers. - Use
internalto restrict access to the same assembly. - Use
privateandprotectedfor encapsulation and inheritance.
Applying Code First Approach
- Create classes first, then use Entity Framework to generate database tables.
- Properties correspond to table columns.
- Use get/set properties instead of fields for EF compatibility.
Applying Single Responsibility Principle
- Keep each class focused on one entity/table.
- Separate customer and order data into different classes.
- Avoid mixing unrelated responsibilities in one class or method.
Running the Application
- After setting up layers and projects, run the presentation layer.
- Confirm the form or console window appears.
- Use this as a base to continue building the application.
Speakers / Sources Featured
- Primary Speaker: The instructor of the C# training camp (name not explicitly mentioned). Guides through the lesson, explains concepts, and demonstrates coding.
This summary captures the key instructional content and concepts from the lesson, focusing on multi-layered architecture, entity layer creation, OOP principles, and practical steps in Visual Studio.
Category
Educational
Share this summary
Featured Products