oop

What are the known "gotchas" with regards to the Chain of Responsibilty pattern?

I have been finding myself using the Chain of Responsibility pattern often (3 times is often for me) in my current project and I'm wondering if I have become a little over-enthusiastic about the solution. Specifically, I have been using the Apache Commons chain project. So, far I have been quite impressed by how it has simplified a numbe...

How to expose only one particular class from an assembly?

Suppose assembly Assembly1.dll contains 3 classes: Class C1, C2, C3. I want to expose only class C1 to the outside world. Classes C2 and C3 will not be accessible. How to acheive this? Note: Making classes C2 and C3 private is not an option as this will make them unaccessible inside the assembly itself. ...

Why is System.Object not abstract in .NET?

I know it is commonly used as a lock object, but is that really sufficient reason? What is the meaning of object o = new object(); An non-abstract class is something that represents actual objects. "asdasdf" is a string. What actual instance can there be of "object" class? It doesn't make sense, OOP-wise. My question is if there is so...

UML Class Diagram Resources

Does anyone have any good resources for refining my skills in developing class diagrams? Would like any strong tutorials in UML 2.0 ideally, but searches seem to be returning poor results. Also currently revising for a final year exam and really want to try and get my teeth into a practice paper with a model answer, I've searched high a...

What OOP design decision will suit the situation of protocol in client/server app?

I am writing a client/server app in C++ and need to realize simple protocol to sent and receive data correctly. I have a class for server protocol which can convert the message to my format and then convert it again from this format. That what is server-side protocol looks like: class BaseProtocol { protected: int NumberOfBytesInPac...

Implementation in global functions, or in a class wrapped by global functions

I have to implement a set of 60 functions, according to the predefined signatures. They must be global functions, and not some class's member functions. When I implement them, I use a set of nicely done classes provided by 3rd party. My implementation of most functions is quite short, about 5-10 lines, and deals mostly with different ac...

How many objects are too many?

When designing an application, does there come a point where you have too many objects? How do you determine when you've crossed the line of granularity in your object model? ...

How to add collation to Linq expressions?

How to implement method for IQuariable like below: var trash = (from a in ContextBase.db.Users orderby a.FirstName select a).ToCollatedList(); In a result I want to see SELECT * from [User] ORDER BY FirstName COLLATE SQL_SwedishStd_Pref_Cp1_CI_AS ASC Thanks. ...

Polymorphic Domain Objects Based On Data Mapper

I have a basic domain object, say like Person or Campaign or Event that is represented by a single table in the database. However, I also have more complicated versions of these objects say like a PersonCampaign or PersonEvent or even CampaignEvent that could theoretically extend one of the base objects. However, for a number of reasons...

Using the Single Responsibility Principle in the "real world"

I basically want to get an idea of the percentage of people who think it's reasonable to use the Single Responsibility Principle in real-world code and how many actually do. In Podcast #38 Joel talks about how useless this OOP principle is the real world; and further that this demonstrates how people like Uncle Bob have likely not writt...

OOP approach for inventory system

We're developing a system to track inventory at our field offices. At its core, the system will have a list of "Assets" - things like Bikes, Computers, Tents. Each Asset goes through states like "Active", "Lost", "Checked Out", "Inventoried". Some states have additional information, like "Checked Out To" or "Inventoried By". So, I'm th...

What's the best VB.NET open source project you've seen?

I'm looking for open source projects written in VB.NET that utilize OOP/design patterns/unit tests to learn from. What's the best you've seen? ...

Flex/ActionScript3: keyword "with" hides misspelled property names

In Flex 3, var anInstance : MyClass = new MyClass(); with (anInstance) { property1 = "fred"; property2 = 5; propert3 = 7; } does NOT flag "propert" as a non-existent property name. I thought this was a remainder of the evil JavaScript object behavior (referring to a property name of an object implicitly creates it), but i...

Pimpl idiom with inheritance

I want to use pimpl idiom with inheritance. Here is the base public class and its implementation class: class A { public: A(){pAImpl = new AImpl;}; void foo(){pAImpl->foo();}; private: AImpl* pAImpl; }; class AImpl { public: void foo(){/*do something*/}; }; And I want to be able to create the der...

Initialize base class in .NET

How do I go about if I need to initialize an object's base with existing object? For example, in this scenario: public class A { public string field1; public string field2; } public class B : A { public string field3; public void Assign(A source) { this.base = source; // <-- will not work, what can I do here...

Dynamically loading multiple JS scripts where scripts are all described identically

I have an interesting problem that I'm unsure how best to solve. I have JS scripts which contain the following: var obj = new namespace.MyObjectName("key", [12, 11, 22, 33, 454, 552, 222], [33, 22, 33, 11, 22, 222, 111]); namespace.MyObjectName = function(keyName, data1, data2) { this.myData1 = data1; this.myData2 = data2; ...

Modelling an elevator using Object-Oriented Analysis and Design

There are a set of questions that seem to be commonly-used in interviews and classes when it comes to object-oriented design and analysis. This is one of them; unfortunately, my OOP professor in college never actually gave an answer to it, and so I've been wondering. The problem is as follows: design a basic set of objects/methods to be...

C++ virtual function from constructor

Why the following example prints "0" and what must change for it to print "1" as I expected ? #include <iostream> struct base { virtual const int value() const { return 0; } base() { std::cout << value() << std::endl; } virtual ~base() {} }; struct derived : public base { virtual const int value() const { ...

how to fetch just 1 row from an object

this query will just one row as a result myDataContext db = new myDataContext(); var query = from u in db.users where u.userId == myUserId select u; I usually get the result out from the "query" object by using "foreach" foreach(var i in query){ username = i.username; } ...

Instantiating a queue as a class member in C++

Suppose I need to have a class which wraps a priority queue of other objects (meaning the queue is a member of the class), and additionally gives it some extra functions. I am not quite sure what the best way is to define that vector and, mainly, how to instantiate it. Currently I have something like this in the header file: // in Som...