Class Structure and Passing Data

JREAM

Below I have a series of classes. I am trying to figure out the best way to pass my data from Process.php into each of the following classes.

/CLI/
    /Process/
        /Condition
            Rule.php
        Condition.php
        Single.php
    Process.php
    Response.php
    Registry.php <-- I don't want to use this, It feels sloppy

At first I wanted to pass data in the hierarchy like below (Im not extending anything at the moment favoring Composition over Inheritance):

\CLI\Process.php

public function run() {
    $condition = new Condition($dataToShare);
}

\CLI\Process\Condition.php

public function __construct($dataToShare) {
    $this->data = $dataToShare;
}

\CLI\Process\Condition\Rule.php

public function __construct($dataToShare) {
    $this->data = $dataToShare;
}

Instead I decided to use a Registry Pattern because I'm paranoid. I feel like the shared data going from class to class and it's messy. Then I found myself setting some Registry values inside a subclass, and it was just as bad!

So a co-worker told me to try an Abstract class so each of these guys can extend it. My problem is that if I extend an Abstract Class then my values won't be set (Because it's a new parent instance).

Is my best option a Singleton? Does anyone have any suggestions to keep this cleaner? I want this to be clean, and I dont want to have this paranoid thought of contaminating data over continually passing it down levels.

While I ask this question it feels like Im speaking Chinese underwater.

SmasherHell

You can try abstract class and static property to share it with all your instance

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Passing data to root Vue class component

From Dev

Swift Passing data from appDelegate to another class

From Dev

Passing a structure (pointer to structure?) to a function

From Dev

Boost python: passing large data structure to python

From Dev

passing structure between function

From Dev

Class-to-class passing of data, optimization

From Dev

Passing data from the class to the MainActivity

From Dev

Passing Data From A Class To WatchOS 2 (Connectivity)

From Dev

Passing data to Pthread using structure in C

From Dev

passing data from UITabBarView Class to sub class of UIViewController using swift

From Dev

Data structure for storing, parsing, passing multidimensional information

From Dev

passing data to torch.class(es) in lua

From Dev

Passing current location data to my asynctask class

From Dev

Passing a pointer to a structure (StructureByReference) in to C code, How to access that data again?

From Dev

Java, getting data and passing it into another class method

From Dev

Passing data between Activity and View class

From Dev

Passing data from a class that 'extends activity' to a class that 'extends fragment'

From Dev

Android - Error while passing data into DatabaseHandler class

From Dev

passing data from BroadcastReceiver to class that extends runnable

From Dev

group fetch / data updates (class structure design)

From Dev

Check in base class if derived class' data structure contains string value

From Dev

passing data to torch.class(es) in lua

From Dev

Xamarin Android passing data from class to activity

From Dev

Passing a subclass of a class that inherits from ctypes.Structure

From Dev

Convert a nested data structure to use a class object

From Dev

Class With Data Structure Paramater Class C# Unity

From Dev

Class With Data Structure Paramater Class C# Unity

From Dev

Passing data types to C++ class contructor

From Dev

Proper structure for Food class with data from json

Related Related

  1. 1

    Passing data to root Vue class component

  2. 2

    Swift Passing data from appDelegate to another class

  3. 3

    Passing a structure (pointer to structure?) to a function

  4. 4

    Boost python: passing large data structure to python

  5. 5

    passing structure between function

  6. 6

    Class-to-class passing of data, optimization

  7. 7

    Passing data from the class to the MainActivity

  8. 8

    Passing Data From A Class To WatchOS 2 (Connectivity)

  9. 9

    Passing data to Pthread using structure in C

  10. 10

    passing data from UITabBarView Class to sub class of UIViewController using swift

  11. 11

    Data structure for storing, parsing, passing multidimensional information

  12. 12

    passing data to torch.class(es) in lua

  13. 13

    Passing current location data to my asynctask class

  14. 14

    Passing a pointer to a structure (StructureByReference) in to C code, How to access that data again?

  15. 15

    Java, getting data and passing it into another class method

  16. 16

    Passing data between Activity and View class

  17. 17

    Passing data from a class that 'extends activity' to a class that 'extends fragment'

  18. 18

    Android - Error while passing data into DatabaseHandler class

  19. 19

    passing data from BroadcastReceiver to class that extends runnable

  20. 20

    group fetch / data updates (class structure design)

  21. 21

    Check in base class if derived class' data structure contains string value

  22. 22

    passing data to torch.class(es) in lua

  23. 23

    Xamarin Android passing data from class to activity

  24. 24

    Passing a subclass of a class that inherits from ctypes.Structure

  25. 25

    Convert a nested data structure to use a class object

  26. 26

    Class With Data Structure Paramater Class C# Unity

  27. 27

    Class With Data Structure Paramater Class C# Unity

  28. 28

    Passing data types to C++ class contructor

  29. 29

    Proper structure for Food class with data from json

HotTag

Archive