Questions tagged [composition]

Composition is the process of combining, or composing, parts of a program into a larger program.

Filter by
Sorted by
Tagged with
1 vote
1 answer
57 views

What is the difference between struct composition and typedef?

Whether use struct to compose a struct type or use typedef to define an alias to the struct, the result looks the same. What is the difference between these two forms? #include <stdio.h> struct ...
binbo's user avatar
  • 11
0 votes
2 answers
43 views

What type should an array store when using composition over inheritance?

When using inheritance, you can create two classes A and B that inherit from class C. You can then create an array of C to store either of these -- C[]. However, when using composition, what type ...
cardiaque66's user avatar
2 votes
0 answers
43 views

Composition For WithOptions Pattern in Golang

In golang there's a pretty cool pattern for variadic options as CallSomeStaff(mandatoryArg, WithSomeVariadicOption(val1), WithOtherVariadicOption(val2)) But what is the best/intended practice (or at ...
404's user avatar
  • 215
0 votes
0 answers
36 views

Lambda and method reference in Compose

In Compose, there is a moment when a lambda or a reference to a method is passed as a parameter and a recomposition occurs, then Compose regards this as another object Explain how he defines it, ...
senior salaga's user avatar
0 votes
1 answer
89 views

Making a class method private/protected but making it accessible if its composed within another class?

In C++, there are public, private, protected attributes/methods which provide different sets of permissions for inheritance. I have a design issue where I have a class A, and a class B has an ...
roulette01's user avatar
  • 2,054
-2 votes
1 answer
75 views

How does inheritance lead to higher coupling than composition?

One major reason for using composition over inheritance is, that inheritance leads to higher coupling. How is that? As long as I set my base class fields and methods to private I don't expose any ...
cobby's user avatar
  • 488
2 votes
1 answer
87 views

Access parent object data member from sub-object in Python

I have a setup like the following class decorator: def __init__(self, fn): self.fn = fn @staticmethod def wrap(fn): return decorator(fn) def __call__(self): ...
Niteya Shah's user avatar
  • 1,831
0 votes
0 answers
9 views

Select layers for composition legend in QGIS

I want to choose specific layers when I'm putting the legend in a map composition. There is an option in which I can write the name of the layers separated by a | . But I have many copies of the layer ...
paola barrera's user avatar
-1 votes
1 answer
68 views

Composition class in Ruby: where to put, how many methods?

On my Rails backend, I want to reuse several methods in different model classes. Google search points me towards Ruby composition. I have two questions concerning good practice: How many methods can ...
user19858571's user avatar
0 votes
1 answer
47 views

FocusRequester not initialized when using if statement to conditionally show TextField in Jetpack Compose

I'm creating a title bar that contains some text. The text cannot be edited by default and becomes editable when the edit button is clicked var value by remember { mutableStateOf("jordan") } ...
Kun.tito's user avatar
  • 185
1 vote
1 answer
53 views

How to combine structs in go for network devices?

I am trying to implement a structure (in a kind of capturing program) for keeping network devices' list in golang. Each device-type both have some basic network attributes (which are applicable to all ...
E. Gündüz's user avatar
0 votes
1 answer
91 views

Factory functions and composition

I have the following code in JavaScript: const calculateDiameter = (circle) => ({ get diameter() { return (circle.radius * 2); } }); const calculateCircumference = (circle) => ({ get ...
Greeso's user avatar
  • 7,682
2 votes
0 answers
67 views

how to combine error with printf in haskell [duplicate]

I found the Haskell module Text.Printf. It provides a sort of C-like printf. For example printf "hi %d\n" 42 will produce the string "hi 42\n". That is pretty neat. Now something ...
A. Meijster's user avatar
0 votes
0 answers
107 views

Creating animations using a visual layer in WinUI 3

My question is more about the styling of the code that uses the visual layer animations than the animations themselves. The problem is that I use animations everywhere: on pages, in controls, in ...
Георгий Попов's user avatar
0 votes
0 answers
70 views

Vue 2.7 Array of objects losing reactivity when modified

I've recently managed to upgrade our codebase to Vue 2.7 in the hopes of being able to start using the CompAPI, but I'm having some issues with it. The feature that I'm having an issue with is the ...
Sensanaty's user avatar
  • 926
1 vote
1 answer
23 views

How to add validation check to multiple methods without boilerplate code?

There is the following code from Android Basics with Compose course by Google: https://pastebin.com/X0VZSmCg. I need to implement checks in SmartHome class methods: turnOnTv() and turnOnLight() ...
Pavel Lesyuk's user avatar
0 votes
0 answers
39 views

An interface-level analog to composition over inheritance

I'm curious if any programming language has a feature allowing multiple member functions in a class --- or some analogous construct in non-OO contexts --- to be grouped together as if they were ...
Osr Workshops's user avatar
2 votes
0 answers
39 views

Aggregation vs Composition in OOP (Java example) [duplicate]

Now I understand the theory of these types of associations: Aggregation implies a relationship where the child can exist independently of the parent. Example: Class (parent) and Student (child). ...
r'ouster's user avatar
0 votes
1 answer
50 views

Is it possible to compose parts of JSONSchema to simplify schema definitions?

I'm building a schema in which I have an array of items to be added. Each item represents an entity containing data and some metadata (configuration values) attached. The metadata is almost always ...
thclark's user avatar
  • 4,962
0 votes
0 answers
15 views

Trying to implement composition with a variable number and type of components

I'm trying to implement composition as the design pattern for an item system. For example, I have a base item class, and it has a name and an ID. But some items are equippable, and instead of making ...
swasfu's user avatar
  • 1
1 vote
1 answer
45 views

Duplication in unit testing

Lets say I have a class like the following : public class Component { private readonly object _a; private readonly object _b; private readonly object _c; public object OperationX() =&...
creativergk's user avatar
-1 votes
3 answers
44 views

Passing multiple params and multiple functions into a function

I have a function await mainFunction(function1, function2, function3) I also want to pass multiple functions into the mainFunction const mainFunction = async (function1, function2, function3) =>...
TommyD's user avatar
  • 913
0 votes
0 answers
21 views

script for adding source image to essential graphics

I'm trying to add source image to essential graphics so I use this code which is for property and change it to use for image. app.beginUndoGroup("Add to EGP"); function add(theLayer){ ...
Fatemeh Hashemi Moghadam's user avatar
1 vote
1 answer
62 views

How to expose all methods of child component in vue3

When wrapping third-party components, props and emits can be passed automatically with "v-bind=$attrs". How do expose of childComponent pass automatically like they do? // ChildComp <...
hdy's user avatar
  • 11
1 vote
1 answer
156 views

Multiple composable instances within a single script tag in Vue 3

I'm currently undertaking a rewrite of our components that are currently written with the Options API. One interesting point for a rewrite from a code-cut standpoint is our many modals, which all have ...
Sensanaty's user avatar
  • 926
1 vote
1 answer
25 views

Vue composition api reactive property

Inside a vue 3 project using typescript, i got two property locale and content : <script setup lang="ts"> import { computed, ref } from 'vue' import { useI18n } from "vue-i18n&...
Raphael Rlt's user avatar
0 votes
0 answers
28 views

Any ideas on how to avoid class constructor property drilling for vanilla JS?

I am having a bit of a problem with composition in my library that I am developing, and I am curious what people think about how I go about it. It all starts at the entrypoint of the app, the Client ...
Jack Wright's user avatar
0 votes
1 answer
55 views

Proper way to decouple components

I am working on the communication of two components (using Vue 2), where one is a button, which can have states such as initial, loading, and concluded (successfully or not), and for each state of the ...
Bernardo Benini Fantin's user avatar
2 votes
2 answers
112 views

How do I utilize Javascript closure and private variables while also using Object.assign + Object.create in a factory function?

I'm trying to figure out how to incorporate factory function closures and use Object.assign/Object.create inheritance at the same time. Probably simple, but I can't figure out how to do it. First I ...
stuffz's user avatar
  • 23
0 votes
1 answer
97 views

Generics: constraints and struct embedded in interface

The following code does not compile, and reports ./main.go:35:7: Test does not satisfy Constraint (Test missing in main.StructWithName) package main import "fmt" type Test struct { ...
Philippe's user avatar
  • 3,943
0 votes
1 answer
27 views

Can an association be non-composition and non-aggregation?

I have heard that aggregation and composition are parts of association (If we are talking about OOP). But there is a occasions where we can't name one like an assotiation or aggregation? I've read ...
Lucy's user avatar
  • 27
0 votes
0 answers
25 views

Does Composition violates Dependency Inversion principle?

As for my understanding, Composition means, if a class A has an object of another class B in the way of "composition", A is responsible for maintaining life cycle of the object of B. ...
Lasindu Nuwanga's user avatar
0 votes
2 answers
52 views

Specifying child method with base class object in Java

I've written below snippet to produce better and reusable code in all of Child classes. Base Entity : public class BaseEntity{ Integer id; //setter getters etc } Child Entity : public ...
Mohammadreza Khatami's user avatar
0 votes
1 answer
45 views

How to provide parameters to different types of components?

I am developing an rpg simulation game in Godot, where NPCs are driven by their needs as in 'The Sims'. I have an Entity class that represents the NPC: class_name Entity extends Node2D var components:...
twenty7's user avatar
  • 97
0 votes
0 answers
51 views

Writing a general, catch-all event handler in Vue.js

Vue 3 has a mechanism to emit events from a child component (with $emit) and receive that event in the parent component (with v-on or @). The mechanism is clearly explained here: https://vuejs.org/...
freecorvette's user avatar
0 votes
1 answer
25 views

Python: conserving list structure when working with Composition-Composite classes

How to conserve list structure when working with Composition in Python? For instance, class Population: '''Defines a population of Colonies''' def __init__(self, Nc, ...): self....
Vítor Sudbrack's user avatar
0 votes
0 answers
30 views

Composed object needs access to parent class method

I have a class Round that has a Calc composed class object. Round also inherits from several base classes, and inherits a method called parameter from one of its base classes. Calc has a method, ...
24n8's user avatar
  • 1,986
1 vote
1 answer
19 views

How to generalize an inherited method call and a composed method call

At work, I'm running into an issue where a piece of code takes in a class object, obj, where the object can be one of multiple classes. The code makes the following call: obj.compute() For one of the ...
24n8's user avatar
  • 1,986
0 votes
3 answers
1k views

Should I Use useMemo to Wrap Components Delivered as Props in React Composition Pattern?

Our React project has a code written in Composition Pattern as below. return ( <Template title={ useMemo( () => ( <> <TitleComponent prop={value} ...
Woojin Lee's user avatar
0 votes
1 answer
23 views

Can we achieve composition goals if we have a language that supports multiple inheritance?

I'm wondering if we could achieve composition goals through inheritance by keeping each class small and inheriting from multiple classes(java and c# doesn't support unfortunately)? for example: #...
Curllog's user avatar
  • 1,464
3 votes
1 answer
230 views

Reusing methods in go which operate on struct values

I am trying to share a single method across multiple structs in go. I do not want to have to redefine the method across every struct. I realise that code reusability in go is achieved by using ...
DanVP's user avatar
  • 49
1 vote
5 answers
175 views

How would one implement generic functionality which gets applied across various distinct classes without inheritance?

I need to define a function that can be used by multiple classes, but as far as I understand, inheriting from a superclass doesn't work for me. Essentially, what I would like to achieve is the ability ...
user21877241's user avatar
1 vote
2 answers
64 views

Designing Microservice dependencies properly with related data

This is a highly theoretical question and focuses largely on me not completely grasping design principles behind related data in microservices and responsibility of obtaining related data. The basic ...
Andy Troschke's user avatar
1 vote
1 answer
46 views

Is it possible to call methods created by factory function?

If I compose some methods with factory function below. function createCrudMethods() { return { findMany: async () => { }, findOne: async () => { }, createOne: async () =>...
Pu5her's user avatar
  • 53
0 votes
1 answer
65 views

How extend a class is diff from implicit class?

I'm trying to understand the difference between child class (class child extend Parent) and implicit class ( implicit class Child (a: Parent)) In both cases, the child instance is able to access both ...
Lenny's user avatar
  • 83
0 votes
1 answer
74 views

What is the idiomatic way to combine member function calls with other function calls in Scala? [duplicate]

Say we have an object (e.g. a list) in Scala, and we want to sequence user-defined functions with object member functions, for instance: g(l.map(f) .foldRight(...)) .map(h) If the sequence of ...
Matei's user avatar
  • 152
-1 votes
1 answer
35 views

Position absolute divs next to each other in list

Is there any way of having a list of divs display inline next to each other when they're positioned absolutely? I don't have control over the markup in my situation, and the divs need to all sit ...
ells157's user avatar
  • 19
0 votes
0 answers
18 views

Composition/Inheritance: Patial Class Specialisation

An 'architectural' question regarding 'best practice', interms of the standards and/or the core guidelines. I am looking for an approach to solving the hypothetical scenario of 'partial specialisation'...
Bevan Jones's user avatar
2 votes
1 answer
90 views

UML classes diagram the question of relations and visibility of fields

I have a few questions regarding my design after having reviewed a number of information sources. I decided to link the User and UserSettings classes with a composition relation (since user settings ...
Smth_Unknown's user avatar
2 votes
3 answers
2k views

Fetch API with Vue Composition API (script setup)

I am so confused. I want a simple generic fetch function to learn it on basic, but I want to do it with the Vue Composition API and script setup. This is my script: <script setup> import {ref} ...
mikasa's user avatar
  • 85

1
2 3 4 5
35