Все вопросы: [oop]

2 239 вопросов

похожие теги:
1
голосов
2ответов
289 просмотров

responsibility based modeling versus class reasons to change

In this text I read Be alert for a component that is just a glorified responsibility. A component is supposed to capture an abstraction that has a purpose in the system. It may happen that what appears at one moment as a meaningful component is really just a single responsibilit...

1
голосов
7ответов
216 просмотров

Learning more about Java

I would like to become really good at programming and in particular java and OO The catch is, that while I like programming and I work as a programmer, I'm not really passionate about being a programmer or programming in general. This leads to not feeling like doing any dev outside of work, whi...

15
голосов
1ответов
1514 просмотров

Should I use inheritance or composition?

I would like to keep this one short. I build a HouseA that has two rooms, say BedRoom and StudyRoom, both deriving from a base class called Room. BedRoom and StudyRoom have a same parent called House. Also, any room in a house can access any other rooms only through the parent. If BedRoom has to ...

5
голосов
3ответов
252 просмотров

Internals of "equals" in .NET

I have a foolish doubt.Generally "System.Object" implements "Equals". When I implements IEquatable interface i can give custom definition ( I believe so) to my "Equals". so the professor class implementation is equal to class Professor:System.Object,IEquatable since there are different d...

0
голосов
1ответов
318 просмотров

Hibernate SessionFactory

Why the examples about hibernate use SessionFactory interface instead SessionFactoryImpl class to open a session on the given connection?

1
голосов
3ответов
1066 просмотров

How does a JVM execute the Inheritance tree structure?

class Vehicle { public int wheels; public int lights; } class Car extends Vehicle { public int wheels =4; public int lights =2; public void lights_on( int lights) { //Code to onlights } } class BMWCar extends Car { public int wheels = 4; public int li...

7
голосов
3ответов
6975 просмотров

PHP runtime class modification

So I want to be able to add/remove class methods at runtime. Before you tell me that's horrible pratice in oop, it might be, but I don't really care. The reason I want to be able to do this is because I want the application to be very modular, so some plugin could extend some base class and add m...

0
голосов
2ответов
414 просмотров

Can (and should?) Zend_Auth return class as the Identity?

I have a class R00_Model_User, which, curiously enough, represents user as he is. Can $result->getIdentity() return me an object of this class? (Or maybe it's stupid?) (There is a factory method in R00_Model_User which prevents from duplicating objects. I'd like Zend_Auth to use it instead of...

3
голосов
8ответов
202 просмотров

How much responsibility should a method have?

This is most certainly a language agnostic question and one that has bothered me for quite some time now. An example will probably help me explain the dilemma I am facing: Let us say we have a method which is responsible for reading a file, populating a collection with some objects (which store ...

0
голосов
2ответов
95 просмотров

How to Properly Enforce Correct Usage of a Class Method?

Our current ORM solution uses Data Mappers to represent tables / views in the database which then return a Collection object that can be used to iterate through the retrieved records as Model objects. Between the Data Mapper and Model layers is a Repository layer that handles domain requests to t...

1
голосов
2ответов
533 просмотров

Events in an Inversion of Control (Dependency Inversion) system go which way?

Up or Down? I'm a very visual person. I'm thinking of my application as a hierarchy, where the top is the root and the bottom is a leaf. I'm also under the understanding that IoC containers are ignorant of their contained objects' responsibilities/functions. Instead, the contained objects know ...

3
голосов
4ответов
371 просмотров

Creating a collection of all classes that inherit from IBlahblah

Using reflection (i'm guessing?), is it possible to create a method that will return a collection of all objects that inherit from an interface named IBlahblah? public interface IBlahblah;

1
голосов
4ответов
273 просмотров

How to design collection in C#

I have a class MySet class MySet { ....... } This class will declare a reference to another type (i.e) class MySubSet { .... } The purpose of the type MySubset is to supply "subset id" and a collection of integers to the type MySet. Which one of the followings is the correc...

1
голосов
2ответов
227 просмотров

recreate instance in base class

I was wondering if it is possible to change the type of an instance of a derived class in it's base class to another derived class from the same base . following I will try to explain it in a code . public class ValueTypeClass { private string _Note; private Stri...

2
голосов
4ответов
252 просмотров

Simplifying Flex/AS3 code

I was programming in php for a while but it was all procedural-oriented. Now I have a project in Flex 3 and I made a simple script which animates (moves) few objects but I think that I am missing the point of object-oriented programming here because I am repeating some stuff over and over... Mayb...

2
голосов
4ответов
545 просмотров

Proper way to pass along many variables in an OOP design (PHP)

How would I properly pass along data to a class being referenced in this structure: -Head Index - PageBuilder - PageSection -Body -Foot I want to send lots of data to head, for example, but I would like to avoid this: new Pa...

4
голосов
6ответов
392 просмотров

How to set ID in Object Oriented Code

I'm a bit confused when it comes to Object oriented programming for say a 3 tier application. Here is just a small example of what I am trying to do (I will shorten the database design to make it simple). Assume I am making a ticket help desk system. A ticket has a description, a responsible p...

1
голосов
5ответов
622 просмотров

Using double negatives to test for conditions

To validate user inputs, I am unsure of which of two alternatives is better 1 isNull( Object input ) 2 notNull( Object input ) apache's commons lang library chose #2 but I am uncomfortable with double negatives. What do you say ?

1
голосов
3ответов
185 просмотров

Unit testing a method called during initialization?

I have a class like the following: class Positive(object): def __init__(self, item): self._validate_item(item) self.item = item def _validate_item(self, item): if item <= 0: raise ValueError("item should be positive.") I'd like to write a unit te...

1
голосов
3ответов
179 просмотров

Designing classes in C#

I know this must be a common question, but take a look: Here i have a test class: public class EmployeeClass { private int _id; private string _name; private double _salary; public int id { get{...} set{...} } public string name { get{...} set{...} } //and so on } The question is: for me, i...

0
голосов
5ответов
137 просмотров

Elegantly designing a method with 2 overloads, one accepts an object the other doesn't

I need to design a method that can potentially take as a parameter an object, if it doesn't then the method has to create a new object by itself. Is this a good way to do it? public void Method1(int companyId, int userId, int clientId) { Method1(null, companyId, userId, clientId); } public...

45
голосов
8ответов
66021 просмотров

Can I instantiate a PHP class inside another class?

I was wondering if it is allowed to create an instance of a class inside another class. Or, do I have to create it outside and then pass it in through the constructor? But then I would have created it without knowing if I would need it. Example (a database class): class some{ if(.....){ inclu...

1
голосов
3ответов
86 просмотров

changed object state after behavior that used the state

I want to give my previous question a second chance since I think I have chosen a bad example. The question is how I should deal with situations where an object still can change after I have used it to do something and the new state is relevant for what is being done. Example in pseudo-code: c...

9
голосов
6ответов
2946 просмотров

Why is method overloading not defined for different return types?

In Scala, you can overload a method by having methods that share a common name, but which either have different arities or different parameter types. I was wondering why this wasn't also extended to the return type of a method? Consider the following code: class C { def m: Int = 42 def m:...

2
голосов
3ответов
459 просмотров

A very basic question about the way GUI integrated with the Logic classes

assume i have a huge input form, which of course representing classes. i need this input to be loaded into the class's instances. this input obviously contains (some very complicated validation) checks, obviously the logic layer contains those input validation already. the question is what am i d...

22
голосов
6ответов
56416 просмотров

JavaScript: How to create a new instance of a class without using the new keyword?

I think the following code will make the question clear. // My class var Class = function() { console.log("Constructor"); }; Class.prototype = { method: function() { console.log("Method");} } // Creating an instance with new var object1 = new Class(); object1.method(); console.log("New returned...

14
голосов
4ответов
8672 просмотров

How do you manage database connections in php?

So recently I've really started to use php actively, and I need some insights on different ways to use database connections. At first I just used the simple mysql_connect(): <?php $connection = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error()); mysql_select_db(DB_DB, $c...

8
голосов
6ответов
1629 просмотров

God object - decrease coupling to a 'master' object

I have an object called Parameters that gets tossed from method to method down and up the call tree, across package boundaries. It has about fifty state variables. Each method might use one or two variables to control its output. I think this is a bad idea, beacuse I can't easily see what a meth...

0
голосов
2ответов
71 просмотров

changed object after storage or object-state used

Example: class UserStorage { public function addUser(User $user) { //saves to db } } class User { public function setName($name); } What if I add a user to the user storage and later change that user object? In this case you might argue that user objects only should be stored on __des...

1
голосов
1ответов
299 просмотров

How to implement concept of .Net RIA Service (Single App Logic) in Asp.Net MVC?

First, let's see the following picture that explain the concept of .Net RIA Service. (source: nikhilk.net) As you see, the application has app logic (business rule) that can be implemented both server side (databases + Repositories + external services) and client side (asp.net web page + Sil...