oop

Is this an anti-pattern?

The situation is this: You have two classes that both implement the same interface and both classes work together to complete some business process. For example networkUserManager and localUserManager implement IUserManager which has a method getUser(). networkUserManager.getUser() puts a request to get a User on the queue and returns...

What is the best way, using the "State" design pattern, to change states?

My current understanding of the State design pattern is basically this: Encapsulate all of the behavior of an object in a particular state in an object. Delegate requests to the "Current" state object. My question is: What is the best way to handle state transitions? In my case, it is likely that "Current" state object will be the one...

How do I copy an instance of an object?

I'm trying to write some code that populates a List (actually, it's a series of Lists, but we can pretend it's just one List). The idea is to add an IPackage to the List for the total quantity of IPackage on order. See the following code: ParseExcel pe = new ParseExcel(); Pinnacle p = pe.ParsePinnacleExcel(); R...

How to inherit from a class in javascript?

In PHP/Java one can do: class Sub extends Super { } And automatically all public/protected methods, properties, fields, etc of the Super class become a part of the Sub class which can be overridden if necessary. What's the equivalent for that in Javascript? ...

Converting a class from Mootools to jQuery or classic javascript

Following Mootools class helps developer to draw a circle overlay on Google Map using Google Maps API v3. I'm using jQuery in my projects and entry-level knowledge in Object-oriented javascript. In Google Maps API v2, this is very easy but API v3 currently haven't built-in methods for drawing circles on map. Plus, in API documentation, ...

C++ classes , Object oriented programming

I have a very simple class named person which is given below , I have a problem with only two functions , i.e setstring () function and setname() function , I am calling setstring() function from the setname function. The only problem is when in the main function I write Object.setname(“Zia”); The result is ok as shown in the output s...

basic question c++, dynamic memory allocation

Suppose I have a class class person { char* name; public: void setname(const char*); }; void person::setname(const char* p) { name=new char[strlen(p)]; strcpy(name,p); name[strlen(p)]='\0'; } My question is about the line name=new char[strlen(p)]; suppose the p pointer is pointing to string i.e “zia” , now strlen(p) will return 3 it...

Memory Allocation Question?

public static void Main() { Test t1 = new Test(); } when will t1 (reference variable) will get memory, at compile time or run time. I think it should be run time. But when I put a breakpoint at Main Method and Put a Watch for t1, it was null. So it means t1 was in memory. Please correct me If I am wrong. Edit: I h...

Properly design a code editor application

I'm working on personal project which is basically a code editor. Imagine standard File menu with menu items New, Open, Save, Save As, Save All, Close, Close All. I'm stuck with proper design. Currently I have: A Document class which represents a document - code editing control, respective tab in tab bar and various properties such a...

Preferred Design Pattern for Interface Locking

I have an application that performs various tasks that can take up to a minute each. I wanted to make sure that I was setting the application to a "working status" in a consistent way, so I set up a class (we'll call it "LockI") that when initialized records the current state of various things (the cursor, the status bar, screen updating...

Create a class MAT of size m x n

Create a class MAT of size m x n. Define the following matrix operations for MAT type objects a. Addition b. Subtraction c. Multiplication. ...

C++ Compiler Error: No matching function for call

Look at the following code. What is wrong with it? The compiler gives the this error: In copy constructor person::person(person&)': No matching function for call toperson::copy(char*&, char*&)' candidates are: void person::copy(char*&, const char*&) " Here is the code: class person { public: person(); person(person ...

How can I get up to speed about Perl's latest object-oriented capabilities?

I have not done Perl for about 8 years and now I'm going into project that's heavily utilizing object-oriented Perl so I need to resharpen my Perl skills and do it quickly. During these past years I mainly did all sorts of Java development and some PHP. I'm very good at OO and I'm not a novice programmer by any remote extent. So here c...

Using a DAO within another DAO - good or bad practice?

This might be something very trivial, but I am a novice with some Object-Oriented patterns. Put simply, is it a bad practice to use methods from one DAO in another DAO? I am trying to create an entity within a DAO and find it very hard to create that entity using just that DAO. So, is it ok to use other DAO methods within the other DAO?...

Using STL Allocator with STL Vectors

Here's the basic problem. There's an API which I depend on, with a method using the following syntax: void foo_api (std::vector<type>& ref_to_my_populated_vector); The area of code in question is rather performance intensive, and I want to avoid using the heap to allocate memory. As a result, I created a custom allocator which alloc...

Getting started with software design using MVC, OO, and Design patterns

NOTE: This question has been updated to provide more detail and insight than the previously. UPDATE: I just want to say thank you to everyone who responded. I'm still pretty much in the dark on what design pattern would work best for the Widget. Perhaps one of the Factory or Builder patterns? I am just getting started on a new proje...

Why java.lang.Object is not abstract?

Why is the Object class, which is base class of 'em all in Java, not abstract? I've had this question for a really really long time and it is asked here purely out of curiosity, that's all. Nothing in my code or anybody's code is breaking because it is not abstract, but I was wondering why they made it concrete? Why would anyone want a...

How to force overriding a method in a descendant, without having an abstract base class?

Question Heading seems to be little confusing, But I will Try to clear my question here. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { public abstract class Employee { private string name; private int empid; BenefitPackage _BenefitPa...

what's interface vs. methods, abstraction vs. encapsulation in C++

Hi, I am confused about such concepts when I discussed with my friend. My friend's opinions are 1) abstraction is about pure virtual function. 2) interface is not member functions, but interface is pure virtual functions. I found that in C++ primer, interface are those operations the data type support, so member functions are in...

What all Design Patterns can I use ?

1. I need to build a "Web Service Server (Simulator)" which generates the xml files and also sends async calls to the client for notification. At this point, I am writing a code to generate dummy XML files which will be used for testing (FileGeneratorClass-- builder)? 2. Also, can I implement this in a way that I do not have to write a...