CSC/ECE 517 Fall 2012/Table Of Contents: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 40: Line 40:
[http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2012/ch1b_1w56_ms#Instance_Variables Instance variables] in ruby are defined.[http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2012/ch1b_1w56_ms#Instance_Methods Instance methods] and [http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2012/ch1b_1w56_ms#Accessor_Methods Accessor methods] are explained briefly along with examples.
[http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2012/ch1b_1w56_ms#Instance_Variables Instance variables] in ruby are defined.[http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2012/ch1b_1w56_ms#Instance_Methods Instance methods] and [http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2012/ch1b_1w56_ms#Accessor_Methods Accessor methods] are explained briefly along with examples.
Class variables and class methods in Ruby are defined [http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2012/ch1b_1w56_ms#Class_Variables_and_Class_Methods here].The basic syntax to declare them as class variables and instance variables is also given.
Class variables and class methods in Ruby are defined [http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2012/ch1b_1w56_ms#Class_Variables_and_Class_Methods here].The basic syntax to declare them as class variables and instance variables is also given.
Ruby [http://en.wikipedia.org/wiki/Mixin Modules] are similar to classes in that they hold a collection of methods,constants and other module and class definitions.Modules definition is similar to classes just that we use the keyword module instead of the class keyword.Unlike [http://en.wikipedia.org/wiki/Object-oriented_programming classes], [http://en.wikipedia.org/wiki/Object-oriented_programming objects] cannot be created based on modules nor can it be sub classed.However, it can be specified that the functionality of one module should be added to another class, or a specific object.
Uses and examples of modules are given [http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2012/ch1b_1w37_ss#Uses_of_modules here].
The most interesting fact about the use of modules is to define [http://en.wikipedia.org/wiki/Mixin mixins]. When a module is included within a class,all its functionality becomes available to the class.Modules can contain [http://en.wikipedia.org/wiki/Method_(computer_programming)#Class_methods class methods] and [http://www.daniweb.com/software-development/java/threads/303430/what-is-instance-method instance methods]. Mixins are different from #include and multiple inheritance and this is demonstrated [http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2012/ch1b_1w37_ss#How_mixinsis_different_from_.23include_and_multiple_inheritance.3F here].
Namespace in [http://en.wikipedia.org/wiki/C%2B%2B C++] is similar to modulesIn general, a [http://en.wikipedia.org/wiki/Namespace namespace] is a container for a set of identifiers (names), and allows the disambiguation of homonym identifiers residing in different namespaces.[http://en.wikipedia.org/wiki/Namespace Namespace] usually group names based on their functionality. Usage of namespaces and its example is given [http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2012/ch1b_1w37_ss#Steps_involved here].
Multiple inheritance in C++ similar to mixins.You can derive a class from any number of base classes. Deriving a class from more than one direct base class is called [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance]. An example is given [http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2012/ch1b_1w37_ss#Example_4 here].
Interfaces in JAVA is similar to mixins.A [http://en.wikipedia.org/wiki/Java_(programming_language) Java] interface defines a set of methods but does not implement them.A class that implements the [http://en.wikipedia.org/wiki/Interface_(Java) interface] agrees to implement all of the methods defined in the interface, thereby agreeing to certain behavior, thereby implementing [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance].
Properties of an interface are:
*An [http://www.codeproject.com/Articles/10553/Using-Interfaces-in-C interface] is implicitly abstract. You do not need to use the abstract keyword when declaring an interface.
*Each method in an interface is also implicitly abstract, so the abstract keyword is not needed.
*Methods in an interface are implicitly public. 
An example is given over [http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2012/ch1b_1w37_ss#Example_5 here].
[http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2012/ch1b_1w37_ss#Comparable Comparable] and [http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2012/ch1b_1w37_ss#Enumerable Enumerable] are commonly used mixins.
[http://en.wikipedia.org/wiki/Regular_expression Regular expressions] are extremely powerful.[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby]was built as a better [http://en.wikipedia.org/wiki/Perl Perl] hence it supports regular expressions.
[http://en.wikipedia.org/wiki/Regular_expression Regular expression] is sort of a string used to match to other strings.In ruby regular expressions are written in the format /pattern/modifiers where pattern is the regular expression and modifiers are the series of characters specifying the various options. More on regular expressions can be found [http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2012/ch1b_1w37_ss#Regular_Expressions here].


=Code Reuse=
=Code Reuse=

Revision as of 02:16, 11 November 2012

Introduction

This wiki page will give you the outline of the topics from Wiki 1a and 1b. A brief introduction to the topics covered(in 1a and 1b) and the links to the appropriate topic is available on this page.

Object Oriented Programming

Object-oriented programming (OOP) is a programming language model organized around "objects" rather than "actions" and data rather than logic. An introduction to Object Oriented Programming and its primary concepts like abstraction,polymorphism,encapsulation and inheritance are explained here.Features and advantages of Object oriented programming is given here. Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. Functional programming decomposes a problem into a set of functions.It is the opposite of object oriented Programming. Advantages of functional programming are given here. We can perform functional programming on an object-oriented programming language because of the following reasons:

  • Object can have constant state.
  • Method can depend only on its arguments and context available at method definition time.

Combining both of these paradigms will not only provide us a robust design structure, but also will enable the programmers to develop solutions to complex problems quickly and effectively.More details can be found here.

Some of the basic features of Functional Programming which can be combined with Object Oriented paradigm are:

A number of programming languages support mixing of both functional and object-oriented code. Three of these (Scala, Ruby, and Conjure), are described in more detail here.

Multiple Inheritance is one of the features of a few Object-oriented (OO) languages in which a class inherits properties (variables & methods) from more than one parent class . The former is called a sub or child class and the latter is called a super class or ancestor class. Here are the usage guidelines of multiple inheritance.A real world example of multiple inheritance is given here. C++ supports multiple inheritance. A detailed explantion is given here. JAVA doesn't support multiple inheritance but with the use of the concept called interface, multiple inheritance can be simulated. A more detailed explanation is available here. Ruby doesn't support multiple inheritance but provides a similar feature using modules and mixins. Advantages of Mixins are given here. A brief explanation of Multiple inheritance in Scala and Python is given here. Advantages and disadvantages of Multiple inheritance are given here. Because of few drawbacks(which are discussed above), few languages have implemented concepts like Modules and Mixins to emulate the power of multiple inheritance. Multiple Inheritance is supported by several object oriented languages such as C++, Ruby, Perl, Python etc.Implementation of multiple inheritance in each of these languages is compared here.

Ruby

Ruby is a dynamic, reflective, general-purpose object-oriented programming language.Ruby is all about objects. A brief outline is given on objects,classes and inheritance. Instance variables in ruby are defined.Instance methods and Accessor methods are explained briefly along with examples. Class variables and class methods in Ruby are defined here.The basic syntax to declare them as class variables and instance variables is also given. Ruby Modules are similar to classes in that they hold a collection of methods,constants and other module and class definitions.Modules definition is similar to classes just that we use the keyword module instead of the class keyword.Unlike classes, objects cannot be created based on modules nor can it be sub classed.However, it can be specified that the functionality of one module should be added to another class, or a specific object. Uses and examples of modules are given here. The most interesting fact about the use of modules is to define mixins. When a module is included within a class,all its functionality becomes available to the class.Modules can contain class methods and instance methods. Mixins are different from #include and multiple inheritance and this is demonstrated here.

Namespace in C++ is similar to modulesIn general, a namespace is a container for a set of identifiers (names), and allows the disambiguation of homonym identifiers residing in different namespaces.Namespace usually group names based on their functionality. Usage of namespaces and its example is given here. Multiple inheritance in C++ similar to mixins.You can derive a class from any number of base classes. Deriving a class from more than one direct base class is called multiple inheritance. An example is given here. Interfaces in JAVA is similar to mixins.A Java interface defines a set of methods but does not implement them.A class that implements the interface agrees to implement all of the methods defined in the interface, thereby agreeing to certain behavior, thereby implementing multiple inheritance. Properties of an interface are:

  • An interface is implicitly abstract. You do not need to use the abstract keyword when declaring an interface.
  • Each method in an interface is also implicitly abstract, so the abstract keyword is not needed.
  • Methods in an interface are implicitly public.

An example is given over here. Comparable and Enumerable are commonly used mixins.



Regular expressions are extremely powerful.Rubywas built as a better Perl hence it supports regular expressions. Regular expression is sort of a string used to match to other strings.In ruby regular expressions are written in the format /pattern/modifiers where pattern is the regular expression and modifiers are the series of characters specifying the various options. More on regular expressions can be found here.

Code Reuse

Code reuse, also known as software reuse is the practice of using the same segment of code in multiple applications. The definition, overview and a brief history of code reuse is found here. There are several techniques in code reuse. Code can be reused by using simple coding. For example, using a single line of code, we can reuse the code.Procedures and macros are the low level code reuse techniques.Methods can be used in code reuse, a method can be defined and declared multiple times wherever required. An individual software component is a software package, a Web service, or a module that encapsulates a set of related functions. All system processes are placed into separate components so that all of the data and functions inside each component are semantically related. Because of this principle, it is often said that components are modular and cohesive. With the help of Packages,modules and inheritance, we can achieve code reuse. Generators,Software architectures, code scavenging, Transformational systems, Very High Level Languages (VHLL) are more techniques of code reuse. Here are some of the best practices to be followed to make sure that the code that is being written is reusable. Advantages and disadvantages of code reuse can be found here. Here are few of the tradeoffs for code reuse at various levels of components.

References

http://en.wikipedia.org/wiki/Component-based_software_engineering http://en.wikipedia.org/wiki/Functional_programming http://docs.python.org/dev/howto/functional.html http://searchsoa.techtarget.com/definition/object-oriented-programming