Mrewan79
Apologies if this question has already been asked.
As I understand it, the way to translate a concept similar to use of abstract classes in Elixir is to use Protocols.
For instance if I have an abstract class of “Item” and I want it to be inherited for instance into “Weapon” or “Food” I would like to utilise the methods and values of this class. I do not want the parent methods to be accessed directly, but wish to add additional methods and utilise the child methods in their own way. (i.e. weapons can do damage, food is edible, weapons aren’t).
I can see the documentation here; https://elixir-lang.org/getting-started/protocols.html but am still not totally clear. The examples seem to work like overrides.
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Mrewan79
I used the search tool and nothing came up, but that doesn’t mean the question hasn’t been asked.
benwilson512
Can you perhaps talk more about the problem you’re trying to solve? The questions you’re asking are sort of the wrong questions in the paradigm that Elixir is. There are no classes, abstract or otherwise, no methods and definitely no parent methods.
If you can talk about about the data you want to represent, and the kinds of functionality you want, we might be able to suggest approaches that better suite a functional paradigm.
Mrewan79
#Abstract data examples
#Item - Abstract values
Weight - Int
Size - Int
Name - String
Description - String
#Food
Weight
Size
Name
Description
Edible = true
CptnKirk
Protocols aren’t about inheriting data fields, they expose standardized behavior across data types. Think about polymorphic methods in OO languages.
You have a Shape, Circle, Square, Triangle classes. Maybe Shape is an interface or abstract class. It defines certain methods common to the shape family of classes that each subtype must implement. For example, an area() method. Each Shape is able to compute its own area, however, those calculations differ depending on subtype.
With Protocols you can do something similar. You can define a Shape protocol along with protocol implementations for each Square, Circle, Triangle struct you might have. These protocol implementations could be defined within the given modules, or supplied externally in another module. The point is, you can have a function operate on data for which there is a Shape protocol implementation in the same way, regardless of the actual underlying contents of the data.
This is how the Enum module provides standard functionality for processing Enumerable things. Enumerable is a protocol that defines four functions. If you define a protocol implementation that implements those four functions for your data, then you can leverage the Enum module for your data as well.