- Class definition
- Constructor
- instance vars
- params
- optional params
- Getters & Setters
- Public methods and private methods
- Inheritance
- children class specific methods
- overriding parent class methods
- extending constructor
- Composition - use other class
- Getters & Setters shortcuts
- attr_writer, attr_reader
- attr_accessor (2in1: attr_writer + attr_reader)
- Reading recap
- classes and objects: https://learnrubythehardway.org/book/ex42.html
- inheritnace & Composition: https://learnrubythehardway.org/book/ex42.html
- Basic two-ways class relationships
- real life example: Alex
has many
animals: a dog, a spider, a cat. And each of these animalsbelongs to
one owner, right? A dog belongs to Alex. A spider belongs to Alex. A cat belongs to Alex has many
- one object of class X can have a collection of objects of class Y (e.g. alex.animals)belongs to
- one object of class Ybelongs to
exactly one object of class X (e.g. animal.owner)- making sure that relationship works both ways
- real life example: Alex
- Three classes relationship (has-many-through relationship)
- real life example: a dog
has many
vet visits in their life and each of these visitsbelongs to
one vet. From anther perspective: a vethas many visits
and each of these visitsbelongs to
one animal. End result is that that a doghas many
vets through visits and a vethas many
animals through visits. has many
+belongs to
between class X and Y (e.g. dog.visits + visit.animal)has many
+belongs to
between class X and Y (e.g. vet.visits + visit.vet)
- real life example: a dog
- Reading: object oriented programming
- 4 principles - https://anampiu.github.io/blog/OOP-principles
- encapsulation: mostly using getters and setters in responsible way + usage of private methods
- inheritance: covered in recap in point 8
- abstraction: no real abstract class and methods in Ruby, we can do sth like https://stackoverflow.com/a/512568 though
- polymorphism: no specific implementation in Ruby, some ideas around well described here: https://robots.thoughtbot.com/back-to-basics-polymorphism-and-ruby
- the simplest examples of 3 principles (abstraction is not included) in Ruby: https://devblast.com/b/ruby-inheritance-encapsulation-polymorphism
- SOLID - https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design and https://robots.thoughtbot.com/back-to-basics-solid
- KISS & YAGNI & DRY - http://www.itexico.com/blog/bid/99765/software-development-kiss-yagni-dry-3-principles-to-simplify-your-life
- 4 principles - https://anampiu.github.io/blog/OOP-principles
- Project schema: UML class diagram