Object-oriented programming is a programming paradigm using "objects": data structures consisting of data fields and methods together with their interactions.
3
votes
1answer
80 views
Improvement of my php code
I wrote a class with this function. Can I improve my code performance in the bottom of the function? I don't like the while loops!
public function loadFields(array $fields, $as_object = ...
2
votes
1answer
38 views
Can I do something better in that code? And improvements?
Hi guys, simple question!
Can I do something better with the code I wrote.
It's running problem less. It's just a snippet of a library I wrote.
Thank you for all answers!
<?php
/*
* ...
0
votes
1answer
45 views
Box(x,y,X,Y), box(x,X,y,Y), box(x,w,y,h), box(x,y,w,h) or box(fromPos,toPos)?
Say you are representing a box, or creating a function that slices a 2d array, or whatever. How do you represent it?
5
votes
3answers
334 views
Is it wrong to write an entire program under one class/method in Java?
I'm new to programming an created a simple rock, paper, scissors game. The entire program is under a single class and the main method, i hear that's probably not the best way to code.
How should i ...
-1
votes
0answers
29 views
Object Oriented PHP - mysql database manipulation [closed]
Been working with this code but it won't run. Please help me find the problem with this.
THis is my class :
<?php
class mysqlcon
{
private $connection;
private $database;
public $query;
...
0
votes
1answer
70 views
I've finally found a satisfactory way to create classes on JavaScript. Are there any cons to it?
Depending on external OO libraries is really bad, using prototypes/new has some limitations, using only hashes has others. Dealing with classes was always a pain in JavaScript and it didn't help that ...
2
votes
1answer
114 views
Collision detection implementation
I'm working on a clone of Hunter Story. You shoot monsters with your bow. Recently I implemented collision detection, this is all working correctly, and I don't think the code needs any dramatic ...
4
votes
4answers
128 views
General advice on a practice linked_list for C++ classes/templates
Introduction
I'm learning C++ (Coming from Haskell, C, and Assembly - and other languages sparsely) and this was my practice with classes and templates. It's a linked list that you can call in this ...
3
votes
1answer
84 views
Best OOP method for a layout library
I had a code for a layout library which looked like :
$this->layout->setLayout($layout)->setTitle($title)->render()
etc.
Today I started writing a new code, simpler and smaller :
...
0
votes
1answer
68 views
Q&A system model design [closed]
Now I am trying to build a Q&A website by myself.The models below is my model design.I have some questions about this.
1、class Category:
public class Category {
private String name;
}
...
2
votes
0answers
37 views
Lua OOP and classically-styled prototypal inheritance
I want to do some object-oriented programming in Lua, and I decided on something like this:
local B = {} -- in real life there is other stuff in B
B.Object = {
constructor = function() end,
...
0
votes
1answer
52 views
Image Resize/Crop Class
I've combined some of my own functions with a function I found and I'm curious to know what others think of it. It will be used to upload and resize/crop images that are jpeg, jpg, png.
<?php
...
0
votes
1answer
43 views
Should a User class only contain attributes and no methods apart from getters/setters?
I'm trying to improve my OOP code and I think my User class is becoming way too fat.
In my program a user has rights over "lists". Read, Write, Update, Delete.
So I made a User class
class User
{
...
1
vote
4answers
181 views
Making this code 'more' OOP
I have just started to try and learn 'OOP' but it appears I'm doing this wrong, according to the people on StackOverflow the code below is far from Object Orientated, but I'm finding it hard as I'm ...
2
votes
1answer
79 views
Abstraction for multiple connection methods
Coding to the interface, rather than the implementation. Here is what I'm doing in simple terms.
Note: Although written using PHP, this is more of a general design / abstraction question that ...
2
votes
1answer
65 views
Design with Context, Table and Functions
Each class of my project has several inputs and outputs. Each input, the same as output, depends on it's own set of value-datatype.
I need to provide a mechanism to forward data streams from one ...
3
votes
1answer
94 views
The eternal dilemma: bar.foo() or foo(bar)?
I was using foo(bar) as it's adopted for functional programming.
console.log(
join(
map(function(row){ return row.join(" "); },
tablify(
...
3
votes
1answer
61 views
Static variable in method vs private class property
I have a class with a method that will be called multiple times over an object's lifetime to perform some processing steps. This method operates on a mixture of immutable (does not change over the ...
1
vote
1answer
42 views
autoloader class fine tune to be usable in every project
I'm open to any advice to help improve this code for general use.
/**
*
* This code was created by Joshua Getner.
* @license http://opensource.org/licenses/bsd-license.php BSD
*
*
*/
namespace ...
0
votes
1answer
88 views
js oop best practise
I have to set up a new JavaScript library for a big project, which isn't Object Oriented yet. So I built a small file to test some needs. The result is the following:
var Module =
{
Config: ...
0
votes
0answers
36 views
Getting colors from an image PHP
I am working on a site that themes itself based on images / logos. I have built the class that gets the colors from image, shown below. I am fairly new to OOP with PHP and looking for feedback on what ...
2
votes
4answers
81 views
Python OO Code Review for small blogging script
I've recently re-written a Python script I use to run a couple of lightweight blogs. Looking over the horrible code I'd written before, I decided to rewrite it using object-oriented concepts. I wanted ...
1
vote
2answers
93 views
Is this class structure good?
I'm writing a pong game in Python and I created classes for the game objects.
The top level class is Object, and Ball and Paddle inherit from it. And ComputerPaddle is a child class of Paddle.
# ...
0
votes
2answers
56 views
along right lines for an application class for mvc?
Please could you review and critic my code and logic. If this is along the right lines for an application mvc class or not. Thanks
namespace dh_mvc2;
use dh_mvc2\dispatchers\Base_Dispatcher;
use ...
0
votes
1answer
41 views
php autloader class reviews welcome
is this class ok? any and all advice very welcome. Would it be better to pass the config file path array into the constructor or even through the static register method
namespace dh_mvc2\autoloaders;
...
6
votes
1answer
163 views
Is this bad OOP design?
I've discovered (and written) a way to object oriented programming in lua in a functional fashion instead of the standard metatable method. It carries much more functionality (no pun intended) but I'm ...
0
votes
2answers
58 views
PHP Class that handles all includes / required files
In effort to streamline applicable PHP file include or require functions I thought that making a class to handle this might be a good idea.
Originally I had an includes/init.php file that included ...
2
votes
1answer
72 views
Scope Resolution Operators and class variables in PHP OOP
I am new to this site, so I apologize if this question is not welcome. I am also new to OOP in PHP. I have done a lot of research on OOP and I keep seeming to read different opinions on several items, ...
1
vote
1answer
132 views
Getting familiar with OOP - Factories
I have no idea if I'm doing this efficiently, or ideally, but I've written what I think is a factory. Please help me understand if this is good practice, or if there is another direction I should take ...
8
votes
0answers
208 views
Thoughts on my brain fart interpreter?
Had some free time this weekend and I hacked together a small Brainfuck interpreter, with the sole intention of explaining PHP's flavour of OO to a friend. This is a bit over-engineered on purpose, ...
-1
votes
1answer
90 views
Should I use inheritance in my case? [closed]
UPDATE - I write in C#. The code is added below.
I have 2 classes that should run a service when calling their Start method, but before it they should:
Copy items to F folder
Open S service in ...
2
votes
1answer
56 views
Merit of a “Search” class similar to a “Builder” class
I have a class something like the following:
class ItemManager {
List<Item> items;
public ItemManager() {
items = Database.retrieveItems();
}
}
An item has several ...
1
vote
2answers
98 views
Oriented-object approach on how to control different classes cleanly
I'm currently creating a client/server application (using Java) and I want to make it fully controllable by an input stream (currently the console). At the moment only one class have to be controlled, ...
0
votes
1answer
38 views
Dynamically create object
I am developing a web-application and I am encountering some trouble :
I have some tabs and each one contains input forms with different values. I need to switch beetween these tabs and see the ...
4
votes
2answers
120 views
Strategy Design Pattern in Python
I'm reading the awesome Head First Design Patterns book. As an exercise I converted first example (or rather a subset of it) to Python. The code I got is rather too simple, i.e. there is no abstract ...
2
votes
1answer
107 views
How to properly store error messages and display them with OOP?
I have a class that I am using to initialize a form for editing. Once the form is submitted, data validation is done through the setters of my class. Good or bad input will be set in order to ...
2
votes
1answer
88 views
Instantiating objects in a MVC in PHP
I am working on converting a PHP application to MVC, and have a couple questions!
1) I have a main Model object, that I require a database connection for, as well as a User object that uses a ...
3
votes
1answer
68 views
How to properly make a user class with a session
So I am working on a LMS project and I have a User class that will handle everything about the user such as registration, login, showing list of courses that they are subscribed to, etc.
...
4
votes
1answer
183 views
PHP Extending PDO Class
I am trying to convert myself from using mysql extension to using PDO, with that being said I was curious if I am going about this the right way.
I have a custom logging system that I built I am ...
3
votes
2answers
63 views
Review of OOP in Ruby class
Could you please review the following class products?
It should tell me whether the product is taxable or imported. Name should indicate if the product is imported or certain keywords should tell ...
0
votes
0answers
28 views
Making one object the property of another whilst avoiding scope issues
After being inspired by some MVC style design patterns, I have been trying to separate data from views in my code and move toward a more sensibly organized object based approach. (please, don't bother ...
3
votes
1answer
64 views
Design review for single master-multiple slaves component
EDIT:
I conclude I've failed to describe the problem.
Intro: Master-Slave Architecture
Master-Slave is a common hardware setting, in which multiple peripheral, passive components, are wired to a ...
0
votes
1answer
48 views
Instance of one class to contain arbitrary number of instances of another class in Python
I'm trying to see if there is a better way to design this. I have a class Animal that is inherited by Male and Female classes (Female class has an additional attribute). I also have a class called ...
1
vote
2answers
102 views
PHP Class Inheritance / Object Instantiation / Object / Property Scope w/ Child / Parent Classes & Dependency Container Class
In PHP, I have a parent/child class and am using dependency container to load them. I am trying to use the same database connection on all of them without duplicating the object.
CLARIFICATION: MY ...
0
votes
1answer
141 views
Object Orientated PHP, what's wrong with this implementation of OOPHP and how might it be improved?
I need some advice off the back of a question I posted on StackOverflow. I'm a procedural PHP programmer and I'm looking to make the move into object oriented PHP. I have started a small project that ...
2
votes
1answer
82 views
First steps with PHP OOP
I am learning OOP using PHP5 and I wrote two simple classes for receive data of database using dependency injection pattern and render a grid with Twig.
Please, if is possible, take a look and give ...
-1
votes
1answer
105 views
design classes for a JAVA swing application [closed]
I am very new in making JAVA swing applications..
My problem statement is to make a library management application,for which i designed classes as below.
Please tell me whether my design of classes ...
1
vote
1answer
403 views
Is this PHP class good enough for CRUD
I wrote this class to make it reusable in any project.
It uses PDO as the MySQL connection.
Beside not using Setters and Getters, is this code secure and good practice for CRUD ?
Thanks for further ...
0
votes
2answers
58 views
Consistent implementation of PHP class constants (arrays not allowed)
I'm currently writing a class:
final class MyTestClass {
const URL = 'http://www.example.org';
private static $MY_ARRAY = array('...');
// since this is not allowed
// const MY_ARRAY = ...
0
votes
2answers
131 views
Constructor with too many arguments [closed]
We have a Transaction class that's very loaded; so loaded that I originally ended up passing almost 20 argument to the ctor. After extracting a few value objects, there are still 12 arguments left, ...