model icon indicating copy to clipboard operation
model copied to clipboard

Feature request: make using variables easier

Open yann-soubeyrand opened this issue 8 months ago • 1 comments

Hello,

I find that using strings to reference elements prevents us from taking advantage of the features offered by our IDEs (like static analysis, re-factoring, etc.). However, defining variables brings a lot of scopes challenges.

The following does not work:

var _ = Design(func() {
	SoftwareSystem("mysystem1", func() {
		container1 := Container("mycontainer1", func() {
		})
	})

	SoftwareSystem("mysystem2", func() {
		Container("mycontainer2", func() {
			Uses(container1, "Uses")
		})
	})
})

We have to pre-declare variables like the following:

var _ = Design(func() {
	var container1 *expr.Container
	
	SoftwareSystem("mysystem1", func() {
		container1 = Container("mycontainer1", func() {
		})
	})

	SoftwareSystem("mysystem2", func() {
		Container("mycontainer2", func() {
			Uses(container1, "Uses")
		})
	})
})

I would like to be able to write something like the following instead:

var _ = Design(func() {
	system1 := SoftwareSystem("mysystem1", func() {
	})

	container1 := system1.AddContainer(Container("mycontainer1", func() {
	}))

	SoftwareSystem("mysystem2", func() {
		Container("mycontainer2", func() {
			Uses(container1, "Uses")
		})
	})
})

yann-soubeyrand avatar Feb 14 '25 14:02 yann-soubeyrand