Coder Social home page Coder Social logo

Complex example about bash-oo-framework HOT 5 OPEN

niieani avatar niieani commented on September 27, 2024
Complex example

from bash-oo-framework.

Comments (5)

constrict0r avatar constrict0r commented on September 27, 2024 1

@rbukovansky , something like this?:

source "$( cd "${BASH_SOURCE[0]%/*}" && cd .. && pwd )/lib/oo-bootstrap.sh"
import util/class

class:Location() {
public string x
public string y
}
Type::Initialize Location

class:Vehicle() {
public Location location
public string name

Vehicle.getter() {
@return:value $(this location toString)
}

Vehicle.Set() {
[reference] toSet
this location x = $($var:toSet x)
this location y = $($var:toSet y)
}
}
Type::Initialize Vehicle

string xSample=33
string ySample=55

Location locationSample
$var:locationSample x = $xSample
$var:locationSample y = $ySample
echo '--------------'
$var:locationSample

Vehicle vehicleSample
$var:vehicleSample Set locationSample
echo '--------------'
$var:vehicleSample

Results:

([__object_type]="Location" [x]="33" [y]="55" )

([location]="([0]=\"([__object_type]=\\\"Location\\\" [x]=\\\"33\\\" [y]=\\\"55\\\" )\")" [__object_type]="Vehicle" )

from bash-oo-framework.

rbukovansky avatar rbukovansky commented on September 27, 2024 1

@constrict0r Holy crackers! 😮 Thanks a lot! 👍

from bash-oo-framework.

constrict0r avatar constrict0r commented on September 27, 2024

Maybe you could check the option class I created, it has an Options collection:
https://github.com/niieani/bash-oo-framework/blob/d71a74aad77a1bfcdaff032b81090dfd1507e221/lib/util/option.sh

https://github.com/niieani/bash-oo-framework/blob/d71a74aad77a1bfcdaff032b81090dfd1507e221/example/option.sh

from bash-oo-framework.

niieani avatar niieani commented on September 27, 2024

@constrict0r, that's some hefty work indeed. Pretty cool!
@rbukovansky to answer your questions:

  1. creating collections of class instances is a bit tricky for now, but you can capture the definitions of instances (result of declare -p YOUR_VARIABLE and store them in a normal Array). The instance is sort of "serialized" that way.
  2. second is possible and should just work as long as you initialize your type before defining the other class. If it doesn't happen, feel free to open an issue, as it's a bug.

from bash-oo-framework.

rbukovansky avatar rbukovansky commented on September 27, 2024

@constrict0r Thanks, but I'm not sure, which question your answer answers. 🤷🏻‍♂️ Could you please elaborate a little bit more? Thank you!

@niieani So, you mean I need to:

  1. Create Class Location
  2. Create an object of class Location
  3. Set its properties
  4. Create Class Vehicle
  5. Create an object of class Vehicle

from bash-oo-framework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.