Why isn't Go considered an
object-oriented progamming
language ?
Rihab Sakhri
01
1. No Classes : In Go, there are no classes. Instead, Go uses structs to
define types, and methods can be associated with these structs.
Example :
ds cannot belong to a
c t , not a cla ss . M et ho
Here , Pe rs on is a stru
iat ed w ith th e stru ct.
class bu t ca n b e as soc
Rihab Sakhri
03
2. No Inheritance : Go does not support inheritance in the traditional
sense where one class can inherit properties and methods from
another class. Instead, it uses composition, where a struct can include
other structs.
Example :
n, but this is not inheritance
, Address is embedded in Perso
In this cas e
it's composition.
Rihab Sakhri
03
3. Interface Instead of Class Hierarchies : Go uses interfaces to
achieve polymorphism but does not have a rigid class hierarchy.
Any type that implements an interface’s methods implicitly satisfies
that interface.
Example :
a n b e p a ssed to the SayHello
ype th at h as a G re e t m et ho d c
Here, an y t a h iera rch y.
n , p ro m oting flex ibility w it hou t
funct io
Rihab Sakhri
04
4. No Access Modifiers : Go does not have traditional access
modifiers (public, private, protected). Instead, visibility is determined
by the first letter of the identifier: uppercase for public and lowercase
for private.
Example :
nnot be accessed outside of its
example, members of person ca
In this
package.
Rihab Sakhri
05
5. Simplicity and Minimalism : Go was designed with simplicity in
mind, preferring fewer abstractions and a more straightforward
approach to programming. This contrasts with many OOP languages
that embrace more complex features.
Rihab Sakhri
06
Conclusion :
While Go supports some object-oriented concepts like encapsulation
through structs and polymorphism through interfaces, it does so in
a way that diverges from traditional OOP principles. Go's focus on
simplicity, composition over inheritance, and the absence
of classes distinguishes it from classic OOP languages.
Rihab Sakhri