Welcome Guest, Not a member yet? Register   Sign In
Naming custom classes properly
#1

[eluser]xwero[/eluser]
I have had a discussion in this thread about the name you use to identify custom classes. Most people, including me, tend to use library to identify your own class. But this weekend i've come to the conclusion jbowman and Pygon are right that libraries are standalone classes that should be usable without framework dependence. But i think it doesn't have mean the libraries can't use MVC like segmentation.
Code:
// example file structure
libraries
  library.php
  models
    library_model.php
  view
    library_view.php  
// library.php
class Library
{
    
    function Library()
    {
       include('models/library_model.php');
    }
    
    function do_something()
    {
        // make the server sweat
        include('views/library_view.php');
    }
}
If you do it like this the library resembles the file structure of a module, but isn't because modules you can build for libraries like Matchbox and Modular Extensions can, and often do, contain CI only code.

Instead of talking about libraries maybe we should call classes that use CI code components? Should the CI user guide use components if they are talking about libraries that depend in CI framework code? Or are library developers prepared to go php native, so that they can call their software a library?
#2

[eluser]Unknown[/eluser]
i disagree with you.
#3

[eluser]xwero[/eluser]
Can you tell why your disagree? The post wasn't to make a point but to start a discussion about identifying classes as a group based on their scope.

For instance the CI zip library only has a dependency in the construct for the log message so you can use it with other frameworks/code as a drop in class with minimal changes so it is a library.
The upload library in addition to the log message depends on the language class for the errors so it would harder to transform to use the class in other frameworks/code so it would be better to referred to as a component?
#4

[eluser]adamp1[/eluser]
I take libraries to provide storing features the application needs in many places. I don't think it should be framework independent since this means no two libraries can use each other. So where do you put the code so two libraries can talk? A controller? A model? So by that theory an application would be very un-modular since each library would have to have its own language library/error checking functions.

I would say plugins are framework specific.
#5

[eluser]xwero[/eluser]
At first i was thinking the same as you. Why wouldn't a library use framework code and you have a good point saying there are some things that libraries will have in common how different they are in functionality. But if you make libraries that have consistent language files and error output you can create your own language/ error intercepting class or if it's possible use a (hacked) framework intercepting class.

Libraries don't talk to each other that much that i know of, for instance the upload and image_lib libraries. It would be more logical if you could do the image manipulation together with the uploading to generating one error because now you first have to evaluate the upload and in the success branch of the upload it's possible an image manipulation error happens meaning not all your data is processed like expected and that makes the upload invalid.

The people at Ellislab do their best to make their libraries as less dependent as possible but third party libraries often use quite a lot framework code to keep the library small, i'm doing it too. The example in previous response was to illustrate where you could draw the line calling a class a library and where you call it a component. In the thread i referred in the topic jbowman pointed out you shouldn't use models in a library because then the dependency on the framework is too strong. And that brings me back to my original question. What name should be used to group classes that depend too much on the framework to call libraries?

Maybe semantics is not the first concern for developers, if it works you can call it whatever you want attitude, but in the user guide, on the forum and in the wiki developers developers should make the distinction to make clear the class can be used only with CI or it can be used with other frameworks or as drop in class. Like Zend framework classes that can be used in CI, for CI developed classes can be used in the Zend framework for instance.




Theme © iAndrew 2016 - Forum software by © MyBB