DEV Community

FreakCdev
FreakCdev

Posted on

3 3

OOP in Batch

Hi, I'm Nguyen Phu Minh, creator and lead developer of the FreakC Programming Language. Since Batch does not have object-oriented programming, so today I'm sharing my attempt in "faking" OOP in Batch.

Creating a structure

First, I will create a file called "Dog.bat":

:: Creating properties
set %~1.age=%~2
set %~2.weight=%~3
:: Creating a child method
(
echo echo %%~1!
)>%~1.say.bat
Enter fullscreen mode Exit fullscreen mode

Then, I will create a main file which we run our code on:

:: Create an object
call Dog "Mary" "3" "4kg"
:: Prints out "age" property of "Mary", which is "3"
echo Age: %Mary.age%
:: Call "Mary.say" with argument "Woof", which prints out "Woof"
call Mary.say "Woof"
Enter fullscreen mode Exit fullscreen mode

That's it! Simple, right? Please comment if you've a better solution.

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay