Project Overview
Part of the Object Oriented Programming section of Coddy's GDScript journey. Lesson 56 of 65.
Challenge
MediumIn this project you build a Library Management System over six steps: a library, books and users, borrowing, search, statistics and returns. Every step starts from your files of the previous step.
This step creates the Library class in library.gd. The starter already declares its three properties:
library_name: the name of the librarybooksandusers: twoArray[String]that start empty. For now they hold titles and user names.
Complete the two methods:
- The constructor
_init(library_name)stores the name in the propertylibrary_name. _to_string()returnsNAME Library (books: N, users: M), whereNandMare the sizes of the two arrays.
The supplied code reads the library name from the first line, then one command per line: book TITLE and user NAME append to the arrays, info prints the three properties and show prints the library. For this input:
Community
info
book Dune
user Ada
showthe output is:
Name: Community
Books: 0
Users: 0
Community Library (books: 1, users: 1)Your code goes in library.gd. main.gd holds the supplied input/output code and cannot be edited.
Try it yourself
extends Node
func _ready():
# Supplied input/output code: keep it as it is
var library := Library.new(OS.read_string_from_stdin())
var line := OS.read_string_from_stdin()
while line != "":
var parts := line.split(" ", true, 1)
match parts[0]:
"book":
library.books.append(parts[1])
"user":
library.users.append(parts[1])
"info":
print("Name: ", library.library_name)
print("Books: ", library.books.size())
print("Users: ", library.users.size())
"show":
print(library)
line = OS.read_string_from_stdin()
All lessons in Object Oriented Programming
1Fundamentals of OOP
External FilesIntroduction to OOPClasses vs ObjectsThe self KeywordMethodsPropertiesConstructor (_init)Recap - Simple Calculator4Polymorphism
Method Overriding RevisitedDuck TypingAbstract Classes and MethodsInterface DesignRecap - Shape Calculator2Class Properties
Instance vs Static VariablesStatic FunctionsProperty SettersProperty GettersPrivate by ConventionRecap - Bank Account Manager5Encapsulation
Public and Private MembersValidation with SettersInformation HidingRead-Only PropertiesRecap - Student Records System8Advanced OOP Concepts
Composition vs InheritanceInner ClassesNodes as ComponentsRefCounted vs NodeEnums in Classes11Project: Library Management
Project OverviewBook and User Classes3Inheritance
Basic InheritanceThe super KeywordMethod OverridingInheritance ChainsType Checks with isRecap - Employee Hierarchy6Special Methods
Virtual Methods IntroductionThe _to_string MethodCustom IteratorsRecap - Custom List9Design Patterns Part 1
Intro to Design PatternsSingleton PatternFactory PatternObserver PatternStrategy PatternPractice on your own: Online GDScript compiler