A metaphor that stuck with me when programming non-DI systems is "a person playing with his/her toys". A person being an object and the person's toys being anything that object creates, stores, initializes, and manipulates. The toys can dispatch events when they reach a certain state, but they know nothing about the person using them; th...
I have a JavaScript class, and I would like to make it so it can't be subclassed. (Similar to marking a class with the "final" keyword in Java.) Here's my JavaScript class:
function Car(make, model) {
this.getMake = function( ) { return make; }
this.getModel = function( ) { return model; }
}
...
I often find myself reading books and articles that outline patterns, best practices, and how to write "clean code." However, some of these concepts just seem to be over engineered and at times obscure the essence of the underlying problem, making the code more difficult to relate to the problem domain being modeled.
How often do you fi...
Hello,
ive got a user class where i can get the name, date of birth etc of the user... (below)
class user {
private $id;
private $name;
private $dob;
private address;
function __construct($id) {
$this->id = $id
}
}
i was just wondering what the best practice to get all users. do i create a function...
I'm new to OOP, so please bear with me if this is a simple question. If I create a class, which has attributes "a", "b", and "c", is it possible for the attributes to be an array, such that attribute a[2] has a meaning?
...
So,
I currently am working on a project, in which two different datasources will be updated.
The business objects have similar structures, but not exactly the same.
What I have currently planned on doing, is using a provider interface, so I have have a handler class to push to both databases.
As the 2nd object is from an external AP...
Hi,
Currently, I am reading Code Complete and in chapter dealing with class, author says that
Class Interfaces must provide consistent Abstraction
I am not able to understand this statement properly and would appreciate if someone could provide explanation with examples and what are relevant pros and cons.
Thanks.
...
I'm writing a small application framework which other programmers will use. So I'm looking to do some reading on framework design issues. I'm not completely new to framework design, but it's always a bit of a challenge.
Although I'm looking for general design principles, this particular framework is for Javascript applications, so it wi...
Is SearchString acting as property of Page class?
Here is code,
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public string SearchString
{
get { return txtSearch.Text; }
}
</script>
<html...
Hi all,
i was just looking for a bit of advice, currently my DB design is that one user has many blog postings. Now i have a user class and a blog class.
However im not sure about the proper way to get all blog posts for that user. Do i create a getAllBlogs() function in the user class which returns blog objects or do i create a main...
What are the pros and cons of each type/approach in writing Object Oriented scripts?
Personally, I have found closures (functional? approach) as a way to encapsulate state more natural and perhaps more elegant. I, however, have heard that this use of closures is slower in JavaScript implementations.
I would at least like to know where ...
Hey Guys.
I will like to see if everybody could share any good training sources on OOP on PHP language.
Good Training Sources for OOP (Object Oriented Programming) PHP, anyone ?
I've seen numerous tutorials, mostly superficial, some of them bad.
Please share anything good either commercial or free, Video or Written.
...
Lets say I have a class called PageBuilder which I instantiate, send parameters to and call functions from through my index file (which acts as a front controller). There are three sub classes associated with the PageBuilder class: Head, Body and Foot, that are accessed by PageBuilder which basically abstracts them for index.
So in the...
Hay guys. I'm kinda new to OOP in PHP. I've learnt how to write and create objects. Is there a way to take an object and pass it to another script? either using GET or POST or SESSION or whatever. If there isn't how would i assign an object some variables on one page, then assign the same object more variables on another page?
Thanks
...
Hay, when should variables be set within a PHP class?
<?php
class MyClass {
var $my_var; // here? like var $my_var = null;
function __construct(){
$this->my_var = null; // or here?
}
}
?>
...
This seems like it'd be a common question, but I cannot find it. Perhaps "system value" is the wrong phrase.
Anyway, by "system value" I mean the built-in values that a system has for a given concept. For example, if I have a list of categories (e.g., mexican, american, italian, etc...) where would you store them? Would you hard-code...
How is the Community member/account of StackOverflow work in terms of the ID being -1? Is it in the database? If not, how is it represented in code - is it a special instance of an account?
I am not looking for delving out privileges.
I want to replicate this so that my application has special "groups" that are defined in code and not ...
How can i perform a function once a variable's value has been set?
say like
$obj = new object(); // dont perform $obj->my_function() just yet
$obj->my_var = 67 // $obj->my_function() now gets run
I want the object to do this function and now having to be called by the script.
Thanks
EDIT
my_var is predefined in the class, __set ...
Am new to design patterns, could you recommend a open code base (preferably in java) that has design patterns used explicitly and elegantly. Reading up GOF has left me confused am looking for a project that used a few patterns that interacted with each other.
thanks.
...
Lets say I have a Phone number my classes need to validate and keep track of and for the most part a phone number is just a string so in an attempt to be DRY one would just create a Phone class and inherit from string. Since I can't do that what is the next best approach? Adding a string as a private member and overloading the equal/= ...