So in C++, we can create a class and then create an instance of this class in another new class like what has been done in the following:
# Creating the MyClass class
class MyClass{
constructor(){
this.my_list = []
}
is_empty(){
return this.my_list.length == 0
}
}
class MaxClass{
constructor(){
this.max_law = new MyClass() # Creating the MyClass instance in MaxClass
this.main_law = new MyClass()# Creating the MyClass instance in MaxClass
}
checking values(){
result = this.max_law.is_empty() # Using the MyClass is_empty function
return [result, this.main_law.is_empty()] # Using the MyClass is_empty function
}
}
Now, I was able to create the MyClass
module like the following:
defmodule MyClass do
defstruct my_list: []
def init, do: %MyClass{}
def is_empty(%MyClass{my_list: elems}), do: length(elems) == 0
end
I tried then creating the MaxClass
module as well like the following:
defmodule MaxClass do
def init do
max_law = main_law = MyClass.init
{max_law, main_law}
end
end
However, I am not sure how we can use this similar to how it is being used in C++.
I apologize for asking another weird question. The Elixir community over here has been an immense help and really glad for all the responses from you guys.