The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Refactoring - OOP Example from VB.NET to C#

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
John Papa

Posts: 66
Nickname: papajohn
Registered: Apr, 2005

John Papa is .NET lead developer/architect/author
Refactoring - OOP Example from VB.NET to C# Posted: Apr 26, 2005 9:17 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by John Papa.
Original Post: Refactoring - OOP Example from VB.NET to C#
Feed Title: John Papa
Feed URL: /error.htm?aspxerrorpath=/blogs/john.papa/rss.aspx
Feed Description: .NET Code Samples, Data Access, Patterns and Other Musings
Latest .NET Buzz Posts
Latest .NET Buzz Posts by John Papa
Latest Posts From John Papa

Advertisement

OK, I don't want to leave out the C# developers from this VB.NET OOP example that Raymond posted recently. So here is one way to accomplish this code in C#.

 

Inheritence, Interfaces, and OOP (oh my!)
public class foo
{
	public static Int32 GetNumberOfRequiredTokens(IPerson person)
	{
		return person.GetNumberOfRequiredTokens();
	}
}

public interface IPerson
{
	Int32 GetNumberOfRequiredTokens();
}

public abstract class Person : IPerson
{

	public Person()
	{
	}

	private Int32 baseTokenAmount = 1;

	protected Int32 Tokens
	{

		get
		{
			return baseTokenAmount;
		}

	}

	public abstract Int32 GetNumberOfRequiredTokens();
}

public class Child : Person
{
	public override Int32 GetNumberOfRequiredTokens()
	{
		return base.Tokens;
	}

}

public class Adult : Person
{
	public override Int32 GetNumberOfRequiredTokens()
	{
		return base.Tokens * 3;
	}

}

public class Infant : Person
{
	public override Int32 GetNumberOfRequiredTokens()
	{
		throw new TooYoungException();
	}

}

public class TooYoungException : Exception
{
}

Read: Refactoring - OOP Example from VB.NET to C#

Topic: Mid Atlantic Code Camp sessions posted Previous Topic   Next Topic Topic: Grande Cwalek!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use