Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Treating classes as first-class objects

I was reading the GoF book and in the beginning of the prototype section I read this:

This benefit applies primarily to languages like C++ that don't treat classes as first class objects.

I've never used C++ but I do have a pretty good understanding of OO programming, yet, this doesn't really make any sense to me. Can anyone out there elaborate on this (I have used\use: C, Python, Java, SQL if that helps.)

like image 849
javamonkey79 Avatar asked Mar 03 '09 04:03

javamonkey79


1 Answers

For a class to be a first class object, the language needs to support doing things like allowing functions to take classes (not instances) as parameters, be able to hold classes in containers, and be able to return classes from functions.

For an example of a language with first class classes, consider Java. Any object is an instance of its class. That class is itself an instance of java.lang.Class.

like image 80
Mr Fooz Avatar answered Oct 21 '22 03:10

Mr Fooz