Just a random assortment of classic object-oriented programming (OOP) toy examples, some more fleshed out than others, to illustrate basic concepts of OOP.
If you fork this repository, be sure to add a FOREX_API_KEY environment variable to your local machine, with that name, and a placeholder for a value if you don't have an API key for an online currency exchange rate API. If you do have such an API key, make sure it is not quoted in any file watched by Git.
For information regarding Hacktoberfest, see CONTRIBUTING.md. Follow those guidelines to ensure not just that your contribution is accepted for Hacktoberfest, but also that it persists in the main branch after Hacktoberfest.
- Abstraction — FINISH WRITING
- Encapsulation — Objects encapsulate their state and forbid changes
except as prescribed by the defining class. See the
Odometer
class in thevehicles.parts
package. AnOdometer
instance allows its mileage to be advanced but not rolled back. - Inheritance — Classes inherit properties from base classes. The
animals
package definitely contains toy examples of this. Inheritance need not be deep to be useful. In the more practical examples, inheritance tends to average two or three levels: a subclass extends an abstract class, which in turn implicitly extendsjava.lang.Object
. - Polymorphism — FINISH WRITING
- Single responsibility — Each class should only have one
responsibility. For example, the
getBalance()
function in theCheckingAccount
class should only get the balance and not do anything else (such as verifying all applicable fees have been assessed.) - Open/Closed — FINISH WRITING
- Liskov substitution — Barbara Liskov was brought into this to make the acronym work. FINISH WRITING
- Interface segregation — Interfaces should not force implementing
classes to implement more than is necessary. For example, suppose we need the
FlyingSquirrel
class and a few other classes to implementglide()
from an interface. But if we have those classes implementFlightCapable
, they also have to have an implementation forfly()
or be declared abstract, and we don't want either of those because flying squirrels don't actually fly, they glide. Animals like eagles and hawks fly but they can also glide. So what we do is that we separateglide()
to theGlideCapable
interface and then theFlightCapable
interface can inheritglide()
fromGlideCapable
. - Dependency inversion — FINISH WRITING
Some people have questioned SOLID, arguing that it's not as relevant today as when it was introduced. Dan North has proposed one alternative to SOLID, CUPID.
- Composable — "plays well with others" FINISH WRITING
- Unix philosophy — "does one thing well" This one goes beyond the single responsibility principle in SOLID in that the FINISH WRITING
- Predictable — "does what you expect" FINISH WRITING
- Idiomatic — "feels natural" FINISH WRITING
- Domain-based — "the solution domain models the problem domain in language and structure" FINISH WRITING