عمر کوتاه است و آموختنی ها زیاد

پس بهترین ها را بیاموز

۲ مطلب در مرداد ۱۳۹۳ ثبت شده است

درختی در صـخره . . .

قزوین - الموت - اناده





۰ نظر موافقین ۲ مخالفین ۰
علی جهانی

رابط Fluent

رابط Fluent یا Fluent interface یک اجرا کننده شی گرا از رابط برنامه نویسی نرم افزار است که باعث خوانا تر شدن کد های نوشته شده می شود.
نمونه در C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace fluent
{
    class Person
    {
        public String Name { get; private set; }
        public int Age { get; private set; }

        public Person WithName(String name)
        {
            Name = name;
            return this;
        }

        public Person WithAge(int age)
        {
            Age = age;
            return this;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Person Ali = new Person().WithName("Ali").WithAge(16);
            Console.WriteLine("Name:{0}",Ali.Name);
            Console.WriteLine("Age:{0}", Ali.Age);
            Console.ReadKey();
        }
    }
}

نمونه در c++:
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

class Person
{
public:
	const char* Name;
	int Age;

	Person WithName(const char* name)
	{
		Name = name;
		return *this;
	}

	Person WithAge(int age)
	{
		Age = age;
		return *this;
	}
};

int main()
{
	Person Ali = Person().WithName("Ali").WithAge(16);
	cout << "Name:" << Ali.Name << "\nAge:" << Ali.Age;
	getchar();
	return 0;
}



۱ نظر موافقین ۰ مخالفین ۰
علی جهانی