Jump to content

RuleBritannia

Members
  • Posts

    92
  • Joined

  • Last visited

Posts posted by RuleBritannia

  1.  

    You should look up how autoloading actually works and what it does. I think this will eliminate the confusion. You cannot “instantiate a class and autoload it everywhere”. As I already said, autoloading can be used to load class definitions. You cannot load arbitrary scripts.

     

    I think you should forget about the Factory Pattern for now. It has absolutely nothing to do with the general problem of instantiating classes. It's an advanced design concept which you may use when you're familiar with the basics and try to improve your code.

     

    Resource sharing is yet another topic. I think you should postpone this as well. Before you jump into the advanced stuff, make sure you understand the basics (like autoloading).

     

     

    So using the factory pattern, does this allow resource sharing?

     

    As for autoloading and including I should not of mixed them throughout this thread, but what I was trying to say is if I had a file with the following code

    db.php
    $db = new PDO('...

    If I include this everywhere a db instance is needed, how is this different to calling a factory pattern class(Which creates or reuses a instance)?

     

    Arnt either of these methods using a new created instance at the begining and resuing a instance if called anytime after?

  2. Hi,

     

    you're confusing many different things which have nothing to do with each other.

     

    Autoloading automatically includes class definitions, nothing more, nothing less. It does not create instances in any way.

     

    The Factory Pattern is a specific way of instantiating classes. It's meant to make the instantiation more flexible and allow you to easily exchange one class for a similar class.

     

    The term “reuse” refers to code reuse. The point is that you are able to reuse your code in different contexts instead of starting all over again everytime. It has nothing to do with resource sharing or anything like that.

     

     

    I should of been more specific, If I instantiate a class(lets say connection) and store it in a variable, then include this everywhere needed and pass around in constructors, why would I need a factory?

     

    As for the term reuse meaning in a code reuse context, I dont believe that is how it was meant, I am sure I have seen on many occasions people saying "you dont want to be creating a new connection, you reuse a database connection already opened."

     

    The problem I have here is understanding how if we use factory or autoload, each one instansiate's lets say a connection(with new), how is this reusing a connection?

  3. Hello

     

    I hear alot of talk about reusing a database connection and attempts to solve this.

     

    I came across this post on stackoverflow but am having difficulty understanding as to how this is any different than just creating a instance in a single file and including it via include, require or autoload wherever a db instance is needed.

     

    The pattern talked about in the post is the factory pattern, it seems that the factory is responsible for creating the instance, something which I thought autoloading did without this additional code?

     

    Another thing I am still confused by with all the reuse talk - If 2 seperate users request 2 different pages on our server(2nd user 0.1 second behind the other user) which both refer back to the same db file/factory, are 2 instances created? or is the previuos users instance somehow used aslong as there request has not finished?

    I thought that the server would make new fresh requests/variables/instantiation etc all over again for every user, perhaps I am wrong.

     

    Thanks in advance.

  4. If you know where the mic is you should be able to pull the ribbon cable (it will most likely disable the webcam too) out that connects to it from the main board.

     

     

    I haven't taken apart too many laptops, and the few I did I wasn't really paying that much attention to things like the mic and such. I'd suspect however that an issue you'd probably run into is various components all using the same connector to the main board. For instance a lid with the display, webcam, and mic may use a single ribbon cable to connect to the motherboard. As a result disconnecting that cable would disconnect your display as well. You could try and single out which pins control which devices and remove them but you run the risk of permanent damage if you get it wrong.

     

    I assumed something like this, Thanks for your input guys, I will give it a shot either way and post back my results.

  5. Hello

     

    I wondered if anybody here had any hands on experience with removing some components from there laptops?

    One componenet im specifically interested in is the mic.

     

    With this being said, Im also aware of removing the drivers and so on to render the componenet "unavailable", but this is not my concern.

     

    I also mentioned laptops as the circuitry could be different to a desktop, Due to the size constraints I am wondering whether alot of the components are wired in a way that removing one can cause big problems elsewhere.

     

    Thanks for any insight/help in advance.

  6. Sounds to me like you are NOT handling this project wisely.  With the possibility for "thousands of rows here daily" having any significant number of errors, that you don't want these things to be processed, but rather rejected at input.  You really should step back and think about what you can do to help validate the input while the user is in the act of doing it so as to prevent as many 'rejections' as possible.

     

    Do you really want to be reviewing dozens(?) of errors every day?

     

    PS - this is the first time I've heard of your approach to error handling in 30+ years of design and development.  Very strange.

     

    They most likley will not have thousands of errors, But its not impossible.

     

    @that you don't want these things to be processed, but rather rejected at input.

     

    They will not be rejected at input, Once they error, they will be moved to another table so they dont clutter the Image table whilst they are not possible to be processed.

     

    The project is also only for me.

     

    @help validate the input while the user is in the act of doing it so as to prevent as many 'rejections' as possible.

     

    This is not possible, That would mean processing thousands of rows at once.

     

    The current method is rows get put in the Image table, processed at a reasonable rate within a parallel limit, If there is some file meta/file corrupt/file type/libary error etc, This will never fix itself by just reattempting to process it, The only way of fixing this is manually checking/deleting/updating/etc the file or libary which processes it.

     

    @Do you really want to be reviewing dozens(?) of errors every day?

    This is irrelevant to wherever/however they are handled/placed.

     

    Also its worth mentioning as I said before, I cannot foresee every possible "error", the plan is to reduce as many as possible, And each time a error does surface, I examine it and update the script to rule it out if possible before processing, But sometimes this is not possible without processing.

  7. No, don't move it. The data belongs where it is, just because you can't currently handle it doesn't mean it doesn't belong there. You should just mark it as processed and optionally include an error code that will indicate it needs to be re-visited.

     

    Trying to shuffle stuff around between tables is only going to cause you headaches in the future.

    hmm, But we can be inserting thousands of rows here daily, Not sure if its a good idea to clutter it with potentially thousands of rows which at that current time cannot be processed.

     

    Im still thinking of the best option for this, Thanks for your input.

  8. When i say errors its not the best word, I mean it in a scenario that if we use for example a libary to process some data, if that libary does not have the capabilities for the image file type, we will move it to error/concern table, so we can deal with it later, rather that leaving it in the que, to be included again a the next loop iteration, or marking it as "problem" and cluttering the table, it seems best moved to error/concern table, as it is not possible to solve this with our current libaries.

  9. What do you mean by a processing error?  Do you mean you can't add the data to the table?  Perhaps you should solve the problem rather than shuffling the data somewhere else.  Check for valid data entry before attempting to post it to the db.

     

    Processing error just within the script logic, eg image type not reconised, with regards to solving the problems, some problems I cannot foresee so it may not be possible to solve them, ontop of this the server must use its resources elsewhere, so we move the row to errors, and move on.

     

    I thought to have this column as a place I can consolidate all errors to, and check here every now and then to see any problems.

  10. Hello

     

    If we had multiple tables which hold data to be processed

    IMAGE
    +----+-----------+  
    | id |   image   |
    +----+-----------+
    | 4  | test.png  |
    | 5  | bird.png  |
    +----+-----------+
    
    ORDER
    +----+-----------+
    | id |   order   |
    +----+-----------+
    | 4  | 100000045 |
    | 5  | 100000046 |
    +----+-----------+
    

    When a processing error occurs, I thought to move the row to a table called error/attention/concern etc, To keep the table clean.

     

    Which would look something like this.

    ERROR
    +----+-----------+----------+-----------+
    | id | table_id  |  image   |   order   |
    +----+-----------+----------+-----------+
    | 1  |  4        | test.png |   EMPTY   |
    | 2  |  5        |  EMPTY   | 100000046 |
    +----+-----------+----------+-----------+
    

    However, This table will have to have corresponding columns for IMAGE and ORDER, But then we have a problem of storing empty/null values for the columns which are not needed on insertion here, This does not seem right.

     

    Has anybody had a similar issue before like this? Im sure there maybe a more definitive way of doing this.

    I also thought possibly just have 2 rows here, and enter a serialized array of data, but that seems even worse than this.

     

    Or finally I could possibly make 2 more tables, IMAGE_ERROR, ORDER_ERROR.

    But upon adding new processing technologies, I would need to add 2 new tables each time.

     

    Thanks in advance for any help/advice/answers.

     

  11. What's the function and what do you use it for (if it's not obvious)?

     

    To the question, I don't actually know of any functions I'd reuse that don't clearly belong in a class...

     

    Lets say you had a function which checks to see if all values in array 1 are less than all values in array 2

    You may need this functionality in many different things.

     

     

     

    If you can use php5.4, you might consider traits. See http://us2.php.net/traits

     

     

    Will read this now, Thanks

  12. Hello

    question is aimed @ experienced OOP'ers

    I just wondered how you handle a function which you use in multiple classes.

    You could write it fresh everytime in each class, Or make a standalone function in a php file and include it, But Im sure there is some better ways of doing this?

     

    So far with research it seems some people are making static "utility" classes, which they can call without initializing.

     

    Regards

  13. If we have a class which loads a row from the database and can update it etc,

    +-------------------------------+
    |  id  car  colour  price  fuel |
    +-------------------------------+
    |  2  bmw   blue   22000 petrol |
    +-------------------------------+

    If within this class, We run a update to change colour from blue to green, We can maintain this green setting without needing to requery the database, as we can change our internal value of $colour within our class to reflect the change.

     

    However, lets say another php script simultaneously does some work on this table, and it changes price from 22000, to 20000

    In our other object, we think we have up to date variables, But unknowingly to us we do not.

    We can requery the table with ID each time to change all internal variables, But this isnt efficient.

     

    Is it possible to link all changes to a central object, and if another script access or updates etc, they do it within this object, that way the change will be reconised anywhere.

     

    Thanks in advance.

  14. What is it you are trying to do? What row? What class?

     

    I think I have found some principles to abide by to reach a ultimate solution.

    data mappers or active record, But I think data mappers are best in my case as I want to stay within SRP.

     

    I am trying to store a row from a table, So I can return values when needed, whilst also updating these field(s) when needed, However a new problem occured, Which is when I perform a update and change a value, the row stored in the object will now not reflect the updated field in the database, so a requery would be needed, But I believe active record and data mappers cover this.

  15. OK, gotcha. I'd probably build a function that gets the list of images. Then call a 2nd function to update the requisite data. But, if you are getting the information from a 3rd party site you probably need some processes to connect to that site and some other things. So, maybe creating a class with all the relevant methods would be a better plan.

    Yes I do have a class specifically for fetching the data from the imagehost, But according to SOLID principles, I should be making a second class for database actions, But within the code this seems illogical when it could be handled within 1 class.

  16. Use two functions?

     

    But, really, I think this can be achieved in a better way without needing to store the data from the query. You state you want to save the number of images associated with a user and the timestamp of when it was checked. But, if you are storing the uploaded images as individual records in a separate table with timestamps of when they were uploaded, then you can run a query at any time to know what the counts were at any point in time in the past or currently. So, running these queries to get the results and then store that data seems to be counterproductive.

     

    The images are not on my server, Lets say for exmaple imageshack.us, I login, check total images, logout.

  17. Hello

     

    So I must return a value from somewhere, lets say image total uploaded count from a user account check.

    The value is returned, used within a loop etc.

    I also want to update my database with that figure, and a timestamp when it was checked.

     

    I know I can put this inside one function, so that after the value check, I can update a table and so on, But this breaks the single responsibility principle, as my function will be doing multiple things.

     

    Im curios how you would do this sticking to SOLID principles whilst not making a complete mockery at the same time.

     

    Thanks in advance.

  18. I would simply pass the DB object through the constructor and let Trip define the default method implementations. You simply refine steps inside PackageA and PackageB.

     

    class Trip {
      private $db;
      
      public function __construct(DB $db) {
        $this->db = $db;
      }
      protected function getDb() { return $this->db; }
    }
    This one.

     

     

    I don't think you know what a Gateway is. A Gateway is to provide access to an external system. Not call local classes and parse it's output, like:

     

    class TwitterGateway {
      public function getTweetsBy($username, $count = null) { .. }
    }

     

    I meant the term gateway just as a abbreviation, I should have said wrapper.

     

    In regards to passing the DB to trips, Does this not break the single responsibility principle?

     

    Trying to abide by all these principles isnt easy.(for me anyway).

     

    Edit : Nvm, Im just going to get it done, Cannot learn and apply every OOP principle in this space of time, My work is getting nowhere because of this.

     

    Thanks for all the help"

  19. If you have an algorithm for each website, but only one or two steps differ you can use:

    http://sourcemaking.com/design_patterns/template_method

    Hello

     

    I believe I have already done this, But my main question is where does db interaction sit within this?

     

    I could put the database handling inside the classes which inheirt the template and decide which methods to use.

    Or

    I build a gateway and parse all the small classes through this gateway before other stuff?

     

     template_method_example_trips_-_uml_clas

     

     

    Here is a good comparable example.

     

    Do I handle my database interaction within PackageA and PackageB?

    Or do I build a separate class, Which I parse the output from PackageA,PackageB and so on?

    This way would abide by the DRY principles, But that still doesn't mean its right.

     

    Thanks in advance.

  20. You could store the value as a class property:

    http://www.php.net/manual/en/language.oop5.properties.php

     

    Yes that would work, with the setter of that object not being in a __construct.

     

    With regards to this overall question, What about many properties that have been set later during the objects use?

     

    example

     

    var $date

    var $time

     

    Im guessing we should set all properties to null when we assign a new value to the "main" property?

    otherwise, we will be using older set values of properties set from a previous "main" value, (within the same new instance however)

    However if we just destroyed the object and started new, all of this would be done automatically, But I am wondering which is the professional way??

     

    kill object, rebuild new

    or

    build once, reset all with new use(via method to set all var inside to null)

     

    Thanks in advance.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.