LocustHorde
LocustHorde

Reputation: 6409

Is it possible to inherit methods into different namespace in clojure?

I want to be able to access several functions in several namespaces by including one single namespace in other places..

eg, assume I have vehicles.clj, car.clj, bike.clj, and handler.clj.

I want to be able 'inherit' or include all methods from car.clj and bike.clj in vehicles.clj so I can just use or require vehicles.clj in my handler.clj namespace (or any other namespace) and call functions in car and bike.cljs.

Not unlike parent and children classes in C#. Is this possible?

The reason I need this is because I've split up many functions into different files so as to keep the separation of concerns, but I want also want to be able to just include the main file (say, vehicles.clj as (:use [myproject.vehicles]) in any other namespace / files and call the functions in all those classes.

Is there a better way to do this?

Thanks.

Upvotes: 4

Views: 230

Answers (2)

octopusgrabbus
octopusgrabbus

Reputation: 10695

I may be missing your point, but it sounds like you are describing a utility library. I found across my small number of Clojure applets all depend on a common library. I used leiningen new util to create that project. Most of my applets are built with util. They are all common routines like a tool bag.

Not coming to Clojure from Java but from C/C++, I found it took a while to get used to Clojure's naming, and I would agree complicating that would make sustaining engineering -- even if you are the sustainer -- more difficult.

Upvotes: 0

Rayne
Rayne

Reputation: 32675

https://github.com/ztellman/potemkin has tools for doing this, but I highly recommend that you don't. This sort of thing can easily make code very difficult to follow and it's easy to turn what seems like improved organization into a spaghetti nightmare.

Use at your discretion, but try to keep in mind that making things easier on yourself doesn't always mean you're improving the code!

Upvotes: 5

Related Questions