Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Adahn the nameless
Jul 12, 2006
I have a C# question.

Suppose I have a class Shape, with a private string member name and a public member function (method?) printName which simply returns name. I then create 3 derived classes: Square, Circle, and Triangle, each with a private string member name.

If I call printName on derived class objects, will it function as intended? Or do I need to define a printName in each of the derived classes?

Adbot
ADBOT LOVES YOU

Adahn the nameless
Jul 12, 2006
This is more or less what I have:
code:

/// <summary>
/// This program will define a virtual Shape class, and 3 child classes:
/// Triangle, Square, and Circle. It will create an array of those shapes, and
/// iterate through the array, printing each shape using a virtual function that each derived class overrides. 
/// </summary>

public class Shape
{
    private string name;


    //prints the name of each shape
    public string printName()
    {
        return name;
    }

   
    public virtual double area()
    {
        return 10;
    }

}

public class Square : Shape
{
    private string name;
    private double side;

    //constructor
    public Square(double s)
    {
        name = "Square";
        side = s;
    }

    //function to calculate area of square
    public override double area()
    {
        return side * side;
    }

}
There's obviously more to the program, but I think this will give you an idea of what I'm trying to say. The goal here is just to write a program that implements class inheritance and polymorphism.


edit: I'm just reading a tutorial on properties now. I guess the C# preferred way of returning the name is with

code:
get 
{
     return name;
}

Adahn the nameless fucked around with this message at 17:38 on Aug 7, 2010

Adahn the nameless
Jul 12, 2006

gibbed posted:

I prefer abstract properties in this situation:

However, what's name for? sounds like you could just use .GetType().Name or so if that's all it's for?

Thanks for your help.

I'll have to look up how .GetType().Name works. I used abstract properties and it worked. But I have a few questions: What's the difference between declaring something abstract and declaring it virtual? Also, I think I could have made Shape an Interface because I don't plan on instantiating any Shape objects. Would that have been better than making it an abstract class?

Adahn the nameless
Jul 12, 2006
I'm trying to create an adorner in WPF that will let me resize a FrameworkElement in a Canvas. So I've got my ResizableAdorner and my ResizableThumb. My question is: Do I need to create default styles for both controls?

The way I envision it, the thumb lies on the adorner layer, and when some criteria are met, I display the layer, otherwise it's hidden.

Adahn the nameless
Jul 12, 2006
I have a class that has a Point structure, _dragStartPoint, as a member variable. I can't figure out this line of code:
code:
_dragStartPoint = new Point?(e.GetPosition(canvas));
Since structures pass by value, wouldn't it be equivalent to say
code:
_dragStartPoint = e.GetPosition(canvas);
e.GetPosition(canvas) returns a Point, if that wasn't clear.

Adahn the nameless
Jul 12, 2006

2banks1swap.avi posted:

When ran locally, our web project has some pretty slow loads at times, and most of it is actually generating markup, apparently - 11.6 seconds in total to just load a drat page!

A lot of this is an issue with caching and probably hitting a service too many times because of a not so great design thing we had to do: a lot of our selects/drop down lists/whatever ya call it is generated every time you load a page, using enums from a database which give descriptions that match to integer values which are then stored with some biz object as part of the project, yadda yadda yadda.

This is so done because the client likes to define poo poo in the database, and the only employees they have themselves are DBAs. We do everything but DBA stuff for the client, more or less.

The enums for our selects come from a controller we set up that hits the database table containing them, and even has a parameter to filter out what we'd need so we get as little data as possible, but it's still slow; even without filtering things the actual size of the data should not take eleven seconds to fart out of the database and be razored up into some markup and burped into the browser.

One thing that might explain things is that each call is synchronous, so until one finishes the other can't start. Since we're going through a not so fast VPN to a database, if each one is 200-500ms long it wouldn't take too many to add up to 11 seconds, but that's still stupidly slow.

I don't know poo poo about the admin/ops side of things, or IIS, or caching - if this happens, how do you go about fixing it?

You're .Net on MVC, right? Assuming I understand your problem, a relatively easy solution:
Cache the lookup data in memory on the server using .Net's memory caching api. (I'm assuming you aren't talking about a ton of records here). This is per process, so it's per app pool in your case, but if it's just some lob app that farts data on a screen I doubt it'll be an issue. I don't know if your team has authority to deploy an external cache that more than one process can hit. That'll cut down on the db requests. If you wanted to get fancy, you could also cache in the browser local storage to cut down on the http requests.

Adahn the nameless
Jul 12, 2006

gariig posted:

First I would find out what is taking so long. You need to know what is wrong before you fix it. You might end up highly optimizing a part of your application that's only 50ms and missing the 2000ms calls elsewhere. I'd start with the Visual Studio Performance Profiler to find the hot spots in your code. You might need to get whoever is hosting the database involved because it could be unoptimized queries (SQL Server Profiler). Once you know the hot spots you can start to develop ways of overcoming them. It could be using async/await to make multiple slow web service calls in parallel. It might be caching (ASP.NET caching, Memcache, etc). Maybe you need to put a web service next to the database so you can send one request to the web service for all of the data needed to build a website.

All of that is really good advice. I was assuming you'd profiled and determined that the db queries were causing the slowdown. If you haven't, definitely gather solid evidence before you take prospective solutions to your team. Also, I missed that you're only seeing this issue in development? If it's not slow in production, caching is probably overkill because of the amount of complexity you're adding. Are you connecting to a remote database over a vpn or something?

Adbot
ADBOT LOVES YOU

Adahn the nameless
Jul 12, 2006
I'd mention biz spark and dreamspark as ways to grab free versions of ms paid products.

  • Locked thread