I'm just curious, are there any diferences between this two ways of field initialization ? When to use wich one ?
Fist way
public class Class1
{
private SomeClass someclass;
public Class1()
{
someclass = new SomeClass(some arg);
}
}
Second way
public class Class1
{
private SomeClass someclass = new SomeClass(s...
What is real difference between Class and Structure when you are dealing with Object Oriented Programming. This question is asked many times during my interviews for SE.
Some people says that there is only one difference:
Structure members are public by default and Class members are private by default.
Some says there are many differen...
In Inheritance concept, i have a static method in super class and i am inheriting that class to one sub class. In that case the static method is inherited to sub class or not?
...
I am having trouble understanding ORM in Ruby on Rails. From what I understand there is a 1:1 relationship between tables/columns and objects/attributes. So every record is an object.
Also what exactly is a Model? I know it maps to a table.
What I'm really after is a deeper understanding of the above. Thank you in advance for your help
...
I'm having a hard time making a design decision
I have a class in python, that processing form data, this data is very similar to other form data, and so I'm refactoring it into it's own object so it can be reused by the other classes.
The delima is weather to make this formprocessor a member of the classes or a parent of the classes.
...
For getting all the defined class attributes I try to go with
TheClass.__dict__
but that also gives me the special attributes. Is there a way to get only the self-defined attributes or do I have to "clean" the dict myself?
...
I've got a bunch of functions that I want to move into a class. They're currently split into a couple of fairly long files. I'd prefer not to have one 2500 line file, but as far as I can tell, you can't use include to split a class up into multiple files. In theory, I could group the functions in different classes, but they're closely re...
I have the following layout:
Entities:
Order
OrderItem
DAO classes:
OrderDAO
OrderItemDAO
So I have POCO classes, and DAO classes.
Now I want to encapsulate the above entities into another entity, so I can have methods like:
x.AddItem(OrderItem item)
x.CalculateTotal();
x.CalculateShipping();
x.Charge();
What would this type...
(Note: this is related to this question, but I think it could have been written more clearly, so I'm trying again -- my update only helped to a limited extent.)
I've inherited some code that creates a complex form with numerous sections, and lots of possible views, depending on a number of parameters. I've been working with it for a whi...
The definitions of "abstraction" and "encapsulation" seem very similar to me. I always confuse these terms. Please, clarify the difference by showing examples.
...
I see that in Ruby (and dynamically typed languages, in general) a very common practice is to pass a hash, instead of declaring concrete method parameters. For example, instead of declaring a method with parameters and calling it like this:
def my_method(width, height, show_border)
my_method(400, 50, false)
you can do it this way:
de...
This should be obvious, but I'm getting a bit confused about PHP variable scope.
I have a variable inside a Constructor, which I want to use later in a function in the same class. My current method is this:
<?php
class Log(){
function Log(){
$_ENV['access'] = true;
}
function test(){
$access = $ENV['access'];
...
Hi there,
Can anyone help? I have the following object in javascript... from what i understand each "INSTANCE" of my calendar will have its own variables.
My question is i need to insert a method/function name called "InitilizeHolidays" this needs to add to an array but the details need to be same in all instances ... I was thinking ab...
I have a controller which has several methods which should all share common informations. Let's say my URI format is like this:
http://server/users/id/admin/index
http://server/users/id/admin/new
http://server/users/id/admin/list
http://server/users/id/admin/delete
I need to retrieve some informations from the database for id and have...
In PHP 5, how do I figure out what class is an object instance of? I know I can compare with the "instanceof" operator, but I don't seem to find how to proceed when the Class name is unknown.
Thanks in advance! :)
...
class Class1(object):
...
class Class2(object):
...
class Class3(object):
...
class A(object):
def _methA(parm1, parm2)
...
def _methB(parm1, parm2)
...
def _methC(parm1, parm2)
...
def manager(parm1, method, params)
...
if parm1.__class__.__name__==Class1.__name__...
I'm looking for some relatively simple, well-written object-oriented code to learn from. I'm a beginner.
So far I have looked at WordPress and Serendipity. WordPress is huge and Serendipity is not object-oriented. To make things worse, both still support PHP4.
Any recommendations? Thanks!
...
So I have an order manager class that looks like:
public class OrderManager
{
private IDBFactory _dbFactory;
private Order _order;
public OrderManager(IDBFactory dbFactory)
{
_dbFactory = dbFactory;
}
public void Calculate()
{
_order.SubTotal
_order.ShippingTotal
...
So you've got an interface and an abstract class that implements a subset of the methods in the interface. You've also got some classes that inherit the abstract class and give implementations of the methods the abstract class doesn't give.
So what's the best practice here? I'm talking about issues like:
1) Should the abstract class im...
It's considered a bad idea/bad design, have a class with a constructor accepting a reference, like the following?
class Compiler
{
public:
Compiler( const std::string& fileName );
~Compiler();
//etc
private:
const std::string& m_CurrentFileName;
};
or should I use values?
I actually do care about performance.
Thank you in adva...