Contents tagged with Object Oriented Programming
-
C# MVC3 Razor Entity Framework & LINQ Custom Membership Provider with Custom Role Provider
This C# project demonstrates how to create an MVC3 Razor Entity Framework & LINQ Custom Membership Provider with Custom Role Provider. Perhaps you are working with a legacy database or you prefer working with a database that uses numeric identity keys instead of Guids. The example UserProfile table in this project uses an integer UserId as the primary key and various other fields that aren't in the default ASP.NET User table. Use the Log On Link in the project and the Register link to create your own account.
-
C# Custom LinkedList Main() method - Learning C# - Part 7
When we create a console application, our Program class and Main() method are setup by default. Our Main() method is defined as a static method. The "static" keyword instructs the system to create only one instance of the method regardless of how many instances of its class are created.
In our Main() method, we create a new LinkedList and name it ListItems. Rather than using this to create nodes, as we did with the Head and Next nodes which were also LinkedLists, we are going to use this to call the methods defined in the LinkedList class. When we type "ListItems." intellisense will kick in and display all public methods defined in our LinkedList class. Now we can use this to Push() inventory items to our list, PrintFifo() or PrintLifo(), PopFifo() or PopLifo(), and FindItems(). We want to follow up with Console.ReadLine(); to keep the text from zooping off the screen and returning to the program. Console.ReadLine(); will allows us to stop and wait for input, thus allowing us to see our results.
In our example above, we print our items in LIFO order, then we remove the top and bottom nodes, then print our remaining items in FIFO order. Then we search for items in the "Electronics" category and display them to the screen. Play around with it, put in break points and step through the code and see what is happening. -
C# Custom LinkedList FindItems() method - Learning C# - Part 6
In this "for" loop, we start with the Head node, and as long as the node is not null, we loop through the nodes, reassigning our current node to the node as stored in the "Next" node. As we loop through the nodes, we see if the value of the item or category match the search criteria, and if so, we print the node values to the screen. If an item is found, we set the boolSuccess value to true and at the end of the method, we pass this back to the calling method.
In our next article, we will look at our Main() program and how to use our new LinkedList class. -
C# Custom LinkedList PrintLifo method and C# Operators - Learning C# - Part 4
In our next article we will print our linked list in first in first out order and create a helper method GetNode() which allows us to retrieve a specific node by position. -
C# Custom LinkedList Push and Pop Methods - Learning C# - Part 3
Removing our node from the "first in" node on the list is much simpler. We simply decrement our size by one so that when we traverse through the nodes we never hit it.
In Part 4 of our series we will Print our list to the screen. -
C# Custom LinkedList Derived Classes, Constructor Initializations - Learning C# - Part 2
We create two self-referencing members, meaning the type is the same name as their class: "private LinkedList Head" and "private LinkedList Next". The first points to the most recent node added to the list or the top of the stack. The second points to the next node on the list that was just previously added so that we can traverse through the list. Once we traverse to the next node, it again has its own Next node, to point to the previous node, and so forth.
The "private int size" statement defines an integer used to keep track of how many records are in the list.
Next we define our constructor: "public LinkedList()." "Constructors: are class methods that are executed when an object of a class or struct is created. They have the same name as the class or struct, and usually initialize the data members of the new object."
True to our definition, we initialize the Head and Next to null. We set our inventoryCategory to empty using "string.Empty." We could have just as easily set our inventoryCategory to empty by assigning it a value of "" (2 quote marks).
We set our size to 0. Our list will be 1 based and increment to 1 when the first node is added.
In Part 3 of our series, we will define our Push and Pop methods. -
C# Custom LinkedList Console Application and Abstract Base Class and Method - Learning C# - Part 1
One of the key concepts of object oriented programming is Inheritance along with Abstraction. Inheritance allows you to create a class that allows you to reuse behaviors and definitions.
We first want to create a base class, Inventory. That means that it is a parent class. To make the Inventory class a base class, we use the keyword "abstract." This means any abstract methods defined in the base class must be implemented in the inherited or derived class. If you do not wish to require implementation, use the "virtual" keyword which means that the derived class "can" override the method with its own implementation, but does not have to.
In our above example, we have an abstract method "Category" and an implemented string and method: inventoryItem and Item(). Notice we do not define an implementation for the Category() method. The implementation must be defined by the derived class.
Our linked list will use the Item() and Category() for retrieving our Inventory item names.
In Part 2 of our series, we will setup our LinkedList derived class and define our properties and setup our constructor. -
Object Oriented Programming Guidebook in ASP.NET (OOP)
Think PIE and make mine cherry. (Java uses A-PIE and includes Abstraction.)
-
Instance versus Class (or Static) Members
If you're new to object oriented development, this web page I found on "Instance and Class Members" will come in handy for you.