-2

So I've been assigned to talk about adding new code routines into a program such as self contained functions and new classes, yet I haven't actually been taught this kind of programming terminology yet. I've tried looking online everywhere but it doesn't really explain it well enough.

The questions that I'm a little confused by are the following:

What are self contained functions in C#? (Code examples would help :3)
And how could it be added in a object-oriented way?

Help would be very appreciated, thanks.

SirTiggs
  • 105
  • 1
  • 2
  • 10
  • Are you supposed to give a presentation for a class you're taking? Read http://www.blackwasp.co.uk/ObjectOrientedConcepts.aspx. – CindyH Apr 01 '15 at 15:42
  • I *guess* that self-contained functions are named [`anonymous methods`](https://msdn.microsoft.com/en-us/library/0yw3tz5k.aspx) in c#. They are used to run a block of code before returning or passing the result to another function, they should be used where you run code once, otherwise you should prefer named functions. – SaschaM78 Apr 01 '15 at 15:43
  • @CindyH It's for a task for college. – SirTiggs Apr 01 '15 at 16:02
  • 1
    The short answer is that "self-contained function" isn't standard terminology, so nobody knows what it means except for the person who used that phrase. You need to ask for clarification. – Joe White Apr 01 '15 at 16:41

2 Answers2

4

Self-contained functions and classes and object-oriented are all pretty much the same thing at the high level you're talking about.

http://en.wikipedia.org/wiki/Object-oriented_programming

I'm guessing that your code base is a mess, with functions using global variables, and giant code files. The goal is to make each item do only one thing. So instead of a function called "Run" which is 500 lines long, you should instead have a function called "Run" which then calls functions "GetRecentData", "CheckDataForErrors", "ReportErrors", "ProcessValidData", and "ReportSuccess". This means that when you need to change the definition of error data, for example, all the related code is neatly in "CheckDataForErrors".

This is a huge topic and you are in way over your head. I'd recommend an object oriented tutorial such as this http://www.blackwasp.co.uk/csharpobjectoriented.aspx or one of many others.

CindyH
  • 2,986
  • 2
  • 24
  • 38
  • I couldn't agree with you more, the person that set this assignment for us isn't exactly the best lecture I've had. Cheers for help/links. – SirTiggs Apr 01 '15 at 16:03
3

I would percieved self-contained functions as methods that have no outside dependencies (i.e. member variables, properties, etc.)

Translated, methods that do not rely on state.

Just a guess though...

Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118