Project Structure
Part of the Object Oriented Programming section of Coddy's C# journey — lesson 62 of 70.
Challenge
EasyLet's set up the foundation for your Library System project! You'll create the basic file structure that will grow into a complete library management application over the coming lessons.
You'll organize your code across four files, each with a specific responsibility:
Book.cs: This file will hold your Book model. For now, create aBookclass in theLibrarySystemnamespace with three auto-implemented properties:Title(string),Author(string), andIsAvailable(bool, defaulting totrue). Add a constructor that takes the title and author as parameters.User.cs: This file will contain your User model. Create aUserclass in the same namespace with two properties:Name(string) andMemberId(int). Include a constructor that accepts both values.Library.cs: This is where your core logic will live. Create aLibraryclass with aNameproperty (string) and a constructor to set it. Add a method calledGetInfo()that returns a string in the format"{Name} Library System Initialized".Program.cs: Bring everything together here. This is your entry point where you'll create instances of your classes and verify the structure works correctly.
You will receive three inputs:
- The library name
- A book entry in the format
title|author - A user entry in the format
name|memberId
Create a Library instance with the given name, a Book with the provided title and author, and a User with the provided name and member ID. Then print three lines:
- The result of calling
GetInfo()on your library - The book's information in the format
Book: {Title} by {Author} - Available: {IsAvailable} - The user's information in the format
User: {Name} (ID: {MemberId})
For example, if the inputs are:
City Central
The Great Gatsby|F. Scott Fitzgerald
Alice Johnson|1001The output should be:
City Central Library System Initialized
Book: The Great Gatsby by F. Scott Fitzgerald - Available: True
User: Alice Johnson (ID: 1001)This structure follows the Single Responsibility Principle - each file handles one specific concern. In the upcoming lessons, you'll expand these classes with borrowing logic, search functionality, and a full console interface!
Try it yourself
using System;
namespace LibrarySystem
{
class Program
{
public static void Main(string[] args)
{
// Read inputs
string libraryName = Console.ReadLine();
string bookInput = Console.ReadLine();
string userInput = Console.ReadLine();
// Parse book input (format: title|author)
string[] bookParts = bookInput.Split('|');
string bookTitle = bookParts[0];
string bookAuthor = bookParts[1];
// Parse user input (format: name|memberId)
string[] userParts = userInput.Split('|');
string userName = userParts[0];
int memberId = Convert.ToInt32(userParts[1]);
// TODO: Create a Library instance with the library name
// TODO: Create a Book instance with the title and author
// TODO: Create a User instance with the name and member ID
// TODO: Print the library info using GetInfo()
// TODO: Print the book info in format: Book: {Title} by {Author} - Available: {IsAvailable}
// TODO: Print the user info in format: User: {Name} (ID: {MemberId})
}
}
}
All lessons in Object Oriented Programming
1Fundamentals of OOP
External FilesNamespaces & DirectivesIntro to Classes & ObjectsThe 'this' KeywordMethods and ParametersFields vs PropertiesConstructorsObject InitializersRecap - Simple Calculator4Inheritance
Basic Inheritance (:) SyntaxThe 'base' KeywordVirtual & Override KeywordsSealed ClassesThe 'object' Base ClassRecap - Employee Hierarchy7Advanced Features
Operator OverloadingIndexers (this[])ToString() OverrideExtension MethodsRecap - Custom List2Properties & Static Members
Auto-Implemented PropertiesRead/Write-Only PropertiesStatic Fields & MethodsStatic ClassesExpression-Bodied Members5Polymorphism & Interfaces
Compile vs Runtime PolyInterface vs Abstract ClassMultiple InterfacesExplicit InterfacesUpcasting & DowncastingRecap - Shape Calculator3Class Architecture
Instance vs Static Data'readonly' & 'const' KeywordsBacking FieldsRecap - Bank Account Manager6Encapsulation
Access ModifiersProperties for EncapsulationData Hiding ImplementationImmutability PatternsRecap - Student Records12Project: Library System
Project StructureBook and User Models